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 ch...@apache.org on 2006/06/06 07:46:09 UTC

svn commit: r412013 - in /webservices/axis2/trunk/java/modules: core/src/org/apache/axis2/receivers/ integration/test/org/apache/axis2/engine/ integration/test/org/apache/axis2/engine/util/ integration/test/org/apache/axis2/integration/

Author: chinthaka
Date: Mon Jun  5 22:46:08 2006
New Revision: 412013

URL: http://svn.apache.org/viewvc?rev=412013&view=rev
Log:
- fixing RAW XML Message Receiver for Axis2-800 and 801 with a test case. Need to do the same for other message receivers.

Added:
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ServiceFaultTest.java
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/util/FaultThrowingService.java
Modified:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/receivers/RawXMLINOutMessageReceiver.java
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/UtilServer.java

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/receivers/RawXMLINOutMessageReceiver.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/receivers/RawXMLINOutMessageReceiver.java?rev=412013&r1=412012&r2=412013&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/receivers/RawXMLINOutMessageReceiver.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/receivers/RawXMLINOutMessageReceiver.java Mon Jun  5 22:46:08 2006
@@ -96,11 +96,7 @@
                 }
 
                 OMElement result;
-                try {
                     result = (OMElement) method.invoke(obj, args);
-                } catch (Exception e) {
-                    throw new AxisFault(e.getMessage());
-                }
 
                 AxisService service = msgContext.getAxisService();
                 service.getTargetNamespace();

Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ServiceFaultTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ServiceFaultTest.java?rev=412013&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ServiceFaultTest.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ServiceFaultTest.java Mon Jun  5 22:46:08 2006
@@ -0,0 +1,104 @@
+/*
+ * 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.engine;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.util.FaultThrowingService;
+import org.apache.axis2.engine.util.TestConstants;
+import org.apache.axis2.integration.UtilServer;
+import org.apache.axis2.integration.UtilServerBasedTestCase;
+import org.apache.axis2.util.Utils;
+
+import javax.xml.namespace.QName;
+
+/**
+ * This test will make sure, faults thrown by services are handled properly.
+ */
+public class ServiceFaultTest extends UtilServerBasedTestCase implements TestConstants {
+
+    protected String testResourceDir = "test-resources";
+    private AxisService service;
+
+    private QName serviceName = new QName("FaultThrowingService");
+    private QName operationName = new QName("echoWithFault");
+
+    private EndpointReference targetEPR;
+
+    protected void setUp() throws Exception {
+        UtilServer.start();
+        service =
+                Utils.createSimpleService(serviceName,
+                        FaultThrowingService.class.getName(),
+                        operationName);
+        UtilServer.deployService(service);
+        targetEPR = new EndpointReference(
+//                "http://127.0.0.1:" + (UtilServer.TESTING_PORT)
+                "http://127.0.0.1:5556"
+                        + "/axis2/services/" + serviceName.getLocalPart() + "/" + operationName.getLocalPart());
+    }
+
+    public void testFaultThrownByService() {
+        try {
+            OMElement payload = getOMElementWithText(FaultThrowingService.THROW_FAULT_AS_AXIS_FAULT);
+            Options options = new Options();
+            options.setTo(targetEPR);
+            options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+            options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+            options.setExceptionToBeThrownOnSOAPFault(false);
+
+            ConfigurationContext configContext =
+                    ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
+            ServiceClient sender = new ServiceClient(configContext, null);
+            sender.setOptions(options);
+
+            String result = sender.sendReceive(payload).toString();
+
+            assertTrue(result.indexOf("test:TestFault") > -1);
+            assertTrue(result.indexOf("FaultReason</soapenv:Text>") > -1);
+            assertTrue(result.indexOf("This is a test Exception") > -1);
+        } catch (AxisFault axisFault) {
+            axisFault.printStackTrace();
+            fail();
+        }
+    }
+
+    private OMElement getOMElementWithText(String text) {
+        OMFactory omFactory = OMAbstractFactory.getOMFactory();
+        OMElement omElement = omFactory.createOMElement("EchoOMElement", null);
+        omElement.setText(text);
+        return omElement;
+    }
+
+    protected void tearDown() throws Exception {
+        UtilServer.unDeployService(serviceName);
+        UtilServer.unDeployClientService();
+        UtilServer.stop();
+    }
+
+
+}

Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/util/FaultThrowingService.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/util/FaultThrowingService.java?rev=412013&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/util/FaultThrowingService.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/util/FaultThrowingService.java Mon Jun  5 22:46:08 2006
@@ -0,0 +1,52 @@
+package org.apache.axis2.engine.util;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.wsdl.WSDLConstants;
+
+import javax.xml.namespace.QName;
+/*
+ * 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 FaultThrowingService {
+
+    public static final String THROW_FAULT_AS_AXIS_FAULT = "ThrowFaultAsAxisFault";
+    public static final String THROW_FAULT_WITH_MSG_CTXT = "ThrowFaultWithMsgCtxt";
+
+    MessageContext inMessageContext;
+
+    public void setOperationContext(OperationContext opContext) {
+        try {
+            inMessageContext = opContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+        } catch (AxisFault axisFault) {
+            axisFault.printStackTrace();
+        }
+    }
+
+    public OMElement echoWithFault(OMElement  echoOMElement) throws AxisFault {
+        String text = echoOMElement.getText();
+        if (THROW_FAULT_AS_AXIS_FAULT.equalsIgnoreCase(text)) {
+            throw new AxisFault(new QName("http://test.org", "TestFault", "test"), "FaultReason", new Exception("This is a test Exception"));
+        } else if (THROW_FAULT_WITH_MSG_CTXT.equalsIgnoreCase(text)) {
+
+        } else {
+           return echoOMElement;
+        }
+        return null;
+    }
+}

Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/UtilServer.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/UtilServer.java?rev=412013&r1=412012&r2=412013&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/UtilServer.java (original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/integration/UtilServer.java Mon Jun  5 22:46:08 2006
@@ -76,23 +76,26 @@
                 receiver.start();
                 System.out.print("Server started on port "
                         + TESTING_PORT + ".....");
+            } catch (Exception e) {
+                e.printStackTrace();
             } finally {
-
             }
 
-            try {
-                Thread.sleep(2000);
-            } catch (InterruptedException e1) {
-                throw new AxisFault("Thread interuptted", e1);
-            }
+        }
 
+        try {
+            Thread.sleep(2000);
+        } catch (InterruptedException e1) {
+            throw new AxisFault("Thread interuptted", e1);
         }
+
+
         count++;
     }
 
-     public static synchronized void start(String repository , String axis2xml) throws Exception {
+    public static synchronized void start(String repository, String axis2xml) throws Exception {
         if (count == 0) {
-            ConfigurationContext er = getNewConfigurationContext(repository,axis2xml);
+            ConfigurationContext er = getNewConfigurationContext(repository, axis2xml);
 
             receiver = new SimpleHTTPServer(er, TESTING_PORT);
 
@@ -125,8 +128,8 @@
                 file.getAbsolutePath() + "/conf/axis2.xml");
     }
 
-      public static ConfigurationContext getNewConfigurationContext(
-            String repository , String axis2xml) throws Exception {
+    public static ConfigurationContext getNewConfigurationContext(
+            String repository, String axis2xml) throws Exception {
         File file = new File(repository);
         if (!file.exists()) {
             throw new Exception("repository directory "
@@ -146,7 +149,7 @@
                 }
             }
             count = 0;
-            // tp.doStop();
+// tp.doStop();
             System.out.print("Server stopped .....");
         } else {
             count--;
@@ -228,7 +231,7 @@
                 configContext.getAxisConfiguration());
 
         configContext.getAxisConfiguration().addModule(axisModule);
-        // sysContext.getAxisConfiguration().engageModule(moduleDesc.getName());
+// sysContext.getAxisConfiguration().engageModule(moduleDesc.getName());
 
         configContext.getAxisConfiguration().addService(service);
 



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