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