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