You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by da...@apache.org on 2006/08/02 16:31:54 UTC

svn commit: r428006 - in /webservices/axis2/trunk/java/modules: core/src/org/apache/axis2/description/ integration/test/org/apache/axis2/addressing/

Author: davidillsley
Date: Wed Aug  2 07:31:53 2006
New Revision: 428006

URL: http://svn.apache.org/viewvc?rev=428006&view=rev
Log:
Committing patch for AXIS2-789 including a new redirection integration test.
David

Added:
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/AddressingServiceTest.java
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/RedirectReceiver.java
Modified:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisOperation.java

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisOperation.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisOperation.java?rev=428006&r1=428005&r2=428006&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisOperation.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisOperation.java Wed Aug  2 07:31:53 2006
@@ -278,9 +278,11 @@
         return operation;
     }
 
+    
+    
 
     /**
-     * Creates a new operation context if there is not one already.
+     * Returns as existing OperationContext related to this message if one exists.
      *
      * @param msgContext
      * @return Returns OperationContext.
@@ -294,21 +296,20 @@
             return operationContext;
         }
 
-        if (null == msgContext.getRelatesTo()) {
-            return null;
-        } else {
-
-            // So this message is part of an ongoing MEP
+        // If this message is not related to another one, or it is but not one emitted
+        // from the same operation, don't further look for an operation context or fault.
+        if (null != msgContext.getRelatesTo()) {
+            // So this message may be part of an ongoing MEP
             ConfigurationContext configContext = msgContext.getConfigurationContext();
 
             operationContext =
                     configContext.getOperationContext(msgContext.getRelatesTo().getValue());
 
-            if (null == operationContext) {
-                throw new AxisFault("cannot Correalte Msg " + this.getName().toString() + " for the " + msgContext.getRelatesTo().getValue());
-            }
+            if (null == operationContext && log.isDebugEnabled()) {
+            	log.debug("Cannot correlate inbound message RelatesTo value ["+msgContext.getRelatesTo()+"] to in-progree MEP");
+        	}
         }
-
+        
         return operationContext;
     }
 

Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/AddressingServiceTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/AddressingServiceTest.java?rev=428006&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/AddressingServiceTest.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/AddressingServiceTest.java Wed Aug  2 07:31:53 2006
@@ -0,0 +1,217 @@
+package org.apache.axis2.addressing;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.InOnlyAxisOperation;
+import org.apache.axis2.description.OutOnlyAxisOperation;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.engine.Echo;
+import org.apache.axis2.engine.util.TestConstants;
+import org.apache.axis2.integration.UtilServer;
+import org.apache.axis2.integration.UtilServerBasedTestCase;
+import org.apache.axis2.receivers.AbstractMessageReceiver;
+import org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver;
+import org.apache.axis2.receivers.RawXMLINOutMessageReceiver;
+import org.apache.axis2.util.Utils;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+/*
+* Copyright 2004,2005,2006 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 AddressingServiceTest extends UtilServerBasedTestCase implements TestConstants {
+
+	private static final Log log = LogFactory.getLog(AddressingServiceTest.class);
+    protected QName transportName = new QName("http://localhost/my",
+            "NullTransport");
+    EndpointReference targetEPR = new EndpointReference(
+            "http://127.0.0.1:" + (UtilServer.TESTING_PORT) + "/axis2/services/EchoXMLService/echoOMElement");
+
+    EndpointReference replyTo = new EndpointReference(
+            "http://127.0.0.1:" + (UtilServer.TESTING_PORT) + "/axis2/services/RedirectReceiverService/echoOMElementResponse");
+    
+    EndpointReference faultTo = new EndpointReference(
+            "http://127.0.0.1:" + (UtilServer.TESTING_PORT) + "/axis2/services/RedirectReceiverService/fault");
+    
+    protected AxisConfiguration engineRegistry;
+    protected MessageContext mc;
+    protected ServiceContext serviceContext;
+    protected AxisService echoService;
+    protected AxisService rrService;
+
+    public static Test suite() {
+        return getTestSetup(new TestSuite(AddressingServiceTest.class));
+    }
+
+    protected void setUp() throws Exception {
+        echoService = Utils.createSimpleService(serviceName,
+                new RawXMLINOutMessageReceiver(),
+                Echo.class.getName(),
+                operationName);
+        UtilServer.deployService(echoService);
+        
+        rrService = createRedirectReceiverService();
+        UtilServer.deployService(rrService);
+    }
+    
+    AxisService createRedirectReceiverService() throws AxisFault {
+        AxisService service = new AxisService("RedirectReceiverService");
+        
+        service.setClassLoader(Thread.currentThread().getContextClassLoader());
+        service.addParameter(new Parameter(AbstractMessageReceiver.SERVICE_CLASS, RedirectReceiver.class.getName()));
+        
+        AxisOperation axisOp = new InOnlyAxisOperation(new QName("echoOMElementResponse"));
+        
+        axisOp.setMessageReceiver(new RawXMLINOnlyMessageReceiver());
+        axisOp.setStyle(WSDLConstants.STYLE_RPC);
+        service.addOperation(axisOp);
+        service.mapActionToOperation(Constants.AXIS2_NAMESPACE_URI + "/" + "echoOMElementResponse", axisOp);
+        
+        AxisOperation axisOp2 = new InOnlyAxisOperation(new QName("fault"));
+        
+        axisOp2.setMessageReceiver(new RawXMLINOnlyMessageReceiver());
+        axisOp2.setStyle(WSDLConstants.STYLE_RPC);
+        service.addOperation(axisOp2);
+        service.mapActionToOperation(Constants.AXIS2_NAMESPACE_URI + "/" + "fault", axisOp2);
+        
+        return service;
+    }
+    
+    protected void tearDown() throws Exception {
+        UtilServer.unDeployService(serviceName);
+        UtilServer.unDeployService(new QName("RedirectReceiverService"));
+        UtilServer.unDeployClientService();
+    }
+    
+    public static AxisService createSimpleOneWayServiceforClient(QName serviceName,
+            String className,
+            QName opName)
+    throws AxisFault {
+        AxisService service = new AxisService(serviceName.getLocalPart());
+        
+        service.setClassLoader(Thread.currentThread().getContextClassLoader());
+        service.addParameter(new Parameter(AbstractMessageReceiver.SERVICE_CLASS, className));
+        
+        AxisOperation axisOp = new OutOnlyAxisOperation(opName);
+        
+        axisOp.setMessageReceiver(new RawXMLINOnlyMessageReceiver());
+        axisOp.setStyle(WSDLConstants.STYLE_RPC);
+        service.addOperation(axisOp);
+        
+        return service;
+    }
+    
+    public void testEchoToReplyTo() throws Exception {
+        OMElement method = createEchoOMElement("this message should not cause a fault.");
+        ServiceClient sender = null;
+
+        try {
+            sender = createServiceClient();
+            sender.fireAndForget(operationName, method);
+            System.out.println("send the reqest");
+            int index = 0;
+            while (!RedirectReceiver.hasReceivedResponse()) {
+                Thread.sleep(100);
+                index++;
+                if (index > 45) {
+                    throw new AxisFault(
+                            "Tests was failed as redirected response not received in time");
+                }
+            }
+        } finally {
+            if (sender != null)
+                sender.finalizeInvoke();
+        }
+    }
+
+    public void testFaultToFaultTo() throws Exception {
+        OMElement method = createEchoOMElement("fault");
+        ServiceClient sender = null;
+
+        try {
+            sender = createServiceClient();
+            sender.fireAndForget(operationName, method);
+            System.out.println("send the reqest");
+            int index = 0;
+            while (!RedirectReceiver.hasReceivedFault()) {
+                Thread.sleep(100);
+                index++;
+                if (index > 45) {
+                    throw new AxisFault(
+                            "Tests was failed as redirected fault not received in time");
+                }
+            }
+        } finally {
+            if (sender != null)
+                sender.finalizeInvoke();
+        }
+    }
+    
+    private OMElement createEchoOMElement(String text){
+        OMFactory fac = OMAbstractFactory.getOMFactory();
+
+        OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
+        OMElement method = fac.createOMElement("echoOMElement", omNs);
+        OMElement value = fac.createOMElement("myValue", omNs);
+        value.setText(text);
+        method.addChild(value);
+        
+        return method;
+    }
+    
+    private ServiceClient createServiceClient() throws AxisFault{
+        AxisService service =
+            createSimpleOneWayServiceforClient(serviceName,
+                        Echo.class.getName(),
+                        operationName);
+
+        ConfigurationContext configcontext = UtilServer.createClientConfigurationContext();
+
+        ServiceClient sender = null;
+        
+        Options options = new Options();
+        options.setTo(targetEPR);
+        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+        options.setAction(operationName.getLocalPart());
+        options.setReplyTo(replyTo);
+        options.setFaultTo(faultTo);
+
+        sender = new ServiceClient(configcontext, service);
+        sender.setOptions(options);
+        sender.engageModule(new QName("addressing"));
+        
+        return sender;
+    }
+}

Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/RedirectReceiver.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/RedirectReceiver.java?rev=428006&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/RedirectReceiver.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/RedirectReceiver.java Wed Aug  2 07:31:53 2006
@@ -0,0 +1,43 @@
+/*
+* Copyright 2006 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.
+*
+*
+*/
+package org.apache.axis2.addressing;
+
+import org.apache.axiom.om.OMElement;
+
+public class RedirectReceiver {
+
+    private static boolean responseRecieved = false;
+    public static boolean hasReceivedResponse(){
+        return responseRecieved;
+    }
+    
+    private static boolean faultRecieved = false;
+    public static boolean hasReceivedFault(){
+        return faultRecieved;
+    }
+    
+    public void echoOMElementResponse(OMElement omEle) {
+        System.out.println("echoOMElementResponse: "+omEle);
+        responseRecieved = true;
+    }
+    
+    public void fault(OMElement omEle) {
+        System.out.println("fault: "+omEle);
+        faultRecieved = true;
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org