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