1 16 package org.apache.axis2.receivers; 17 18 import org.apache.axis2.Constants; 19 import org.apache.axis2.context.MessageContext; 20 import org.apache.axis2.description.OperationDescription; 21 import org.apache.axis2.engine.AxisFault; 22 import org.apache.axis2.engine.DependencyManager; 23 import org.apache.axis2.engine.MessageReceiver; 24 import org.apache.axis2.om.OMElement; 25 import org.apache.axis2.om.OMNamespace; 26 import org.apache.axis2.soap.SOAPEnvelope; 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 import org.apache.wsdl.WSDLService; 30 31 import java.lang.reflect.Method ; 32 33 36 public class RawXMLINOutMessageReceiver 37 extends AbstractInOutSyncMessageReceiver 38 implements MessageReceiver { 39 42 protected Log log = LogFactory.getLog(getClass()); 43 44 47 private String scope; 48 49 52 private ClassLoader classLoader; 53 54 57 public RawXMLINOutMessageReceiver() { 58 scope = Constants.APPLICATION_SCOPE; 59 } 60 61 public void invokeBusinessLogic(MessageContext msgContext, MessageContext newmsgContext) 62 throws AxisFault { 63 try { 64 65 Object obj = getTheImplementationObject(msgContext); 67 68 Class ImplClass = obj.getClass(); 70 71 DependencyManager.configureBusinussLogicProvider(obj, msgContext); 73 74 OperationDescription opDesc = msgContext.getOperationContext().getAxisOperation(); 75 Method method = findOperation(opDesc, ImplClass); 76 if (method != null) { 77 String style = msgContext.getOperationContext().getAxisOperation().getStyle(); 78 79 Class [] parameters = method.getParameterTypes(); 80 Object [] args = null; 81 82 if (parameters == null || parameters.length == 0) { 83 args = new Object [0]; 84 } else if (parameters.length == 1) { 85 OMElement omElement = null; 86 if (WSDLService.STYLE_DOC.equals(style)) { 87 omElement = msgContext.getEnvelope().getBody().getFirstElement(); 88 } else if (WSDLService.STYLE_RPC.equals(style)) { 89 OMElement operationElement = msgContext.getEnvelope().getBody().getFirstElement(); 90 if (operationElement != null) { 91 if (method.getName().equals(operationElement.getLocalName()) 92 || operationElement.getLocalName() != null && operationElement.getLocalName().startsWith(method.getName()) ) { 93 omElement = operationElement.getFirstElement(); 94 } else { 95 throw new AxisFault("Operation Name does not match the immediate child name, expected "+ method.getName() + " but get " + operationElement.getLocalName()); 96 } 97 } else { 98 throw new AxisFault("rpc style expect the immediate child of the SOAP body "); 99 } 100 } else { 101 throw new AxisFault("Unknown style "); 102 } 103 args = new Object [] { omElement }; 104 } else { 105 throw new AxisFault( 106 "Raw Xml provider supports only the methods bearing the signature public OMElement " 107 + "<method-name>(OMElement) where the method name is anything"); 108 } 109 110 OMElement result = (OMElement) method.invoke(obj, args); 111 112 OMElement bodyContent = null; 113 if (WSDLService.STYLE_RPC.equals(style)) { 114 OMNamespace ns = getSOAPFactory().createOMNamespace("http://soapenc/", "res"); 115 bodyContent = 116 getSOAPFactory().createOMElement(method.getName() + "Response", ns); 117 bodyContent.addChild(result); 118 }else{ 119 bodyContent = result; 120 } 121 122 SOAPEnvelope envelope = getSOAPFactory().getDefaultEnvelope(); 123 if(bodyContent!= null){ 124 envelope.getBody().addChild(bodyContent); 125 } 126 newmsgContext.setEnvelope(envelope); 127 } else { 128 throw new AxisFault( 129 "Implementation class does not define a method called" + opDesc.getName()); 130 } 131 } catch (Exception e) { 132 throw AxisFault.makeFault(e); 133 } 134 135 } 136 137 public Method findOperation(OperationDescription op, Class ImplClass) { 138 Method method = null; 139 String methodName = op.getName().getLocalPart(); 140 Method [] methods = ImplClass.getMethods(); 141 for (int i = 0; i < methods.length; i++) { 142 if (methods[i].getName().equals(methodName)) { 143 method = methods[i]; 144 break; 145 } 146 } 147 return method; 148 } 149 } 150 | Popular Tags |