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/11/22 11:31:08 UTC
svn commit: r478117 - in
/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing:
MultiHopRedirectService1.java MultiHopRedirectService2.java
MultiHopRedirectServiceTest.java
Author: davidillsley
Date: Wed Nov 22 02:31:07 2006
New Revision: 478117
URL: http://svn.apache.org/viewvc?view=rev&rev=478117
Log:
New integration tests to test and demonstrate a multi-hop,
ws-addressing based service invocation.
Added:
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/MultiHopRedirectService1.java
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/MultiHopRedirectService2.java
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/MultiHopRedirectServiceTest.java
Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/MultiHopRedirectService1.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/MultiHopRedirectService1.java?view=auto&rev=478117
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/MultiHopRedirectService1.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/MultiHopRedirectService1.java Wed Nov 22 02:31:07 2006
@@ -0,0 +1,34 @@
+/*
+* 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.
+*
+*
+*/
+package org.apache.axis2.addressing;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.integration.UtilServer;
+
+public class MultiHopRedirectService1 {
+
+ public OMElement echoRedirect(OMElement ome) throws AxisFault{
+ MessageContext currInMc = MessageContext.getCurrentMessageContext();
+ MessageContext currOutMc = currInMc.getOperationContext().getMessageContext("Out");
+ currOutMc.setTo(new EndpointReference("http://127.0.0.1:" + (UtilServer.TESTING_PORT) + "/axis2/services/MultiHopRedirectService2/echoRedirect"));
+ currOutMc.setReplyTo(currInMc.getReplyTo());
+ return ome;
+ }
+}
Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/MultiHopRedirectService2.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/MultiHopRedirectService2.java?view=auto&rev=478117
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/MultiHopRedirectService2.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/MultiHopRedirectService2.java Wed Nov 22 02:31:07 2006
@@ -0,0 +1,33 @@
+/*
+* 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.
+*
+*
+*/
+package org.apache.axis2.addressing;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+
+public class MultiHopRedirectService2 {
+ public OMElement echoRedirect(OMElement ome) throws AxisFault{
+ System.out.println("MultiHopRedirectService2");
+ MessageContext currInMc = MessageContext.getCurrentMessageContext();
+ MessageContext currOutMc = currInMc.getOperationContext().getMessageContext("Out");
+ currOutMc.setTo(currInMc.getReplyTo());
+ currOutMc.getRelatesTo().setValue(currInMc.getRelatesTo().getValue());
+ return ome;
+ }
+}
Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/MultiHopRedirectServiceTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/MultiHopRedirectServiceTest.java?view=auto&rev=478117
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/MultiHopRedirectServiceTest.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/addressing/MultiHopRedirectServiceTest.java Wed Nov 22 02:31:07 2006
@@ -0,0 +1,167 @@
+/*
+* 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.
+*
+*
+*/
+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.InOutAxisOperation;
+import org.apache.axis2.description.OutInAxisOperation;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.engine.util.TestConstants;
+import org.apache.axis2.integration.UtilServer;
+import org.apache.axis2.integration.UtilServerBasedTestCase;
+import org.apache.axis2.receivers.RawXMLINOutMessageReceiver;
+
+/**
+ * This tests that it is possible to use the more advanced function allowed by the WS-Addressing
+ * specification to redirect responses. This test sets up 2 services, MultiHopRedirectService1 and
+ * MultiHopRedirectService2.
+ * MultiHopRedirectService1 echos the XML it receives to MultiHopRedirectService2, adding the
+ * original ReplyTo.
+ * MultiHopRedirectService2 then echos the XML to the orignal ReplyTo, setting the RelatesTo to
+ * the messageID of the original request message to allow the client to correlate the message.
+ *
+ * The clearly only works if the client is using a separate listener (which the client in the test does)
+ */
+public class MultiHopRedirectServiceTest extends UtilServerBasedTestCase implements TestConstants {
+
+ EndpointReference targetEPR = new EndpointReference(
+ "http://127.0.0.1:" + (UtilServer.TESTING_PORT) + "/axis2/services/MultiHopRedirectService1/echoRedirect");
+
+ protected AxisConfiguration engineRegistry;
+ protected MessageContext mc;
+ protected ServiceContext serviceContext;
+ protected AxisService mhs1;
+ protected AxisService mhs2;
+
+ public static Test suite() {
+ return getTestSetup(new TestSuite(MultiHopRedirectServiceTest.class));
+ }
+
+ protected void setUp() throws Exception {
+ mhs1 = createMultiHopRedirectService1();
+ mhs2 = createMultiHopRedirectService2();
+ UtilServer.deployService(mhs1);
+ UtilServer.deployService(mhs2);
+ }
+
+ AxisService createMultiHopRedirectService1() throws AxisFault {
+ AxisService service = new AxisService("MultiHopRedirectService1");
+
+ service.setClassLoader(Thread.currentThread().getContextClassLoader());
+ service.addParameter(new Parameter(Constants.SERVICE_CLASS, MultiHopRedirectService1.class.getName()));
+
+ AxisOperation axisOp = new InOutAxisOperation(new QName("echoRedirect"));
+
+ axisOp.setMessageReceiver(new RawXMLINOutMessageReceiver());
+ service.addOperation(axisOp);
+ service.mapActionToOperation(Constants.AXIS2_NAMESPACE_URI + "/" + "echoRedirect", axisOp);
+
+ return service;
+ }
+
+ AxisService createMultiHopRedirectService2() throws AxisFault {
+ AxisService service = new AxisService("MultiHopRedirectService2");
+
+ service.setClassLoader(Thread.currentThread().getContextClassLoader());
+ service.addParameter(new Parameter(Constants.SERVICE_CLASS, MultiHopRedirectService2.class.getName()));
+
+ AxisOperation axisOp = new InOutAxisOperation(new QName("echoRedirect"));
+
+ axisOp.setMessageReceiver(new RawXMLINOutMessageReceiver());
+ service.addOperation(axisOp);
+ service.mapActionToOperation(Constants.AXIS2_NAMESPACE_URI + "/" + "echoRedirect", axisOp);
+
+ return service;
+ }
+
+ protected void tearDown() throws Exception {
+ UtilServer.unDeployService(new QName("MultiHopRedirectService1"));
+ UtilServer.unDeployService(new QName("MultiHopRedirectService2"));
+ UtilServer.unDeployClientService();
+ }
+
+ public void testMultiHop() throws Exception {
+ OMElement method = createElement("this message should not cause a fault.");
+ ServiceClient sender = null;
+
+ try {
+ sender = createServiceClient();
+ OMElement response = sender.sendReceive(new QName("echoRedirect"), method);
+ assertEquals("this message should not cause a fault.", response.getText());
+ } finally {
+ if (sender != null)
+ sender.cleanup();
+ }
+ }
+
+ private OMElement createElement(String text) {
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+
+ OMNamespace omNs = fac.createOMNamespace(Constants.AXIS2_NAMESPACE_URI+"/addressing", "axis2addressing");
+ OMElement value = fac.createOMElement("element", omNs);
+ value.setText(text);
+
+ return value;
+ }
+
+ private ServiceClient createServiceClient() throws AxisFault {
+ AxisService service = new AxisService("MultiHopRedirectService1");
+
+ service.setClassLoader(Thread.currentThread().getContextClassLoader());
+ service.addParameter(new Parameter(Constants.SERVICE_CLASS, MultiHopRedirectService1.class.getName()));
+
+ AxisOperation axisOp = new OutInAxisOperation(new QName("echoRedirect"));
+
+ axisOp.setMessageReceiver(new RawXMLINOutMessageReceiver());
+ axisOp.setSoapAction(Constants.AXIS2_NAMESPACE_URI + "/" + "echoRedirect");
+ axisOp.setOutputAction(Constants.AXIS2_NAMESPACE_URI + "/" + "echoRedirect");
+ service.addOperation(axisOp);
+ service.mapActionToOperation(Constants.AXIS2_NAMESPACE_URI + "/" + "echoRedirect", axisOp);
+
+ ConfigurationContext configcontext = UtilServer.createClientConfigurationContext();
+
+ ServiceClient sender;
+
+ Options options = new Options();
+ options.setTo(targetEPR);
+ options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+ options.setUseSeparateListener(true);
+ sender = new ServiceClient(configcontext, service);
+ sender.setOptions(options);
+ sender.engageModule(new QName("addressing"));
+ return sender;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org