View Javadoc

1   package org.codehaus.ivory.plexus;
2   
3   import javax.servlet.ServletContext;
4   import org.apache.avalon.framework.service.ServiceException;
5   import org.apache.avalon.framework.service.ServiceManager;
6   import org.apache.axis.AxisFault;
7   import org.apache.axis.AxisProperties;
8   import org.apache.axis.server.AxisServer;
9   import org.apache.axis.transport.http.AxisServlet;
10  import org.codehaus.ivory.AxisService;
11  import org.codehaus.ivory.DefaultAxisService;
12  
13  /***
14   * An implementation of the Axis AxisServlet which retrieves the AxisEngine
15   * from the ServiceManager.
16   * 
17   * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
18   * @since Mar 8, 2003
19   */
20  public class PlexusAxisServlet 
21      extends AxisServlet
22  {
23  	ServiceManager manager;
24  	
25  	AxisService axisService;
26  	
27  	public PlexusAxisServlet()
28  	{
29  	}
30      
31  	/***
32  	 * Provide the AxisEngine to the base servlet class.
33  	 * 
34  	 * @return AxisServer
35  	 * @see org.apache.axis.transport.http.AxisServletBase#getEngine()
36  	 */
37  	public AxisServer getEngine() throws AxisFault
38  	{
39  		manager = getServiceManager();
40          
41  		try
42  		{
43  			axisService = ( AxisService ) manager.lookup( AxisService.ROLE );
44  		}
45  		catch (ServiceException e)
46  		{
47  			throw new AxisFault( "Could not find the AxisService.", e );
48  		}
49          
50  		return axisService.getAxisServer();
51  	}
52      
53  	/***
54  	 * Retrieve the ServiceBroker from the ServletContext.  This presupposes
55  	 * that the installation is using Plexus.
56  	 * 
57  	 * @return ServiceBroker
58  	 */
59      public ServiceManager getServiceManager()
60      {
61          return DefaultAxisService.getServiceManager();
62      }
63      
64  	public void destroy()
65  	{
66  		super.destroy();
67      	
68          if ( axisService != null )
69              manager.release( axisService );
70  	}
71  
72      /***
73       * respond to the ?list command.
74       * if enableList is set, we list the engine config. If it isnt, then an
75       * error is written out
76       * @param response
77       * @param writer
78       * @throws AxisFault
79       */
80  //    protected void processListRequest( HttpServletResponse response, 
81  //                                       PrintWriter writer )
82  //        throws AxisFault 
83  //    {
84  //        AxisEngine engine = getEngine();
85  //
86  //        boolean enableList = true;
87  //        
88  //        if (enableList) {
89  //            if ( engine.getConfig() instanceof WSDDEngineConfiguration )
90  //            {
91  //                super.processListRequest( response, writer );
92  //            }
93  //            else if ( engine.getConfig() instanceof SimpleProvider )
94  //            {
95  //                SimpleProvider config = ( SimpleProvider ) engine.getConfig();
96  //                
97  //                Iterator itr;
98  //                try
99  //                {
100 //                    itr = config.getDeployedServices();
101 //                }
102 //                catch (ConfigurationException e)
103 //                {
104 //                    throw new AxisFault( "Configuration error.", e );
105 //                }
106 //                
107 //                response.setContentType("text/html");
108 //                writer.println("<h2>Services</h2>");
109 //                for ( SOAPService service = (SOAPService) itr.next();
110 //                    itr.hasNext(); )
111 //                {
112 //                    writer.println("<p>" +
113 //                                   service.getName() +
114 //                                   "</p>");
115 //                }
116 //            }
117 //        } 
118 //        else 
119 //        {
120 //            // list not enable, return error
121 //            //error code is, what, 401
122 //            response.setStatus(HttpURLConnection.HTTP_FORBIDDEN);
123 //            response.setContentType("text/html");
124 //            writer.println("<h2>" +
125 //                           Messages.getMessage("error00") +
126 //                           "</h2>");
127 //            writer.println("<p><i>?list</i> " +
128 //                           Messages.getMessage("disabled00") +
129 //                           "</p>");
130 //        }
131 //    }
132     
133     protected String getOption(ServletContext context,
134             String param,
135             String dephault)
136     {
137         String value = AxisProperties.getProperty(param);
138 
139         if (value == null) value = getInitParameter(param);
140 
141         if (value == null) value = context.getInitParameter(param);
142         try
143         {
144             AxisServer engine = getEngine();
145             if (value == null && engine != null) value = (String) engine
146                     .getOption(param);
147         }
148         catch (AxisFault axisFault)
149         {
150         }
151 
152         return (value != null) ? value : dephault;
153     }
154 }