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