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.OMAbstractFactory; 25 import org.apache.axis2.om.OMElement; 26 import org.apache.axis2.om.OMNamespace; 27 import org.apache.axis2.soap.SOAPEnvelope; 28 import org.apache.axis2.soap.SOAPFactory; 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 import org.apache.wsdl.WSDLService; 32 33 import java.lang.reflect.Method ; 34 35 38 public class RawXMLINOnlyMessageReceiver 39 extends AbstractInMessageReceiver 40 implements MessageReceiver { 41 44 protected Log log = LogFactory.getLog(getClass()); 45 46 49 private String scope; 50 51 54 private Method method; 55 56 59 private ClassLoader classLoader; 60 61 64 public RawXMLINOnlyMessageReceiver() { 65 scope = Constants.APPLICATION_SCOPE; 66 } 67 68 public void invokeBusinessLogic(MessageContext msgContext) 69 throws AxisFault { 70 try { 71 72 Object obj = getTheImplementationObject(msgContext); 74 75 Class ImplClass = obj.getClass(); 77 DependencyManager.configureBusinussLogicProvider(obj,msgContext); 78 79 OperationDescription op = msgContext.getOperationContext().getAxisOperation(); 80 if (op == null) { 81 throw new AxisFault("Operation is not located, if this is doclit style the SOAP-ACTION should specified via the SOAP Action to use the RawXMLProvider"); 82 } 83 String methodName = op.getName().getLocalPart(); 84 Method [] methods = ImplClass.getMethods(); 85 for (int i = 0; i < methods.length; i++) { 86 if (methods[i].getName().equals(methodName)) { 87 this.method = methods[i]; 88 break; 89 } 90 } 91 Class [] parameters = method.getParameterTypes(); 92 if ((parameters != null) 93 && (parameters.length == 1) 94 && OMElement.class.getName().equals(parameters[0].getName())) { 95 OMElement methodElement = msgContext.getEnvelope().getBody().getFirstElement(); 96 97 OMElement parmeter = null; 98 SOAPEnvelope envelope = null; 99 100 String style = msgContext.getOperationContext().getAxisOperation().getStyle(); 101 102 if (WSDLService.STYLE_DOC.equals(style)) { 103 parmeter = methodElement; 104 Object [] parms = new Object [] { parmeter }; 105 106 OMElement result = (OMElement) method.invoke(obj, parms); 108 envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope(); 109 envelope.getBody().setFirstChild(result); 110 111 } else if (WSDLService.STYLE_RPC.equals(style)) { 112 parmeter = methodElement.getFirstElement(); 113 Object [] parms = new Object [] { parmeter }; 114 115 OMElement result = (OMElement) method.invoke(obj, parms); 117 SOAPFactory fac = OMAbstractFactory.getSOAP11Factory(); 118 envelope = fac.getDefaultEnvelope(); 119 120 OMNamespace ns = fac.createOMNamespace("http://soapenc/", "res"); 121 OMElement responseMethodName = fac.createOMElement(methodName + "Response", ns); 122 if (result != null) { 123 responseMethodName.addChild(result); 124 } 125 if (responseMethodName != null) { 126 envelope.getBody().addChild(responseMethodName); 127 } 128 } else { 129 throw new AxisFault("Unknown style "); 130 } 131 } else { 132 throw new AxisFault( 133 "Raw Xml provider supports only the methods bearing the signature public OMElement " 134 + "<method-name>(OMElement) where the method name is anything"); 135 } 136 } catch (Exception e) { 137 throw AxisFault.makeFault(e); 138 } 139 140 } 141 } 142 | Popular Tags |