1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transport.soap.axis.extensions; |
12 | |
|
13 | |
import org.mule.RegistryContext; |
14 | |
import org.mule.RequestContext; |
15 | |
import org.mule.api.service.Service; |
16 | |
import org.mule.transport.soap.axis.AxisConnector; |
17 | |
import org.mule.transport.soap.axis.AxisMessageReceiver; |
18 | |
import org.mule.transport.soap.axis.AxisServiceProxy; |
19 | |
|
20 | |
import java.lang.reflect.Proxy; |
21 | |
|
22 | |
import org.apache.axis.AxisFault; |
23 | |
import org.apache.axis.Constants; |
24 | |
import org.apache.axis.MessageContext; |
25 | |
import org.apache.axis.description.OperationDesc; |
26 | |
import org.apache.axis.handlers.soap.SOAPService; |
27 | |
import org.apache.axis.providers.java.MsgProvider; |
28 | |
import org.apache.commons.logging.Log; |
29 | |
import org.apache.commons.logging.LogFactory; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
public class MuleMsgProvider extends MsgProvider |
36 | |
{ |
37 | |
|
38 | |
|
39 | |
|
40 | |
private static final long serialVersionUID = -4399291846942449361L; |
41 | |
|
42 | |
private AxisConnector connector; |
43 | |
|
44 | 2 | private static Log logger = LogFactory.getLog(MuleMsgProvider.class); |
45 | |
|
46 | 52 | private String METHOD_BODYARRAY = "soapbodyelement"; |
47 | 52 | private String METHOD_ELEMENTARRAY = "element"; |
48 | 52 | private String METHOD_DOCUMENT = "document"; |
49 | |
|
50 | |
public MuleMsgProvider(AxisConnector connector) |
51 | 52 | { |
52 | 52 | this.connector = connector; |
53 | 52 | } |
54 | |
|
55 | |
protected Object makeNewServiceObject(MessageContext messageContext, String s) throws Exception |
56 | |
{ |
57 | 52 | String transUrl = (String)messageContext.getProperty("transport.url"); |
58 | 52 | int i = transUrl.indexOf('?'); |
59 | 52 | if (i > -1) |
60 | |
{ |
61 | 12 | transUrl = transUrl.substring(0, i); |
62 | |
} |
63 | 52 | AxisMessageReceiver receiver = (AxisMessageReceiver)connector.lookupReceiver(transUrl); |
64 | 52 | if (receiver == null) |
65 | |
{ |
66 | 0 | receiver = (AxisMessageReceiver)connector.lookupReceiver(messageContext.getTargetService()); |
67 | |
} |
68 | 52 | if (receiver == null) |
69 | |
{ |
70 | 0 | throw new AxisFault("Could not find Mule registered service: " + s); |
71 | |
} |
72 | 52 | Class[] classes = AxisServiceProxy.getInterfacesForComponent(receiver.getService()); |
73 | 52 | return AxisServiceProxy.createProxy(receiver, true, classes); |
74 | |
} |
75 | |
|
76 | |
protected Class getServiceClass(String s, SOAPService soapService, MessageContext messageContext) |
77 | |
throws AxisFault |
78 | |
{ |
79 | 52 | Service component = RegistryContext.getRegistry().lookupService(soapService.getName()); |
80 | |
try |
81 | |
{ |
82 | 52 | Class[] classes = AxisServiceProxy.getInterfacesForComponent(component); |
83 | 52 | return Proxy.getProxyClass(Thread.currentThread().getContextClassLoader(), classes); |
84 | |
} |
85 | 0 | catch (Exception e) |
86 | |
{ |
87 | 0 | throw new AxisFault("Failed to implementation class for component: " + e.getMessage(), e); |
88 | |
} |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
protected void setOperationStyle(MessageContext msgContext) |
96 | |
{ |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | 0 | int methodType = msgContext.getOperation().getMessageOperationStyle(); |
106 | 0 | if (methodType > -1) |
107 | |
{ |
108 | |
|
109 | 0 | return; |
110 | |
} |
111 | 0 | OperationDesc operation = msgContext.getOperation(); |
112 | 0 | String methodSignature = operation.getMethod().toString().toLowerCase(); |
113 | 0 | if (methodSignature.indexOf(METHOD_BODYARRAY) != -1) |
114 | |
{ |
115 | 0 | methodType = OperationDesc.MSG_METHOD_BODYARRAY; |
116 | |
} |
117 | 0 | else if (methodSignature.indexOf(METHOD_ELEMENTARRAY) != -1) |
118 | |
{ |
119 | 0 | methodType = OperationDesc.MSG_METHOD_ELEMENTARRAY; |
120 | |
} |
121 | 0 | else if (methodSignature.indexOf(METHOD_DOCUMENT) != -1) |
122 | |
{ |
123 | 0 | methodType = OperationDesc.MSG_METHOD_DOCUMENT; |
124 | |
} |
125 | |
else |
126 | |
{ |
127 | 0 | methodType = OperationDesc.MSG_METHOD_SOAPENVELOPE; |
128 | |
} |
129 | 0 | operation.setMessageOperationStyle(methodType); |
130 | 0 | logger.debug("Now Invoking service (Method Format) " + operation.getMethod().toString()); |
131 | 0 | logger.debug("Now Invoking service (MethodType) " |
132 | |
+ String.valueOf(operation.getMessageOperationStyle())); |
133 | 0 | } |
134 | |
|
135 | |
public void invoke(MessageContext msgContext) throws AxisFault |
136 | |
{ |
137 | |
|
138 | |
|
139 | |
|
140 | 52 | super.invoke(msgContext); |
141 | 52 | if (RequestContext.getExceptionPayload() != null) |
142 | |
{ |
143 | 0 | Throwable t = RequestContext.getExceptionPayload().getException(); |
144 | 0 | if (t instanceof Exception) |
145 | |
{ |
146 | 0 | AxisFault fault = AxisFault.makeFault((Exception)t); |
147 | 0 | if (t instanceof RuntimeException) |
148 | |
{ |
149 | 0 | fault.addFaultDetail(Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION, "true"); |
150 | |
} |
151 | 0 | throw fault; |
152 | |
} |
153 | |
else |
154 | |
{ |
155 | 0 | throw (Error)t; |
156 | |
} |
157 | |
} |
158 | 52 | } |
159 | |
|
160 | |
} |