You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2005/12/07 03:41:59 UTC

svn commit: r354671 - in /webservices/axis2/trunk/java/modules/integration: project.xml test/org/apache/axis2/integration/UtilsJMSServer.java test/org/apache/axis2/jms/ test/org/apache/axis2/jms/JMSEchoRawXMLTest.java

Author: dims
Date: Tue Dec  6 18:41:55 2005
New Revision: 354671

URL: http://svn.apache.org/viewcvs?rev=354671&view=rev
Log:
Bingo! got JMSEchoRawXMLTest working with ActiveMQ (commented out of harness!)

PS: Please bear with me while i clean up the code. don't want to lose the work and hence the check-in.


Added:
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/UtilsJMSServer.java
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/jms/
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/jms/JMSEchoRawXMLTest.java
Modified:
    webservices/axis2/trunk/java/modules/integration/project.xml

Modified: webservices/axis2/trunk/java/modules/integration/project.xml
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/project.xml?rev=354671&r1=354670&r2=354671&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/project.xml (original)
+++ webservices/axis2/trunk/java/modules/integration/project.xml Tue Dec  6 18:41:55 2005
@@ -270,6 +270,7 @@
                 <exclude>**/*Util*.java</exclude>
                 <exclude>**/*InteropStubTest.java</exclude>
                 <exclude>**org/apache/axis2/mail/*.java</exclude>
+                <exclude>**org/apache/axis2/jms/*.java</exclude>
                 <exclude>**org/apache/axis2/soap12testing/soap12testsuite/*.java</exclude>
                 <exclude>**/ScenarioST1Test.java</exclude>
             </excludes>

Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/UtilsJMSServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/UtilsJMSServer.java?rev=354671&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/UtilsJMSServer.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/UtilsJMSServer.java Tue Dec  6 18:41:55 2005
@@ -0,0 +1,113 @@
+/*
+ * 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.
+ */
+
+package org.apache.axis2.integration;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.transport.jms.SimpleJMSListener;
+import org.apache.axis2.transport.jms.JMSConstants;
+import org.apache.axis2.transport.jms.JNDIVendorAdapter;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.context.ServiceGroupContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.util.Utils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+import java.io.File;
+import java.util.HashMap;
+
+public class UtilsJMSServer {
+    private static int count = 0;
+    private static SimpleJMSListener receiver;
+
+    public static final int TESTING_PORT = 5555;
+    public static final String FAILURE_MESSAGE = "Intentional Failure";
+    private static Log log = LogFactory.getLog(UtilsJMSServer.class);
+
+    public static synchronized void deployService(AxisService service)
+            throws AxisFault {
+
+        receiver.getSystemContext().getAxisConfiguration().addService(service);
+
+        Utils.resolvePhases(receiver.getSystemContext().getAxisConfiguration(),
+                service);
+        ServiceGroupContext serviceGroupContext = service.getParent().getServiceGroupContext(receiver.getSystemContext());
+
+    }
+
+    public static synchronized void unDeployService(QName service)
+            throws AxisFault {
+        receiver.getSystemContext().getAxisConfiguration().removeService(service.getLocalPart());
+    }
+
+    public static synchronized void start() throws Exception {
+        if (count == 0) {
+
+            HashMap connectorMap = new HashMap();
+            HashMap cfMap = new HashMap();
+            String destination = "dynamicQueues/FOO.BAR";
+            String username = null;
+            String password = null;
+            boolean doThreads = true;
+                
+            cfMap.put(JNDIVendorAdapter.CONNECTION_FACTORY_JNDI_NAME, "ConnectionFactory");
+            cfMap.put(JNDIVendorAdapter.CONTEXT_FACTORY, "org.activemq.jndi.ActiveMQInitialContextFactory");
+            cfMap.put(JNDIVendorAdapter.PROVIDER_URL, "tcp://localhost:61616");
+
+            //start JMS server
+            ConfigurationContextFactory erfac =
+                    new ConfigurationContextFactory();
+            File file = new File(org.apache.axis2.Constants.TESTING_REPOSITORY);
+            System.out.println(file.getAbsoluteFile());
+            if (!file.exists()) {
+                throw new Exception("Repository directory does not exist");
+            }
+
+             ConfigurationContext er  = erfac.buildConfigurationContext(
+                    file.getAbsolutePath());
+            try {
+                Thread.sleep(2000);
+            } catch (InterruptedException e1) {
+                throw new AxisFault("Thread interuptted", e1);
+            }
+            er.getAxisConfiguration().engageModule(
+                    new QName("addressing"));
+            receiver =
+                    new SimpleJMSListener(org.apache.axis2.Constants.TESTING_REPOSITORY, connectorMap, cfMap, destination, username, password, doThreads);
+            receiver.start();
+
+        }
+        count++;
+    }
+
+    public static synchronized void stop() {
+        try {
+            if (count == 1) {
+                receiver.shutdown();
+                count = 0;
+                System.out.print("Server stopped .....");
+            } else {
+                count--;
+            }
+        } catch (Exception e) {
+           log.error(e.getMessage(), e);
+        }
+    }
+
+}

Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/jms/JMSEchoRawXMLTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/jms/JMSEchoRawXMLTest.java?rev=354671&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/jms/JMSEchoRawXMLTest.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/jms/JMSEchoRawXMLTest.java Tue Dec  6 18:41:55 2005
@@ -0,0 +1,252 @@
+/*
+ * 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.
+ */
+
+package org.apache.axis2.jms;
+
+
+import junit.framework.TestCase;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.transport.jms.JMSConstants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.async.AsyncResult;
+import org.apache.axis2.client.async.Callback;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.Echo;
+import org.apache.axis2.integration.UtilServer;
+import org.apache.axis2.integration.UtilsJMSServer;
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMFactory;
+import org.apache.axis2.om.OMNamespace;
+import org.apache.axis2.soap.SOAPFactory;
+import org.apache.axis2.util.Utils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+
+public class JMSEchoRawXMLTest extends TestCase {
+    private EndpointReference targetEPR =
+            new EndpointReference("jms:/dynamicQueues/FOO.BAR?ConnectionFactoryJNDIName=ConnectionFactory&java.naming.factory.initial=org.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616");
+    private QName serviceName = new QName("EchoXMLService");
+    private QName operationName = new QName("echoOMElement");
+
+    private AxisService service;
+    private AxisService clientService;
+    private ServiceContext serviceContext;
+
+    private boolean finish = false;
+    private Log log = LogFactory.getLog(getClass());
+
+    public JMSEchoRawXMLTest() {
+        super(JMSEchoRawXMLTest.class.getName());
+    }
+
+    public JMSEchoRawXMLTest(String testName) {
+        super(testName);
+    }
+
+    protected void setUp() throws Exception {
+        UtilsJMSServer.start();
+
+        //create and deploy the service
+        service =
+                Utils.createSimpleService(serviceName,
+                        Echo.class.getName(),
+                        operationName);
+        UtilsJMSServer.deployService(service);
+        clientService = Utils.createSimpleService(serviceName,
+                Echo.class.getName(),
+                operationName);
+        serviceContext = UtilServer.createAdressedEnabledClientSide(clientService);
+    }
+
+    protected void tearDown() throws Exception {
+        UtilsJMSServer.stop();
+    }
+
+    private OMElement createPayload() {
+        OMFactory fac = OMAbstractFactory.getOMFactory();
+        OMNamespace omNs = fac.createOMNamespace("http://localhost/axis2/services/EchoXMLService", "my");
+        OMElement method = fac.createOMElement("echoOMElement", omNs);
+        OMElement value = fac.createOMElement("myValue", omNs);
+        value.addChild(
+                fac.createText(value, "Isaac Assimov, the foundation Sega"));
+        method.addChild(value);
+
+        return method;
+    }
+
+    public void testEchoXMLASync() throws Exception {
+        OMElement payload = createPayload();
+
+        org.apache.axis2.client.Call call = new org.apache.axis2.client.Call(
+                serviceContext);
+
+        Options options = new Options();
+        call.setClientOptions(options);
+        options.setTo(targetEPR);
+        call.engageModule(new QName(Constants.MODULE_ADDRESSING));
+        options.setListenerTransportProtocol(Constants.TRANSPORT_JMS);
+        options.setUseSeparateListener(false);
+        options.setAction(serviceName.getLocalPart());
+        options.setSoapAction("echoOMElement");
+        options.getProperties().put(JMSConstants.DESTINATION, "dynamicQueues/FOO.BAR");
+        options.getProperties().put(JMSConstants.WAIT_FOR_RESPONSE, Boolean.TRUE);
+        options.getProperties().put(JMSConstants._TIMEOUT_TIME, new Long(100000));
+
+        Callback callback = new Callback() {
+            public void onComplete(AsyncResult result) {
+                try {
+                    result.getResponseEnvelope().serialize(XMLOutputFactory.newInstance()
+                            .createXMLStreamWriter(System.out));
+                } catch (XMLStreamException e) {
+                    reportError(e);
+                } finally {
+                    finish = true;
+                }
+            }
+
+            public void reportError(Exception e) {
+                log.info(e.getMessage());
+                finish = true;
+            }
+        };
+
+        call.invokeNonBlocking(operationName.getLocalPart(),
+                payload,
+                callback);
+        int index = 0;
+        while (!finish) {
+            Thread.sleep(10000);
+            index++;
+            if (index > 10) {
+                throw new AxisFault(
+                        "Server was shutdown as the async response take too long to complete");
+            }
+        }
+        call.close();
+    }
+
+    public void testEchoXMLSync() throws Exception {
+        SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
+
+        OMElement payload = createPayload();
+
+        org.apache.axis2.client.Call call = new org.apache.axis2.client.Call(
+                serviceContext);
+
+        Options options = new Options();
+        call.setClientOptions(options);
+        options.setTo(targetEPR);
+        call.engageModule(new QName(Constants.MODULE_ADDRESSING));
+        options.setListenerTransportProtocol(Constants.TRANSPORT_JMS);
+        options.setUseSeparateListener(false);
+        options.setAction(serviceName.getLocalPart());
+        options.setSoapAction("EchoXMLService/echoOMElement");
+        options.getProperties().put(JMSConstants.DESTINATION, "dynamicQueues/FOO.BAR");
+        options.getProperties().put(JMSConstants.WAIT_FOR_RESPONSE, Boolean.TRUE);
+        options.getProperties().put(JMSConstants._TIMEOUT_TIME, new Long(100000));
+
+        OMElement result =
+                call.invokeBlocking(operationName.getLocalPart(),
+                        payload);
+        result.serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(
+                System.out));
+        call.close();
+    }
+
+//    public void testEchoXMLCompleteSync() throws Exception {
+//        AxisService service =
+//                Utils.createSimpleService(serviceName,
+//                        Echo.class.getName(),
+//                        operationName);
+//
+//        OMFactory fac = OMAbstractFactory.getOMFactory();
+//
+//        OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
+//        OMElement payloadElement = fac.createOMElement("echoOMElement", omNs);
+//        OMElement value = fac.createOMElement("myValue", omNs);
+//        value.setText("Isaac Assimov, the foundation Sega");
+//        payloadElement.addChild(value);
+//
+//        org.apache.axis2.client.Call call = new org.apache.axis2.client.Call(
+//                serviceContext);
+//        Options options = new Options();
+//        call.setClientOptions(options);
+//        options.setTo(targetEPR);
+//        call.engageModule(new QName(Constants.MODULE_ADDRESSING));
+//        options.setAction(operationName.getLocalPart());
+//        options.setListenerTransportProtocol(Constants.TRANSPORT_TCP);
+//        options.setUseSeparateListener(true);
+//
+//        OMElement result = call.invokeBlocking(
+//                operationName.getLocalPart(), payloadElement);
+//        result.serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(
+//                System.out));
+//        call.close();
+//
+//    }
+//
+//    public void testEchoXMLSyncMC() throws Exception {
+//        ConfigurationContextFactory confac = new ConfigurationContextFactory();
+//        ConfigurationContext configContext = confac.buildClientConfigurationContext(Constants.TESTING_REPOSITORY);
+//
+//        AxisOperation opdesc = new OutInAxisOperation(new QName("echoOMElement"));
+//        org.apache.axis2.client.Call call = new org.apache.axis2.client.Call(Constants.TESTING_REPOSITORY);
+//        Options options = new Options();
+//        call.setClientOptions(options);
+//        options.setTo(targetEPR);
+//        options.setAction(operationName.getLocalPart());
+//        options.setListenerTransportProtocol(Constants.TRANSPORT_TCP);
+//        options.setUseSeparateListener(false);
+//
+//        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("Isaac Assimov, the foundation Sega");
+//        method.addChild(value);
+//        SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
+//        SOAPEnvelope envelope = factory.getDefaultEnvelope();
+//        envelope.getBody().addChild(method);
+//
+//        MessageContext requestContext = new MessageContext(configContext);
+//        AxisService srevice = new AxisService(serviceName);
+//        srevice.addOperation(opdesc);
+//        configContext.getAxisConfiguration().addService(srevice);
+//        requestContext.setAxisService(service);
+//        requestContext.setAxisOperation(opdesc);
+//
+//        //  requestContext.setTo(targetEPR);
+//
+//        requestContext.setEnvelope(envelope);
+//        MessageContext res = call.invokeBlocking(opdesc, requestContext);
+//
+//        SOAPEnvelope env = call.invokeBlocking("echoOMElement", envelope);
+////        SOAPEnvelope env=  res.getEnvelope();
+//        env.getBody().serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(
+//                System.out));
+//    }
+//
+//
+}