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