1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transport.soap.axis.extensions; |
12 | |
|
13 | |
import org.mule.MuleServer; |
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 | |
import java.util.ArrayList; |
22 | |
import java.util.Iterator; |
23 | |
|
24 | |
import javax.xml.namespace.QName; |
25 | |
import javax.xml.rpc.holders.Holder; |
26 | |
|
27 | |
import org.apache.axis.AxisFault; |
28 | |
import org.apache.axis.Constants; |
29 | |
import org.apache.axis.MessageContext; |
30 | |
import org.apache.axis.constants.Style; |
31 | |
import org.apache.axis.description.OperationDesc; |
32 | |
import org.apache.axis.description.ParameterDesc; |
33 | |
import org.apache.axis.description.ServiceDesc; |
34 | |
import org.apache.axis.handlers.soap.SOAPService; |
35 | |
import org.apache.axis.message.RPCElement; |
36 | |
import org.apache.axis.message.RPCHeaderParam; |
37 | |
import org.apache.axis.message.RPCParam; |
38 | |
import org.apache.axis.message.SOAPEnvelope; |
39 | |
import org.apache.axis.providers.java.RPCProvider; |
40 | |
import org.apache.axis.soap.SOAPConstants; |
41 | |
import org.apache.axis.utils.JavaUtils; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public class MuleRPCProvider extends RPCProvider |
48 | |
{ |
49 | |
|
50 | |
|
51 | |
|
52 | |
private static final long serialVersionUID = -4987111047650933518L; |
53 | |
|
54 | |
private AxisConnector connector; |
55 | |
|
56 | |
public MuleRPCProvider(AxisConnector connector) |
57 | 326 | { |
58 | 326 | this.connector = connector; |
59 | 326 | } |
60 | |
|
61 | |
protected Object makeNewServiceObject(MessageContext messageContext, String s) throws Exception |
62 | |
{ |
63 | 108 | String transUrl = (String)messageContext.getProperty("transport.url"); |
64 | 108 | int i = transUrl.indexOf("?"); |
65 | 108 | if (i > -1) |
66 | |
{ |
67 | 42 | transUrl = transUrl.substring(0, i); |
68 | |
} |
69 | 108 | AxisMessageReceiver receiver = (AxisMessageReceiver)connector.lookupReceiver(transUrl); |
70 | 108 | if (receiver == null) |
71 | |
{ |
72 | 64 | receiver = (AxisMessageReceiver)connector.lookupReceiver(messageContext.getTargetService()); |
73 | |
} |
74 | 108 | if (receiver == null) |
75 | |
{ |
76 | 0 | throw new AxisFault("Could not find Mule registered service: " + s); |
77 | |
} |
78 | 108 | Class[] classes = AxisServiceProxy.getInterfacesForComponent(receiver.getService()); |
79 | 108 | return AxisServiceProxy.createProxy(receiver, true, classes); |
80 | |
} |
81 | |
|
82 | |
protected Class getServiceClass(String s, SOAPService soapService, MessageContext messageContext) |
83 | |
throws AxisFault |
84 | |
{ |
85 | 84 | Service component = MuleServer.getMuleContext().getRegistry().lookupService(soapService.getName()); |
86 | |
try |
87 | |
{ |
88 | 84 | Class[] classes = AxisServiceProxy.getInterfacesForComponent(component); |
89 | 84 | return Proxy.getProxyClass(Thread.currentThread().getContextClassLoader(), classes); |
90 | |
} |
91 | 0 | catch (Exception e) |
92 | |
{ |
93 | 0 | throw new AxisFault("Failed to implementation class for component: " + e.getMessage(), e); |
94 | |
} |
95 | |
} |
96 | |
|
97 | |
public void invoke(MessageContext msgContext) throws AxisFault |
98 | |
{ |
99 | 108 | super.invoke(msgContext); |
100 | 100 | if (RequestContext.getExceptionPayload() != null) |
101 | |
{ |
102 | 0 | Throwable t = RequestContext.getExceptionPayload().getException(); |
103 | 0 | if (t instanceof Exception) |
104 | |
{ |
105 | 0 | AxisFault fault = AxisFault.makeFault((Exception)t); |
106 | 0 | if (t instanceof RuntimeException) |
107 | |
{ |
108 | 0 | fault.addFaultDetail(Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION, "true"); |
109 | |
} |
110 | 0 | throw fault; |
111 | |
} |
112 | |
else |
113 | |
{ |
114 | 0 | throw (Error)t; |
115 | |
} |
116 | |
} |
117 | 100 | } |
118 | |
|
119 | |
protected RPCElement createResponseBody(RPCElement body, |
120 | |
MessageContext msgContext, |
121 | |
OperationDesc operation, |
122 | |
ServiceDesc serviceDesc, |
123 | |
Object objRes, |
124 | |
SOAPEnvelope resEnv, |
125 | |
ArrayList outs) throws Exception |
126 | |
{ |
127 | 100 | String methodName = operation.getName(); |
128 | |
|
129 | |
|
130 | 100 | RPCElement resBody = new RPCElement(methodName + "Response"); |
131 | 100 | resBody.setPrefix(body.getPrefix()); |
132 | 100 | resBody.setNamespaceURI(body.getNamespaceURI()); |
133 | 100 | resBody.setEncodingStyle(msgContext.getEncodingStyle()); |
134 | |
try |
135 | |
{ |
136 | |
|
137 | 100 | if (operation.getMethod().getReturnType() != Void.TYPE) |
138 | |
{ |
139 | 84 | QName returnQName = operation.getReturnQName(); |
140 | 84 | if (returnQName == null) |
141 | |
{ |
142 | 82 | String nsp = body.getNamespaceURI(); |
143 | 82 | if (nsp == null || nsp.length() == 0) |
144 | |
{ |
145 | 82 | nsp = serviceDesc.getDefaultNamespace(); |
146 | |
} |
147 | 82 | returnQName = new QName(msgContext.isEncoded() ? "" : nsp, methodName + "Return"); |
148 | |
} |
149 | |
|
150 | 84 | RPCParam param = new RPCParam(returnQName, objRes); |
151 | 84 | param.setParamDesc(operation.getReturnParamDesc()); |
152 | |
|
153 | 84 | if (!operation.isReturnHeader()) |
154 | |
{ |
155 | |
|
156 | 84 | if (msgContext.getSOAPConstants() == SOAPConstants.SOAP12_CONSTANTS |
157 | |
&& (serviceDesc.getStyle().equals(Style.RPC))) |
158 | |
{ |
159 | 0 | RPCParam resultParam = new RPCParam(Constants.QNAME_RPC_RESULT, returnQName); |
160 | 0 | resultParam.setXSITypeGeneration(Boolean.FALSE); |
161 | 0 | resBody.addParam(resultParam); |
162 | |
} |
163 | 84 | resBody.addParam(param); |
164 | |
} |
165 | |
else |
166 | |
{ |
167 | 0 | resEnv.addHeader(new RPCHeaderParam(param)); |
168 | |
} |
169 | |
|
170 | |
} |
171 | |
|
172 | |
|
173 | 100 | if (!outs.isEmpty()) |
174 | |
{ |
175 | 0 | for (Iterator i = outs.iterator(); i.hasNext();) |
176 | |
{ |
177 | |
|
178 | 0 | RPCParam param = (RPCParam)i.next(); |
179 | 0 | Holder holder = (Holder)param.getObjectValue(); |
180 | 0 | Object value = JavaUtils.getHolderValue(holder); |
181 | 0 | ParameterDesc paramDesc = param.getParamDesc(); |
182 | |
|
183 | 0 | param.setObjectValue(value); |
184 | 0 | if (paramDesc != null && paramDesc.isOutHeader()) |
185 | |
{ |
186 | 0 | resEnv.addHeader(new RPCHeaderParam(param)); |
187 | |
} |
188 | |
else |
189 | |
{ |
190 | 0 | resBody.addParam(param); |
191 | |
} |
192 | 0 | } |
193 | |
} |
194 | |
} |
195 | 0 | catch (Exception e) |
196 | |
{ |
197 | 0 | throw e; |
198 | 100 | } |
199 | 100 | return resBody; |
200 | |
} |
201 | |
} |