1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transport.soap.axis; |
12 | |
|
13 | |
import org.mule.DefaultMuleMessage; |
14 | |
import org.mule.RequestContext; |
15 | |
import org.mule.api.MessagingException; |
16 | |
import org.mule.api.MuleEventContext; |
17 | |
import org.mule.api.MuleException; |
18 | |
import org.mule.api.MuleMessage; |
19 | |
import org.mule.api.config.MuleProperties; |
20 | |
import org.mule.api.endpoint.EndpointURI; |
21 | |
import org.mule.api.lifecycle.Callable; |
22 | |
import org.mule.api.lifecycle.Initialisable; |
23 | |
import org.mule.api.lifecycle.InitialisationException; |
24 | |
import org.mule.config.MuleManifest; |
25 | |
import org.mule.config.i18n.CoreMessages; |
26 | |
import org.mule.config.i18n.MessageFactory; |
27 | |
import org.mule.endpoint.MuleEndpointURI; |
28 | |
import org.mule.module.cxf.SoapConstants; |
29 | |
import org.mule.transport.http.HttpConnector; |
30 | |
import org.mule.transport.http.HttpConstants; |
31 | |
import org.mule.transport.soap.axis.extensions.AxisMuleSession; |
32 | |
import org.mule.transport.soap.axis.extensions.MuleConfigProvider; |
33 | |
import org.mule.util.StringUtils; |
34 | |
|
35 | |
import java.io.ByteArrayInputStream; |
36 | |
import java.io.ByteArrayOutputStream; |
37 | |
import java.io.File; |
38 | |
import java.io.FileInputStream; |
39 | |
import java.io.IOException; |
40 | |
import java.util.ArrayList; |
41 | |
import java.util.Iterator; |
42 | |
import java.util.Map; |
43 | |
import java.util.Properties; |
44 | |
|
45 | |
import javax.xml.namespace.QName; |
46 | |
|
47 | |
import org.apache.axis.AxisEngine; |
48 | |
import org.apache.axis.AxisFault; |
49 | |
import org.apache.axis.ConfigurationException; |
50 | |
import org.apache.axis.Constants; |
51 | |
import org.apache.axis.Message; |
52 | |
import org.apache.axis.MessageContext; |
53 | |
import org.apache.axis.description.OperationDesc; |
54 | |
import org.apache.axis.description.ServiceDesc; |
55 | |
import org.apache.axis.handlers.soap.SOAPService; |
56 | |
import org.apache.axis.i18n.Messages; |
57 | |
import org.apache.axis.security.servlet.ServletSecurityProvider; |
58 | |
import org.apache.axis.server.AxisServer; |
59 | |
import org.apache.axis.transport.http.HTTPConstants; |
60 | |
import org.apache.axis.transport.http.ServletEndpointContextImpl; |
61 | |
import org.apache.axis.utils.Admin; |
62 | |
import org.apache.axis.utils.XMLUtils; |
63 | |
import org.apache.commons.logging.Log; |
64 | |
import org.w3c.dom.Document; |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
public class AxisServiceComponent implements Initialisable, Callable |
78 | |
{ |
79 | 0 | protected static final Log logger = org.apache.commons.logging.LogFactory.getLog(AxisServiceComponent.class); |
80 | |
|
81 | |
public static final String INIT_PROPERTY_TRANSPORT_NAME = "transport.name"; |
82 | |
public static final String INIT_PROPERTY_USE_SECURITY = "use-servlet-security"; |
83 | |
public static final String INIT_PROPERTY_ENABLE_LIST = "axis.enableListQuery"; |
84 | |
public static final String DEFAULT_AXIS_HOME = "/axisHome"; |
85 | |
|
86 | 0 | private String transportName = "http"; |
87 | 0 | private ServletSecurityProvider securityProvider = null; |
88 | 0 | private boolean enableList = true; |
89 | |
private String homeDir; |
90 | |
private AxisServer axis; |
91 | |
|
92 | |
|
93 | |
public AxisServiceComponent() |
94 | 0 | { |
95 | |
|
96 | 0 | } |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
public Object onCall(MuleEventContext context) throws Exception |
118 | |
{ |
119 | 0 | AxisStringWriter response = new AxisStringWriter(); |
120 | 0 | String method = context.getMessage().getInboundProperty(HttpConnector.HTTP_METHOD_PROPERTY, HttpConstants.METHOD_POST); |
121 | 0 | if (HttpConstants.METHOD_GET.equalsIgnoreCase(method)) |
122 | |
{ |
123 | 0 | doGet(context, response); |
124 | |
} |
125 | |
else |
126 | |
{ |
127 | 0 | doPost(context, response); |
128 | |
} |
129 | 0 | response.close(); |
130 | |
|
131 | 0 | String payload = response.getWriter().toString(); |
132 | 0 | Map<String, Object> properties = response.getProperties(); |
133 | 0 | return new DefaultMuleMessage(payload, properties, context.getMuleContext()); |
134 | |
} |
135 | |
|
136 | |
public void initialise() throws InitialisationException |
137 | |
{ |
138 | 0 | if (axis == null) |
139 | |
{ |
140 | 0 | throw new InitialisationException(MessageFactory.createStaticMessage("No Axis instance, this component has not been initialized properly."), this); |
141 | |
} |
142 | 0 | } |
143 | |
|
144 | |
public void doGet(MuleEventContext context, AxisStringWriter response) |
145 | |
throws MuleException, IOException |
146 | |
{ |
147 | |
try |
148 | |
{ |
149 | |
|
150 | |
|
151 | |
|
152 | 0 | EndpointURI endpointUri = context.getEndpointURI(); |
153 | |
|
154 | |
|
155 | |
|
156 | 0 | if (!"true".equalsIgnoreCase(context.getEndpointURI().getParams().getProperty("servlet.endpoint"))) |
157 | |
{ |
158 | 0 | String uri = SoapConstants.SOAP_ENDPOINT_PREFIX + context.getEndpointURI().getScheme() |
159 | |
+ "://" + context.getEndpointURI().getHost() + ":" |
160 | |
+ context.getEndpointURI().getPort(); |
161 | 0 | uri += context.getMessage().getInboundProperty(HttpConnector.HTTP_REQUEST_PROPERTY, StringUtils.EMPTY); |
162 | 0 | endpointUri = new MuleEndpointURI(uri, context.getMuleContext()); |
163 | 0 | endpointUri.initialise(); |
164 | |
} |
165 | |
|
166 | 0 | AxisEngine engine = getAxis(); |
167 | 0 | String pathInfo = endpointUri.getPath(); |
168 | 0 | boolean wsdlRequested = false; |
169 | 0 | boolean listRequested = false; |
170 | |
|
171 | 0 | if (endpointUri.getAddress().endsWith(".jws")) |
172 | |
{ |
173 | 0 | throw new AxisFault("Jws not supported by the Mule Axis service"); |
174 | |
} |
175 | |
|
176 | 0 | String queryString = endpointUri.getQuery(); |
177 | 0 | if (queryString != null) |
178 | |
{ |
179 | 0 | if (queryString.equalsIgnoreCase(SoapConstants.WSDL_PROPERTY)) |
180 | |
{ |
181 | 0 | wsdlRequested = true; |
182 | |
} |
183 | |
else |
184 | |
{ |
185 | 0 | if (queryString.equalsIgnoreCase(SoapConstants.LIST_PROPERTY)) |
186 | |
{ |
187 | 0 | listRequested = true; |
188 | |
} |
189 | |
} |
190 | |
} |
191 | |
|
192 | 0 | boolean hasNoPath = (StringUtils.isEmpty(pathInfo) || pathInfo.equals("/")); |
193 | 0 | if (!wsdlRequested && !listRequested && hasNoPath) |
194 | |
{ |
195 | 0 | reportAvailableServices(context, response); |
196 | |
} |
197 | |
else |
198 | |
{ |
199 | 0 | MessageContext msgContext = new MessageContext(engine); |
200 | 0 | populateMessageContext(msgContext, context, endpointUri); |
201 | |
|
202 | 0 | msgContext.setProperty("transport.url", endpointUri.toString()); |
203 | 0 | if (wsdlRequested) |
204 | |
{ |
205 | 0 | processWsdlRequest(msgContext, response); |
206 | |
} |
207 | 0 | else if (listRequested) |
208 | |
{ |
209 | 0 | processListRequest(response); |
210 | |
} |
211 | |
else |
212 | |
{ |
213 | 0 | processMethodRequest(msgContext, context, response, endpointUri); |
214 | |
} |
215 | |
} |
216 | |
} |
217 | 0 | catch (AxisFault fault) |
218 | |
{ |
219 | 0 | reportTroubleInGet(fault, response); |
220 | |
} |
221 | 0 | catch (Exception e) |
222 | |
{ |
223 | 0 | reportTroubleInGet(e, response); |
224 | 0 | } |
225 | 0 | } |
226 | |
|
227 | |
protected void doPost(MuleEventContext context, AxisStringWriter response) |
228 | |
throws Exception |
229 | |
{ |
230 | |
String soapAction; |
231 | |
Message responseMsg; |
232 | 0 | AxisEngine engine = getAxis(); |
233 | 0 | if (engine == null) |
234 | |
{ |
235 | |
|
236 | 0 | throw new MessagingException(CoreMessages.objectIsNull("Axis Engine"), context.getMessage()); |
237 | |
} |
238 | 0 | MessageContext msgContext = new MessageContext(engine); |
239 | |
|
240 | |
String contentType; |
241 | |
try |
242 | |
{ |
243 | |
|
244 | 0 | EndpointURI endpointUri = context.getEndpointURI(); |
245 | 0 | populateMessageContext(msgContext, context, endpointUri); |
246 | 0 | if (securityProvider != null) |
247 | |
{ |
248 | 0 | if (logger.isDebugEnabled()) |
249 | |
{ |
250 | 0 | logger.debug("securityProvider:" + securityProvider); |
251 | |
} |
252 | 0 | msgContext.setProperty("securityProvider", securityProvider); |
253 | |
} |
254 | |
|
255 | 0 | Object request = context.getMessage().getPayload(); |
256 | 0 | if (request instanceof File) |
257 | |
{ |
258 | 0 | request = new FileInputStream((File)request); |
259 | |
} |
260 | 0 | else if (request instanceof byte[]) |
261 | |
{ |
262 | 0 | request = new ByteArrayInputStream((byte[])request); |
263 | |
} |
264 | |
|
265 | 0 | final String cType = context.getMessage().getInboundProperty(HTTPConstants.HEADER_CONTENT_TYPE); |
266 | 0 | final String cLocation = context.getMessage().getInboundProperty(HTTPConstants.HEADER_CONTENT_LOCATION); |
267 | 0 | Message requestMsg = new Message(request, false, cType, cLocation); |
268 | |
|
269 | 0 | if (logger.isDebugEnabled()) |
270 | |
{ |
271 | 0 | logger.debug("Request Message:" + requestMsg); |
272 | |
} |
273 | 0 | msgContext.setRequestMessage(requestMsg); |
274 | 0 | msgContext.setProperty("transport.url", endpointUri.toString()); |
275 | |
|
276 | 0 | soapAction = getSoapAction(context); |
277 | 0 | if (soapAction != null) |
278 | |
{ |
279 | 0 | msgContext.setUseSOAPAction(true); |
280 | 0 | msgContext.setSOAPActionURI(soapAction); |
281 | |
} |
282 | 0 | msgContext.setSession(new AxisMuleSession(context.getSession())); |
283 | |
|
284 | 0 | if (logger.isDebugEnabled()) |
285 | |
{ |
286 | 0 | logger.debug("Invoking Axis Engine."); |
287 | |
} |
288 | 0 | AxisServiceProxy.setProperties(RequestContext.getEvent().getEndpoint().getProperties()); |
289 | 0 | engine.invoke(msgContext); |
290 | 0 | if (logger.isDebugEnabled()) |
291 | |
{ |
292 | 0 | logger.debug("Return from Axis Engine."); |
293 | |
} |
294 | 0 | if (RequestContext.getExceptionPayload() instanceof Exception) |
295 | |
{ |
296 | 0 | throw (Exception)RequestContext.getExceptionPayload().getException(); |
297 | |
} |
298 | |
|
299 | 0 | if (request instanceof File) |
300 | |
{ |
301 | 0 | ((File)request).delete(); |
302 | |
} |
303 | 0 | responseMsg = msgContext.getResponseMessage(); |
304 | 0 | if (responseMsg == null) |
305 | |
{ |
306 | 0 | throw new Exception(Messages.getMessage("noResponse01")); |
307 | |
} |
308 | |
} |
309 | 0 | catch (AxisFault fault) |
310 | |
{ |
311 | 0 | logger.error(fault.toString() + " target service is: " + msgContext.getTargetService() |
312 | |
+ ". MuleEvent is: " + context.toString(), fault); |
313 | 0 | processAxisFault(fault); |
314 | 0 | configureResponseFromAxisFault(response, fault); |
315 | 0 | responseMsg = msgContext.getResponseMessage(); |
316 | 0 | if (responseMsg == null) |
317 | |
{ |
318 | 0 | responseMsg = new Message(fault); |
319 | |
} |
320 | |
} |
321 | 0 | catch (Exception e) |
322 | |
{ |
323 | 0 | responseMsg = msgContext.getResponseMessage(); |
324 | 0 | response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, "500"); |
325 | 0 | responseMsg = convertExceptionToAxisFault(e, responseMsg); |
326 | 0 | } |
327 | |
|
328 | 0 | contentType = responseMsg.getContentType(msgContext.getSOAPConstants()); |
329 | |
|
330 | 0 | sendResponse(contentType, response, responseMsg); |
331 | |
|
332 | 0 | if (logger.isDebugEnabled()) |
333 | |
{ |
334 | 0 | logger.debug("Response sent."); |
335 | |
} |
336 | 0 | } |
337 | |
|
338 | |
private void reportTroubleInGet(Exception exception, AxisStringWriter response) |
339 | |
{ |
340 | 0 | response.setProperty(HttpConstants.HEADER_CONTENT_TYPE, "text/html"); |
341 | 0 | response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, "500"); |
342 | 0 | response.write("<h2>" + Messages.getMessage("error00") + "</h2>"); |
343 | 0 | response.write("<p>" + Messages.getMessage("somethingWrong00") + "</p>"); |
344 | 0 | if (exception instanceof AxisFault) |
345 | |
{ |
346 | 0 | AxisFault fault = (AxisFault)exception; |
347 | 0 | processAxisFault(fault); |
348 | 0 | writeFault(response, fault); |
349 | 0 | } |
350 | |
else |
351 | |
{ |
352 | 0 | logger.error(exception.getMessage(), exception); |
353 | 0 | response.write("<pre>Exception - " + exception + "<br>"); |
354 | 0 | response.write("</pre>"); |
355 | |
} |
356 | 0 | } |
357 | |
|
358 | |
protected void processAxisFault(AxisFault fault) |
359 | |
{ |
360 | 0 | org.w3c.dom.Element runtimeException = fault |
361 | |
.lookupFaultDetail(Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION); |
362 | 0 | if (runtimeException != null) |
363 | |
{ |
364 | 0 | logger.info(Messages.getMessage("axisFault00"), fault); |
365 | 0 | fault.removeFaultDetail(Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION); |
366 | |
} |
367 | 0 | else if (logger.isDebugEnabled()) |
368 | |
{ |
369 | 0 | logger.debug(Messages.getMessage("axisFault00"), fault); |
370 | |
} |
371 | |
|
372 | 0 | } |
373 | |
|
374 | |
private void writeFault(AxisStringWriter response, AxisFault axisFault) |
375 | |
{ |
376 | 0 | String localizedMessage = XMLUtils.xmlEncodeString(axisFault.getLocalizedMessage()); |
377 | 0 | response.write("<pre>Fault - " + localizedMessage + "<br>"); |
378 | 0 | response.write(axisFault.dumpToString()); |
379 | 0 | response.write("</pre>"); |
380 | 0 | } |
381 | |
|
382 | |
protected void processMethodRequest(MessageContext msgContext, |
383 | |
MuleEventContext context, |
384 | |
AxisStringWriter response, |
385 | |
EndpointURI endpointUri) throws AxisFault |
386 | |
{ |
387 | 0 | Properties params = endpointUri.getUserParams(); |
388 | |
|
389 | 0 | String method = (String)params.remove(MuleProperties.MULE_METHOD_PROPERTY); |
390 | 0 | if (method == null) |
391 | |
{ |
392 | 0 | method = endpointUri.getPath().substring(endpointUri.getPath().lastIndexOf("/") + 1); |
393 | |
} |
394 | 0 | StringBuffer args = new StringBuffer(64); |
395 | |
|
396 | |
Map.Entry entry; |
397 | 0 | for (Iterator iterator = params.entrySet().iterator(); iterator.hasNext();) |
398 | |
{ |
399 | 0 | entry = (Map.Entry)iterator.next(); |
400 | 0 | args.append("<").append(entry.getKey()).append(">"); |
401 | 0 | args.append(entry.getValue()); |
402 | 0 | args.append("</").append(entry.getKey()).append(">"); |
403 | |
} |
404 | |
|
405 | 0 | if (method == null) |
406 | |
{ |
407 | 0 | response.setProperty(HttpConstants.HEADER_CONTENT_TYPE, "text/html"); |
408 | 0 | response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, "400"); |
409 | 0 | response.write("<h2>" + Messages.getMessage("error00") + ": " |
410 | |
+ Messages.getMessage("invokeGet00") + "</h2>"); |
411 | 0 | response.write("<p>" + Messages.getMessage("noMethod01") + "</p>"); |
412 | |
} |
413 | |
else |
414 | |
{ |
415 | 0 | invokeEndpointFromGet(msgContext, response, method, args.toString()); |
416 | |
} |
417 | 0 | } |
418 | |
|
419 | |
protected void processWsdlRequest(MessageContext msgContext, AxisStringWriter response) |
420 | |
throws AxisFault |
421 | |
{ |
422 | 0 | AxisEngine engine = getAxis(); |
423 | |
try |
424 | |
{ |
425 | 0 | engine.generateWSDL(msgContext); |
426 | 0 | Document doc = (Document)msgContext.getProperty("WSDL"); |
427 | 0 | if (doc != null) |
428 | |
{ |
429 | 0 | response.setProperty(HttpConstants.HEADER_CONTENT_TYPE, "text/xml"); |
430 | 0 | XMLUtils.DocumentToWriter(doc, response.getWriter()); |
431 | |
} |
432 | |
else |
433 | |
{ |
434 | 0 | if (logger.isDebugEnabled()) |
435 | |
{ |
436 | 0 | logger.debug("processWsdlRequest: failed to create WSDL"); |
437 | |
} |
438 | 0 | reportNoWSDL(response, "noWSDL02", null); |
439 | |
} |
440 | |
} |
441 | 0 | catch (AxisFault axisFault) |
442 | |
{ |
443 | 0 | if (axisFault.getFaultCode().equals(Constants.QNAME_NO_SERVICE_FAULT_CODE)) |
444 | |
{ |
445 | 0 | processAxisFault(axisFault); |
446 | 0 | response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, "404"); |
447 | 0 | reportNoWSDL(response, "noWSDL01", axisFault); |
448 | |
} |
449 | |
else |
450 | |
{ |
451 | 0 | throw axisFault; |
452 | |
} |
453 | 0 | } |
454 | 0 | } |
455 | |
|
456 | |
protected void invokeEndpointFromGet(MessageContext msgContext, |
457 | |
AxisStringWriter response, |
458 | |
String method, |
459 | |
String args) throws AxisFault |
460 | |
{ |
461 | 0 | String body = "<" + method + ">" + args + "</" + method + ">"; |
462 | 0 | String msgtxt = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body>" |
463 | |
+ body + "</SOAP-ENV:Body>" + "</SOAP-ENV:Envelope>"; |
464 | 0 | Message responseMsg = null; |
465 | |
try |
466 | |
{ |
467 | 0 | ByteArrayInputStream istream = new ByteArrayInputStream(msgtxt.getBytes("ISO-8859-1")); |
468 | 0 | AxisEngine engine = getAxis(); |
469 | 0 | Message msg = new Message(istream, false); |
470 | 0 | msgContext.setRequestMessage(msg); |
471 | 0 | AxisServiceProxy.setProperties(RequestContext.getEvent().getEndpoint().getProperties()); |
472 | 0 | engine.invoke(msgContext); |
473 | 0 | responseMsg = msgContext.getResponseMessage(); |
474 | 0 | response.setProperty(HTTPConstants.HEADER_CACHE_CONTROL, "no-cache"); |
475 | 0 | response.setProperty(HTTPConstants.HEADER_PRAGMA, "no-cache"); |
476 | 0 | if (responseMsg == null) |
477 | |
{ |
478 | 0 | throw new Exception(Messages.getMessage("noResponse01")); |
479 | |
} |
480 | |
} |
481 | 0 | catch (AxisFault fault) |
482 | |
{ |
483 | 0 | processAxisFault(fault); |
484 | 0 | configureResponseFromAxisFault(response, fault); |
485 | 0 | responseMsg = new Message(fault); |
486 | |
} |
487 | 0 | catch (Exception e) |
488 | |
{ |
489 | 0 | response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, "500"); |
490 | 0 | responseMsg = convertExceptionToAxisFault(e, responseMsg); |
491 | 0 | } |
492 | 0 | response.setProperty(HTTPConstants.HEADER_CONTENT_TYPE, "text/xml"); |
493 | 0 | response.write(responseMsg.getSOAPPartAsString()); |
494 | 0 | } |
495 | |
|
496 | |
protected void reportServiceInfo(AxisStringWriter response, SOAPService service, String serviceName) |
497 | |
{ |
498 | 0 | response.setProperty(HttpConstants.HEADER_CONTENT_TYPE, "text/html"); |
499 | 0 | response.write("<h1>" + service.getName() + "</h1>"); |
500 | 0 | response.write("<p>" + Messages.getMessage("axisService00") + "</p>"); |
501 | 0 | response.write("<i>" + Messages.getMessage("perhaps00") + "</i>"); |
502 | 0 | } |
503 | |
|
504 | |
protected void processListRequest(AxisStringWriter response) throws AxisFault |
505 | |
{ |
506 | 0 | AxisEngine engine = getAxis(); |
507 | 0 | response.setProperty(HTTPConstants.HEADER_CONTENT_TYPE, "text/html"); |
508 | 0 | if (enableList) |
509 | |
{ |
510 | 0 | Document doc = Admin.listConfig(engine); |
511 | 0 | if (doc != null) |
512 | |
{ |
513 | 0 | XMLUtils.DocumentToWriter(doc, response.getWriter()); |
514 | |
} |
515 | |
else |
516 | |
{ |
517 | 0 | response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, "404"); |
518 | 0 | response.write("<h2>" + Messages.getMessage("error00") + "</h2>"); |
519 | 0 | response.write("<p>" + Messages.getMessage("noDeploy00") + "</p>"); |
520 | |
} |
521 | 0 | } |
522 | |
else |
523 | |
{ |
524 | 0 | response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, "403"); |
525 | 0 | response.write("<h2>" + Messages.getMessage("error00") + "</h2>"); |
526 | 0 | response.write("<p><i>?list</i> " + Messages.getMessage("disabled00") + "</p>"); |
527 | |
} |
528 | 0 | } |
529 | |
|
530 | |
private void reportNoWSDL(AxisStringWriter response, String moreDetailCode, AxisFault axisFault) |
531 | |
{ |
532 | 0 | response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, "404"); |
533 | 0 | response.setProperty(HTTPConstants.HEADER_CONTENT_TYPE, "text/html"); |
534 | 0 | response.write("<h2>" + Messages.getMessage("error00") + "</h2>"); |
535 | 0 | response.write("<p>" + Messages.getMessage("noWSDL00") + "</p>"); |
536 | 0 | if (moreDetailCode != null) |
537 | |
{ |
538 | 0 | response.write("<p>" + Messages.getMessage(moreDetailCode) + "</p>"); |
539 | |
} |
540 | |
|
541 | 0 | } |
542 | |
|
543 | |
protected void reportAvailableServices(MuleEventContext context, AxisStringWriter response) |
544 | |
throws ConfigurationException, AxisFault |
545 | |
{ |
546 | 0 | AxisEngine engine = getAxis(); |
547 | 0 | response.setProperty(HttpConstants.HEADER_CONTENT_TYPE, "text/html"); |
548 | 0 | response.write("<h2>And now... Some Services</h2>"); |
549 | 0 | String version = MuleManifest.getProductVersion(); |
550 | 0 | if (version == null) |
551 | |
{ |
552 | 0 | version = "Version Not Set"; |
553 | |
} |
554 | 0 | response.write("<h5>(Mule - " + version + ")</h5>"); |
555 | |
Iterator i; |
556 | |
|
557 | |
try |
558 | |
{ |
559 | 0 | response |
560 | |
.write("<table width=\"400\"><tr><th>Mule Component Services</th><th>Axis Services</th></tr><tr><td width=\"200\" valign=\"top\">"); |
561 | 0 | i = engine.getConfig().getDeployedServices(); |
562 | 0 | listServices(i, response); |
563 | 0 | response.write("</td><td width=\"200\" valign=\"top\">"); |
564 | 0 | i = ((MuleConfigProvider)engine.getConfig()).getAxisDeployedServices(); |
565 | 0 | listServices(i, response); |
566 | 0 | response.write("</td></tr></table>"); |
567 | |
} |
568 | 0 | catch (ConfigurationException configException) |
569 | |
{ |
570 | 0 | if (configException.getContainedException() instanceof AxisFault) |
571 | |
{ |
572 | 0 | throw (AxisFault)configException.getContainedException(); |
573 | |
} |
574 | |
else |
575 | |
{ |
576 | 0 | throw configException; |
577 | |
} |
578 | 0 | } |
579 | |
|
580 | 0 | } |
581 | |
|
582 | |
private void listServices(Iterator i, AxisStringWriter response) |
583 | |
{ |
584 | 0 | response.write("<ul>"); |
585 | 0 | while (i.hasNext()) |
586 | |
{ |
587 | 0 | ServiceDesc sd = (ServiceDesc)i.next(); |
588 | 0 | StringBuffer sb = new StringBuffer(512); |
589 | 0 | sb.append("<li>"); |
590 | 0 | String name = sd.getName(); |
591 | 0 | sb.append(name); |
592 | 0 | sb.append(" <a href=\""); |
593 | 0 | if (sd.getEndpointURL() != null) |
594 | |
{ |
595 | 0 | sb.append(sd.getEndpointURL()); |
596 | 0 | if (!sd.getEndpointURL().endsWith("/")) |
597 | |
{ |
598 | 0 | sb.append("/"); |
599 | |
} |
600 | |
} |
601 | 0 | sb.append(name); |
602 | 0 | sb.append("?wsdl\"><i>(wsdl)</i></a></li>"); |
603 | 0 | response.write(sb.toString()); |
604 | 0 | if (sd.getDocumentation() != null) |
605 | |
{ |
606 | 0 | response.write("<ul><h6>" + sd.getDocumentation() + "</h6></ul>"); |
607 | |
} |
608 | 0 | ArrayList operations = sd.getOperations(); |
609 | 0 | if (!operations.isEmpty()) |
610 | |
{ |
611 | 0 | response.write("<ul>"); |
612 | |
OperationDesc desc; |
613 | 0 | for (Iterator it = operations.iterator(); it.hasNext();) |
614 | |
{ |
615 | 0 | desc = (OperationDesc)it.next(); |
616 | 0 | response.write("<li>" + desc.getName()); |
617 | |
} |
618 | 0 | response.write("</ul>"); |
619 | |
} |
620 | 0 | } |
621 | 0 | response.write("</ul>"); |
622 | 0 | } |
623 | |
|
624 | |
protected void reportCantGetAxisService(MuleEventContext context, AxisStringWriter response) |
625 | |
{ |
626 | 0 | response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, "404"); |
627 | 0 | response.setProperty(HttpConstants.HEADER_CONTENT_TYPE, "text/html"); |
628 | 0 | response.write("<h2>" + Messages.getMessage("error00") + "</h2>"); |
629 | 0 | response.write("<p>" + Messages.getMessage("noService06") + "</p>"); |
630 | 0 | } |
631 | |
|
632 | |
private void configureResponseFromAxisFault(AxisStringWriter response, AxisFault fault) |
633 | |
{ |
634 | 0 | int status = getHttpResponseStatus(fault); |
635 | 0 | if (status == 401) |
636 | |
{ |
637 | 0 | response.setProperty(HttpConstants.HEADER_WWW_AUTHENTICATE, "Basic realm=\"AXIS\""); |
638 | |
} |
639 | 0 | response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, String.valueOf(status)); |
640 | 0 | } |
641 | |
|
642 | |
private Message convertExceptionToAxisFault(Exception exception, Message responseMsg) |
643 | |
{ |
644 | 0 | logger.error(exception.getMessage(), exception); |
645 | 0 | if (responseMsg == null) |
646 | |
{ |
647 | 0 | AxisFault fault = AxisFault.makeFault(exception); |
648 | 0 | processAxisFault(fault); |
649 | 0 | responseMsg = new Message(fault); |
650 | |
} |
651 | 0 | return responseMsg; |
652 | |
} |
653 | |
|
654 | |
protected int getHttpResponseStatus(AxisFault af) |
655 | |
{ |
656 | 0 | return af.getFaultCode().getLocalPart().startsWith("Server.Unauth") ? 401 : '\u01F4'; |
657 | |
} |
658 | |
|
659 | |
private void sendResponse(String contentType, |
660 | |
AxisStringWriter response, |
661 | |
Message responseMsg) throws Exception |
662 | |
{ |
663 | 0 | if (responseMsg == null) |
664 | |
{ |
665 | 0 | response.setProperty(HttpConnector.HTTP_STATUS_PROPERTY, "204"); |
666 | 0 | if (logger.isDebugEnabled()) |
667 | |
{ |
668 | 0 | logger.debug("NO AXIS MESSAGE TO RETURN!"); |
669 | |
} |
670 | |
} |
671 | |
else |
672 | |
{ |
673 | 0 | if (logger.isDebugEnabled()) |
674 | |
{ |
675 | 0 | logger.debug("Returned Content-Type:" + contentType); |
676 | |
} |
677 | 0 | response.setProperty(HttpConstants.HEADER_CONTENT_TYPE, contentType); |
678 | 0 | ByteArrayOutputStream baos = new ByteArrayOutputStream(8192); |
679 | 0 | responseMsg.writeTo(baos); |
680 | 0 | response.write(baos.toString()); |
681 | |
} |
682 | 0 | } |
683 | |
|
684 | |
private void populateMessageContext(MessageContext msgContext, |
685 | |
MuleEventContext context, |
686 | |
EndpointURI endpointUri) throws AxisFault, ConfigurationException |
687 | |
{ |
688 | 0 | MuleMessage msg = context.getMessage(); |
689 | |
|
690 | 0 | if (logger.isDebugEnabled()) |
691 | |
{ |
692 | 0 | logger.debug("MessageContext:" + msgContext); |
693 | 0 | logger.debug("HEADER_CONTENT_TYPE:" + msg.getInboundProperty(HttpConstants.HEADER_CONTENT_TYPE)); |
694 | 0 | logger.debug("HEADER_CONTENT_LOCATION:" + msg.getInboundProperty(HttpConstants.HEADER_CONTENT_LOCATION)); |
695 | 0 | logger.debug("Constants.MC_HOME_DIR:" + String.valueOf(getHomeDir())); |
696 | 0 | logger.debug("Constants.MC_RELATIVE_PATH:" + endpointUri.getPath()); |
697 | 0 | logger.debug("HTTPConstants.HEADER_AUTHORIZATION:" + msg.getInboundProperty("Authorization")); |
698 | 0 | logger.debug("Constants.MC_REMOTE_ADDR:" + endpointUri.getHost()); |
699 | |
} |
700 | |
|
701 | 0 | msgContext.setTransportName(transportName); |
702 | 0 | msgContext.setProperty("home.dir", getHomeDir()); |
703 | 0 | msgContext.setProperty("path", endpointUri.getPath()); |
704 | 0 | msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLET, this); |
705 | 0 | msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETLOCATION, endpointUri.getPath()); |
706 | |
|
707 | 0 | String serviceName = getServiceName(context, endpointUri); |
708 | |
|
709 | 0 | SOAPService service = msgContext.getAxisEngine().getConfig().getService( |
710 | |
new QName(serviceName.substring(1))); |
711 | |
|
712 | |
|
713 | 0 | String scheme = endpointUri.getScheme(); |
714 | 0 | if (!("vm".equalsIgnoreCase(scheme) |
715 | |
|| "jms".equalsIgnoreCase(scheme) |
716 | |
|| "servlet".equalsIgnoreCase(scheme))) |
717 | |
{ |
718 | |
|
719 | 0 | if (service.getOption(AxisConnector.SERVICE_PROPERTY_COMPONENT_NAME) != null) |
720 | |
{ |
721 | 0 | String servicePath = (String)service.getOption("servicePath"); |
722 | 0 | if (StringUtils.isEmpty(endpointUri.getPath())) |
723 | |
{ |
724 | 0 | if (!("/" + endpointUri.getAddress()).startsWith(servicePath + serviceName)) |
725 | |
{ |
726 | 0 | throw new AxisFault("Failed to find service: " + "/" + endpointUri.getAddress()); |
727 | |
} |
728 | |
} |
729 | |
|
730 | |
|
731 | 0 | else if (!endpointUri.getPath().endsWith(servicePath + serviceName)) |
732 | |
{ |
733 | 0 | throw new AxisFault("Failed to find service: " + endpointUri.getPath()); |
734 | |
} |
735 | |
} |
736 | |
} |
737 | |
|
738 | 0 | msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETPATHINFO, serviceName); |
739 | 0 | msgContext.setProperty("serviceName", serviceName); |
740 | |
|
741 | 0 | msgContext.setProperty("Authorization", msg.getInboundProperty("Authorization")); |
742 | 0 | msgContext.setProperty("remoteaddr", endpointUri.getHost()); |
743 | 0 | ServletEndpointContextImpl sec = new ServletEndpointContextImpl(); |
744 | 0 | msgContext.setProperty("servletEndpointContext", sec); |
745 | 0 | } |
746 | |
|
747 | |
private String getSoapAction(MuleEventContext context) throws AxisFault |
748 | |
{ |
749 | 0 | String soapAction = context.getMessage().getInboundProperty(SoapConstants.SOAP_ACTION_PROPERTY_CAPS); |
750 | 0 | if (logger.isDebugEnabled()) |
751 | |
{ |
752 | 0 | logger.debug("Header Soap Action:" + soapAction); |
753 | |
} |
754 | |
|
755 | 0 | if (StringUtils.isEmpty(soapAction)) |
756 | |
{ |
757 | 0 | soapAction = context.getEndpointURI().getAddress(); |
758 | |
} |
759 | 0 | return soapAction; |
760 | |
} |
761 | |
|
762 | |
protected String getServiceName(MuleEventContext context, EndpointURI endpointUri) throws AxisFault |
763 | |
{ |
764 | 0 | String serviceName = endpointUri.getPath(); |
765 | 0 | if (StringUtils.isEmpty(serviceName)) |
766 | |
{ |
767 | 0 | serviceName = getSoapAction(context); |
768 | 0 | serviceName = serviceName.replaceAll("\"", ""); |
769 | 0 | int i = serviceName.indexOf("/", serviceName.indexOf("//")); |
770 | 0 | if (i < -1) |
771 | |
{ |
772 | 0 | serviceName = serviceName.substring(i + 2); |
773 | |
} |
774 | |
|
775 | |
} |
776 | |
|
777 | 0 | int i = serviceName.lastIndexOf('/'); |
778 | 0 | if (i > -1) |
779 | |
{ |
780 | 0 | serviceName = serviceName.substring(i); |
781 | |
} |
782 | 0 | i = serviceName.lastIndexOf('?'); |
783 | 0 | if (i > -1) |
784 | |
{ |
785 | 0 | serviceName = serviceName.substring(0, i); |
786 | |
} |
787 | 0 | return serviceName; |
788 | |
} |
789 | |
|
790 | |
public String getTransportName() |
791 | |
{ |
792 | 0 | return transportName; |
793 | |
} |
794 | |
|
795 | |
public void setTransportName(String transportName) |
796 | |
{ |
797 | 0 | this.transportName = transportName; |
798 | 0 | } |
799 | |
|
800 | |
public boolean isEnableList() |
801 | |
{ |
802 | 0 | return enableList; |
803 | |
} |
804 | |
|
805 | |
public void setEnableList(boolean enableList) |
806 | |
{ |
807 | 0 | this.enableList = enableList; |
808 | 0 | } |
809 | |
|
810 | |
public String getHomeDir() |
811 | |
{ |
812 | 0 | if (homeDir == null) |
813 | |
{ |
814 | |
|
815 | 0 | homeDir = DEFAULT_AXIS_HOME; |
816 | |
} |
817 | 0 | return homeDir; |
818 | |
} |
819 | |
|
820 | |
public void setHomeDir(String homeDir) |
821 | |
{ |
822 | 0 | this.homeDir = homeDir; |
823 | 0 | } |
824 | |
|
825 | |
public AxisServer getAxis() |
826 | |
{ |
827 | 0 | return axis; |
828 | |
} |
829 | |
|
830 | |
public void setAxis(AxisServer axisServer) |
831 | |
{ |
832 | 0 | this.axis = axisServer; |
833 | 0 | } |
834 | |
} |