axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dee...@apache.org
Subject svn commit: r394926 - in /webservices/axis2/trunk/java/modules: codegen/src/org/apache/axis2/rpc/receivers/ core/src/org/apache/axis2/receivers/
Date Tue, 18 Apr 2006 12:28:08 GMT
Author: deepal
Date: Tue Apr 18 05:28:04 2006
New Revision: 394926

URL: http://svn.apache.org/viewcvs?rev=394926&view=rev
Log:
- fixing http://issues.apache.org/jira/browse/AXIS2-582
- added two new async message receivers

Added:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCInOutAsyncMessageReceiver.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCUtil.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/receivers/RawXMLINOutAsyncMessageReceiver.java
Modified:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCMessageReceiver.java

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCInOutAsyncMessageReceiver.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCInOutAsyncMessageReceiver.java?rev=394926&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCInOutAsyncMessageReceiver.java
(added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCInOutAsyncMessageReceiver.java
Tue Apr 18 05:28:04 2006
@@ -0,0 +1,123 @@
+package org.apache.axis2.rpc.receivers;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.DependencyManager;
+import org.apache.axis2.receivers.AbstractInOutAsyncMessageReceiver;
+
+import javax.xml.namespace.QName;
+import java.lang.reflect.Method;
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*
+*/
+
+public class RPCInOutAsyncMessageReceiver extends AbstractInOutAsyncMessageReceiver {
+
+    private Method method;
+
+    /**
+     * reflect and get the Java method
+     * - for each i'th param in the java method
+     * - get the first child's i'th child
+     * -if the elem has an xsi:type attr then find the deserializer for it
+     * - if not found,
+     * lookup deser for th i'th param (java type)
+     * - error if not found
+     * - deserialize & save in an object array
+     * - end for
+     * <p/>
+     * - invoke method and get the return value
+     * <p/>
+     * - look up serializer for return value based on the value and type
+     * <p/>
+     * - create response msg and add return value as grand child of <soap:body>
+     *
+     * @param inMessage
+     * @param outMessage
+     * @throws AxisFault
+     */
+
+    public void invokeBusinessLogic(MessageContext inMessage, MessageContext outMessage)
throws AxisFault {
+        try {
+            // get the implementation class for the Web Service
+            Object obj = getTheImplementationObject(inMessage);
+
+            Class ImplClass = obj.getClass();
+            DependencyManager.configureBusinessLogicProvider(obj,
+                    inMessage.getOperationContext());
+
+            AxisOperation op = inMessage.getOperationContext().getAxisOperation();
+            AxisService service = inMessage.getAxisService();
+            OMElement methodElement = inMessage.getEnvelope().getBody()
+                    .getFirstElement();
+
+            OMNamespace namespace = methodElement.getNamespace();
+            if (namespace == null || !service.getSchematargetNamespace().equals(namespace.getName()))
{
+                throw new AxisFault("namespace mismatch require " +
+                        service.getSchematargetNamespace() +
+                        " found " + methodElement.getNamespace().getName());
+            }
+            String methodName = op.getName().getLocalPart();
+            Method[] methods = ImplClass.getMethods();
+            for (int i = 0; i < methods.length; i++) {
+                if (methods[i].getName().equals(methodName)) {
+                    this.method = methods[i];
+                    break;
+                }
+            }
+
+
+            Object[] objectArray = RPCUtil.processRequest(methodElement, method);
+            Object resObject;
+            try {
+                resObject = method.invoke(obj, objectArray);
+            } catch (Exception e) {
+                throw new AxisFault(e.getMessage());
+            }
+            SOAPFactory fac = getSOAPFactory(inMessage);
+
+            // Handling the response
+            OMNamespace ns = fac.createOMNamespace(service.getSchematargetNamespace(),
+                    service.getSchematargetNamespacePrefix());
+            SOAPEnvelope envelope = fac.getDefaultEnvelope();
+            OMElement bodyContent = null;
+
+            if (resObject instanceof Object[]) {
+                QName resName = new QName(service.getSchematargetNamespace(),
+                        method.getName() + "Response",
+                        service.getSchematargetNamespacePrefix());
+                OMElement bodyChild = RPCUtil.getResponseElement(resName, (Object[]) resObject);
+                envelope.getBody().addChild(bodyChild);
+            } else {
+                RPCUtil.processResponse(fac, resObject, bodyContent, ns, envelope, method);
+            }
+
+            outMessage.setEnvelope(envelope);
+
+        } catch (Exception e) {
+            throw AxisFault.makeFault(e);
+        }
+    }
+
+
+}

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCMessageReceiver.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCMessageReceiver.java?rev=394926&r1=394925&r2=394926&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCMessageReceiver.java
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCMessageReceiver.java
Tue Apr 18 05:28:04 2006
@@ -21,32 +21,24 @@
 
 package org.apache.axis2.rpc.receivers;
 
-import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axis2.AxisFault;
-import org.apache.axis2.util.StreamWrapper;
 import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.databinding.typemapping.SimpleTypeMapper;
-import org.apache.axis2.databinding.utils.BeanUtil;
 import org.apache.axis2.description.AxisOperation;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.engine.DependencyManager;
 import org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver;
 
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamReader;
 import java.lang.reflect.Method;
 
 public class RPCMessageReceiver extends AbstractInOutSyncMessageReceiver {
 
 
     private Method method;
-    private String RETURN_WRAPPER = "return";
 
     /**
      * reflect and get the Java method
@@ -100,7 +92,7 @@
             }
 
 
-            Object[] objectArray = processRequest(methodElement);
+            Object[] objectArray = RPCUtil.processRequest(methodElement, method);
             Object resObject;
             try {
                 resObject = method.invoke(obj, objectArray);
@@ -119,59 +111,16 @@
                 QName resName = new QName(service.getSchematargetNamespace(),
                         method.getName() + "Response",
                         service.getSchematargetNamespacePrefix());
-                OMElement bodyChild = getResponseElement(resName, (Object[]) resObject);
+                OMElement bodyChild = RPCUtil.getResponseElement(resName, (Object[]) resObject);
                 envelope.getBody().addChild(bodyChild);
             } else {
-                processResponse(fac, resObject, bodyContent, ns, envelope);
+                RPCUtil.processResponse(fac, resObject, bodyContent, ns, envelope, method);
             }
 
             outMessage.setEnvelope(envelope);
 
         } catch (Exception e) {
             throw AxisFault.makeFault(e);
-        }
-    }
-
-    private Object[] processRequest(OMElement methodElement) throws AxisFault {
-        Class[] parameters = method.getParameterTypes();
-        return BeanUtil.deserialize(methodElement, parameters);
-    }
-
-    private OMElement getResponseElement(QName resname, Object [] objs) {
-        return BeanUtil.getOMElement(resname, objs, RETURN_WRAPPER);
-    }
-
-    private void processResponse(SOAPFactory fac, Object resObject,
-                                 OMElement bodyContent,
-                                 OMNamespace ns,
-                                 SOAPEnvelope envelope) {
-        if (resObject != null) {
-            //simple type
-            if (resObject instanceof OMElement) {
-                bodyContent = (OMElement) resObject;
-            } else if (SimpleTypeMapper.isSimpleType(resObject)) {
-                bodyContent = fac.createOMElement(
-                        method.getName() + "Response", ns);
-                OMElement child = fac.createOMElement(RETURN_WRAPPER, null);
-                child.addChild(fac.createOMText(child, SimpleTypeMapper.getStringValue(resObject)));
-                bodyContent.addChild(child);
-            } else {
-                bodyContent = fac.createOMElement(
-                        method.getName() + "Response", ns);
-                // Java Beans
-                XMLStreamReader xr = BeanUtil.getPullParser(resObject,
-                        new QName(RETURN_WRAPPER));
-                StAXOMBuilder stAXOMBuilder =
-                        OMXMLBuilderFactory.createStAXOMBuilder(
-                                OMAbstractFactory.getOMFactory(), new StreamWrapper(xr));
-                OMElement documentElement = stAXOMBuilder.getDocumentElement();
-                if (documentElement != null) {
-                    bodyContent.addChild(documentElement);
-                }
-            }
-        }
-        if (bodyContent != null) {
-            envelope.getBody().addChild(bodyContent);
         }
     }
 

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCUtil.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCUtil.java?rev=394926&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCUtil.java
(added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/rpc/receivers/RPCUtil.java
Tue Apr 18 05:28:04 2006
@@ -0,0 +1,84 @@
+package org.apache.axis2.rpc.receivers;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.databinding.typemapping.SimpleTypeMapper;
+import org.apache.axis2.databinding.utils.BeanUtil;
+import org.apache.axis2.util.StreamWrapper;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+import java.lang.reflect.Method;
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*
+*/
+
+public class RPCUtil {
+
+    private static String RETURN_WRAPPER = "return";
+
+    public static void processResponse(SOAPFactory fac, Object resObject,
+                                       OMElement bodyContent,
+                                       OMNamespace ns,
+                                       SOAPEnvelope envelope,
+                                       Method method) {
+        if (resObject != null) {
+            //simple type
+            if (resObject instanceof OMElement) {
+                bodyContent = (OMElement) resObject;
+            } else if (SimpleTypeMapper.isSimpleType(resObject)) {
+                bodyContent = fac.createOMElement(
+                        method.getName() + "Response", ns);
+                OMElement child = fac.createOMElement(RETURN_WRAPPER, null);
+                child.addChild(fac.createOMText(child, SimpleTypeMapper.getStringValue(resObject)));
+                bodyContent.addChild(child);
+            } else {
+                bodyContent = fac.createOMElement(
+                        method.getName() + "Response", ns);
+                // Java Beans
+                XMLStreamReader xr = BeanUtil.getPullParser(resObject,
+                        new QName(RETURN_WRAPPER));
+                StAXOMBuilder stAXOMBuilder =
+                        OMXMLBuilderFactory.createStAXOMBuilder(
+                                OMAbstractFactory.getOMFactory(), new StreamWrapper(xr));
+                OMElement documentElement = stAXOMBuilder.getDocumentElement();
+                if (documentElement != null) {
+                    bodyContent.addChild(documentElement);
+                }
+            }
+        }
+        if (bodyContent != null) {
+            envelope.getBody().addChild(bodyContent);
+        }
+    }
+
+    public static Object[] processRequest(OMElement methodElement, Method method) throws
AxisFault {
+        Class[] parameters = method.getParameterTypes();
+        return BeanUtil.deserialize(methodElement, parameters);
+    }
+
+    public static OMElement getResponseElement(QName resname, Object [] objs) {
+        return BeanUtil.getOMElement(resname, objs, RETURN_WRAPPER);
+    }
+
+}

Added: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/receivers/RawXMLINOutAsyncMessageReceiver.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/receivers/RawXMLINOutAsyncMessageReceiver.java?rev=394926&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/receivers/RawXMLINOutAsyncMessageReceiver.java
(added)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/receivers/RawXMLINOutAsyncMessageReceiver.java
Tue Apr 18 05:28:04 2006
@@ -0,0 +1,111 @@
+package org.apache.axis2.receivers;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.DependencyManager;
+import org.apache.axis2.i18n.Messages;
+
+import java.lang.reflect.Method;
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*
+*/
+
+public class RawXMLINOutAsyncMessageReceiver extends AbstractInOutAsyncMessageReceiver {
+
+    public Method findOperation(AxisOperation op, Class ImplClass) {
+        Method method = null;
+        String methodName = op.getName().getLocalPart();
+        Method[] methods = ImplClass.getMethods();
+
+        for (int i = 0; i < methods.length; i++) {
+            if (methods[i].getName().equals(methodName)) {
+                method = methods[i];
+
+                break;
+            }
+        }
+
+        return method;
+    }
+
+    public void invokeBusinessLogic(MessageContext msgContext, MessageContext newmsgContext)
+            throws AxisFault {
+        try {
+
+            // get the implementation class for the Web Service
+            Object obj = getTheImplementationObject(msgContext);
+
+            // find the WebService method
+            Class ImplClass = obj.getClass();
+
+            // Inject the Message Context if it is asked for
+            DependencyManager.configureBusinessLogicProvider(obj,
+                    msgContext.getOperationContext());
+
+            AxisOperation opDesc = msgContext.getOperationContext().getAxisOperation();
+            Method method = findOperation(opDesc, ImplClass);
+
+            if (method != null) {
+                Class[]  parameters = method.getParameterTypes();
+                Object[] args;
+
+                if ((parameters == null) || (parameters.length == 0)) {
+                    args = new Object[0];
+                } else if (parameters.length == 1) {
+                    OMElement omElement = msgContext.getEnvelope().getBody().getFirstElement();
+                    args = new Object[]{omElement};
+                } else {
+                    throw new AxisFault(Messages.getMessage("rawXmlProivdeIsLimited"));
+                }
+
+                OMElement result;
+                try {
+                    result = (OMElement) method.invoke(obj, args);
+                } catch (Exception e) {
+                    throw new AxisFault(e.getMessage());
+                }
+
+                AxisService service = msgContext.getAxisService();
+                service.getTargetNamespace();
+                result.declareNamespace(service.getTargetNamespace(),
+                        service.getTargetNamespacePrefix());
+                OMElement bodyContent;
+
+                SOAPFactory fac = getSOAPFactory(msgContext);
+                bodyContent = result;
+
+                SOAPEnvelope envelope = fac.getDefaultEnvelope();
+
+                if (bodyContent != null) {
+                    envelope.getBody().addChild(bodyContent);
+                }
+
+                newmsgContext.setEnvelope(envelope);
+            } else {
+                throw new AxisFault(Messages.getMessage("methodNotImplemented",
+                        opDesc.getName().toString()));
+            }
+        } catch (Exception e) {
+            throw AxisFault.makeFault(e);
+        }
+    }
+}



Mime
View raw message