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