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 ro...@apache.org on 2007/07/30 18:11:53 UTC

svn commit: r561030 - in /webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample: AddNumbersHandlerTests.java addnumbershandler/AddNumbersClientLogicalHandler.java

Author: rott
Date: Mon Jul 30 09:11:52 2007
New Revision: 561030

URL: http://svn.apache.org/viewvc?view=rev&rev=561030
Log:
test to verify client app gets exception when outbound
client handler throws exception during one-way invoke

Modified:
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler.java

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java?view=diff&rev=561030&r1=561029&r2=561030
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java Mon Jul 30 09:11:52 2007
@@ -419,7 +419,7 @@
         }       
     }
     
-    public void testOneWayWithException() {
+    public void testOneWayWithProtocolException() {
         try {
             TestLogger.logger.debug("----------------------------------");
             TestLogger.logger.debug("test: " + getName());
@@ -450,6 +450,39 @@
         }
         TestLogger.logger.debug("----------------------------------");
     }
+    
+    public void testOneWayWithRuntimeException() {
+        try {
+            TestLogger.logger.debug("----------------------------------");
+            TestLogger.logger.debug("test: " + getName());
+
+            AddNumbersHandlerService service = new AddNumbersHandlerService();
+            AddNumbersHandlerPortType proxy = service.getAddNumbersHandlerPort();
+
+            BindingProvider p = (BindingProvider) proxy;
+
+            p.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, axisEndpoint);
+            p.getRequestContext().put("myClientKey", "myClientVal");
+
+            List<Handler> handlers = p.getBinding().getHandlerChain();
+            if (handlers == null)
+                handlers = new ArrayList<Handler>();
+            handlers.add(new AddNumbersClientLogicalHandler());
+            handlers.add(new AddNumbersClientProtocolHandler());
+            p.getBinding().setHandlerChain(handlers);
+            
+            BindingProvider bp = (BindingProvider) proxy;
+            bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, axisEndpoint);
+            // value 99 will trigger exception from AddNumbersClientLogicalHandler
+            proxy.oneWayInt(999);
+            fail("Should have got an exception, but did not.");
+        } catch (Exception e) {
+            e.printStackTrace();
+            assertEquals(e.getMessage(), "I don't like the value 999");
+        }
+        TestLogger.logger.debug("----------------------------------");
+    }
+
 
     /*
      * A callback implementation that can be used to collect the exceptions

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler.java?view=diff&rev=561030&r1=561029&r2=561030
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersClientLogicalHandler.java Mon Jul 30 09:11:52 2007
@@ -23,6 +23,11 @@
 import java.util.Map;
 import java.util.StringTokenizer;
 
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPConstants;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFault;
+import javax.xml.soap.SOAPMessage;
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Source;
 import javax.xml.transform.Transformer;
@@ -32,9 +37,14 @@
 import javax.xml.ws.LogicalMessage;
 import javax.xml.ws.ProtocolException;
 import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.soap.SOAPFaultException;
 
 import org.apache.axis2.jaxws.handler.AttachmentsAdapter;
 import org.apache.axis2.jaxws.handler.LogicalMessageContext;
+import org.apache.axis2.jaxws.marshaller.impl.alt.MethodMarshallerUtils;
+import org.apache.axis2.jaxws.message.XMLFault;
+import org.apache.axis2.jaxws.message.util.XMLFaultUtils;
+import org.apache.axis2.jaxws.utility.SAAJFactory;
 
 /*
  * You can't actually specify whether a handler is for client or server,
@@ -128,6 +138,17 @@
             String st = getStringFromSourcePayload(msg.getPayload());
             if (st.contains("<arg0>99</arg0>")) {
                 throw new ProtocolException("I don't like the value 99");
+            } else if (st.contains("<arg0>999</arg0>")) {
+                XMLFault xmlFault = MethodMarshallerUtils.createXMLFaultFromSystemException(new RuntimeException("I don't like the value 999"));
+                try {
+                    javax.xml.soap.MessageFactory mf = SAAJFactory.createMessageFactory(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE);
+                    SOAPMessage message = mf.createMessage();
+                    SOAPBody body = message.getSOAPBody();
+                    SOAPFault soapFault = XMLFaultUtils.createSAAJFault(xmlFault, body);
+                    throw new SOAPFaultException(soapFault);
+                } catch (SOAPException soape) {
+                    throw new RuntimeException("Got SOAPException.  That's bad.");
+                }
             }
             
             // Check for the presences of the attachment property



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