|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
PlexusAxisServlet.java | 0% | 17.9% | 60% | 18.6% |
|
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 | 5 |
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 | 4 |
public AxisServer getEngine() throws AxisFault |
48 |
{ |
|
49 | 4 |
manager = getServiceManager(); |
50 |
|
|
51 | 4 |
try
|
52 |
{ |
|
53 | 4 |
axisService = ( AxisService ) manager.lookup( AxisService.ROLE ); |
54 |
} |
|
55 |
catch (ServiceException e)
|
|
56 |
{ |
|
57 | 0 |
throw new AxisFault( "Could not find the AxisService.", e ); |
58 |
} |
|
59 |
|
|
60 | 4 |
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 | 4 |
public ServiceManager getServiceManager()
|
70 |
{ |
|
71 | 4 |
return PlexusServletUtils.getServiceManager( getServletContext() );
|
72 |
} |
|
73 |
|
|
74 | 0 |
public void destroy() |
75 |
{ |
|
76 | 0 |
super.destroy();
|
77 |
|
|
78 | 0 |
if ( axisService != null ) |
79 | 0 |
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 | 0 |
protected void processListRequest( HttpServletResponse response, |
91 |
PrintWriter writer ) |
|
92 |
throws AxisFault
|
|
93 |
{ |
|
94 | 0 |
AxisEngine engine = getEngine(); |
95 |
|
|
96 | 0 |
boolean enableList = true; |
97 |
|
|
98 | 0 |
if (enableList) {
|
99 | 0 |
if ( engine.getConfig() instanceof WSDDEngineConfiguration ) |
100 |
{ |
|
101 | 0 |
super.processListRequest( response, writer );
|
102 |
} |
|
103 | 0 |
else if ( engine.getConfig() instanceof SimpleProvider ) |
104 |
{ |
|
105 | 0 |
SimpleProvider config = ( SimpleProvider ) engine.getConfig(); |
106 |
|
|
107 | 0 |
Iterator itr; |
108 | 0 |
try
|
109 |
{ |
|
110 | 0 |
itr = config.getDeployedServices(); |
111 |
} |
|
112 |
catch (ConfigurationException e)
|
|
113 |
{ |
|
114 | 0 |
throw new AxisFault( "Configuration error.", e ); |
115 |
} |
|
116 |
|
|
117 | 0 |
response.setContentType("text/html");
|
118 | 0 |
writer.println("<h2>Services</h2>");
|
119 | 0 |
for ( SOAPService service = (SOAPService) itr.next();
|
120 | 0 |
itr.hasNext(); ) |
121 |
{ |
|
122 | 0 |
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 | 0 |
response.setStatus(HttpURLConnection.HTTP_FORBIDDEN); |
133 | 0 |
response.setContentType("text/html");
|
134 | 0 |
writer.println("<h2>" +
|
135 |
Messages.getMessage("error00") +
|
|
136 |
"</h2>");
|
|
137 | 0 |
writer.println("<p><i>?list</i> " +
|
138 |
Messages.getMessage("disabled00") +
|
|
139 |
"</p>");
|
|
140 |
} |
|
141 |
} |
|
142 |
} |
|
143 |
|
|