You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by jl...@apache.org on 2007/05/16 06:20:43 UTC

svn commit: r538431 - in /incubator/cxf/trunk: rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/ systests/src/test/java/org/apache/cxf/systest/handlers/

Author: jliu
Date: Tue May 15 21:20:40 2007
New Revision: 538431

URL: http://svn.apache.org/viewvc?view=rev&rev=538431
Log:
Support JAX-WS handlers throw Protocol/Runtime exception on server side outbound.

Modified:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerFaultOutInterceptor.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerFaultOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerFaultOutInterceptor.java?view=diff&rev=538431&r1=538430&r2=538431
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerFaultOutInterceptor.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerFaultOutInterceptor.java Tue May 15 21:20:40 2007
@@ -24,6 +24,7 @@
 import java.util.Set;
 
 import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPMessage;
 import javax.xml.ws.Binding;
 import javax.xml.ws.ProtocolException;
 import javax.xml.ws.handler.Handler;
@@ -82,6 +83,9 @@
         }
 
         if (getInvoker(message).isOutbound()) {
+            //The SOAPMessage might be set from the outchain, in this case, 
+            //we need to clean it up and create a new SOAPMessage dedicated to fault.
+            message.setContent(SOAPMessage.class, null);
 
             SAAJ_OUT.handleMessage(message);
 

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java?view=diff&rev=538431&r1=538430&r2=538431
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java Tue May 15 21:20:40 2007
@@ -719,10 +719,31 @@
             handlerTest.pingWithArgs("soapHandler3 inbound throw RuntimeException");
             fail("did not get expected exception");
         } catch (RuntimeException e) {
-            //FIXME
+/*            e.printStackTrace();
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            PrintStream ps = new PrintStream(baos, true);
+            e.printStackTrace(ps);
+            assertTrue("Did not get expected exception message",  baos.toString()
+                .indexOf("HandleMessage throws RuntimeException exception") > -1);
+            assertTrue("Did not get expected javax.xml.ws.soap.SOAPFaultException", baos.toString()
+                .indexOf("javax.xml.ws.soap.SOAPFaultException") > -1);*/
+        }        
+    }
+    
+    @Test
+    public void testSOAPHandlerHandleMessageThrowsRuntimeExceptionServerOutbound() throws PingException {
+        try {
+            handlerTest.pingWithArgs("soapHandler3 outbound throw RuntimeException");
+            fail("did not get expected exception");
+        } catch (RuntimeException e) {
             //e.printStackTrace();
-/*            assertTrue("Did not get expected exception message", e.getMessage()
-                .indexOf("HandleMessage throws runtime exception") > -1);*/
+/*            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            PrintStream ps = new PrintStream(baos, true);
+            e.printStackTrace(ps);
+            assertTrue("Did not get expected exception message",  baos.toString()
+                .indexOf("HandleMessage throws RuntimeException exception") > -1);
+            assertTrue("Did not get expected javax.xml.ws.soap.SOAPFaultException", baos.toString()
+                .indexOf("javax.xml.ws.soap.SOAPFaultException") > -1);*/
         }        
     }
     
@@ -732,17 +753,34 @@
             handlerTest.pingWithArgs("soapHandler3 inbound throw ProtocolException");
             fail("did not get expected WebServiceException");
         } catch (WebServiceException e) {
-            //FIXME
-/*            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+/*            e.printStackTrace();
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
             PrintStream ps = new PrintStream(baos, true);
             e.printStackTrace(ps);
             assertTrue("Did not get expected exception message",  baos.toString()
-                .indexOf("HandleMessage throws runtime exception") > -1);
+                .indexOf("HandleMessage throws ProtocolException exception") > -1);
             assertTrue("Did not get expected javax.xml.ws.soap.SOAPFaultException", baos.toString()
                 .indexOf("javax.xml.ws.soap.SOAPFaultException") > -1);*/
         }        
     }
 
+    @Test
+    public void testSOAPHandlerHandleMessageThrowsProtocolExceptionServerOutbound() throws PingException {
+        try {
+            handlerTest.pingWithArgs("soapHandler3 outbound throw ProtocolException");
+            fail("did not get expected WebServiceException");
+        } catch (WebServiceException e) {
+/*            e.printStackTrace();
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            PrintStream ps = new PrintStream(baos, true);
+            e.printStackTrace(ps);
+            assertTrue("Did not get expected exception message",  baos.toString()
+                .indexOf("HandleMessage throws ProtocolException exception") > -1);
+            assertTrue("Did not get expected javax.xml.ws.soap.SOAPFaultException", baos.toString()
+                .indexOf("javax.xml.ws.soap.SOAPFaultException") > -1);*/
+        }        
+    }
+    
     @Test
     @Ignore
     public void testLogicalHandlerHandleMessageThrowsProtocolExceptionServerInbound()

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java?view=diff&rev=538431&r1=538430&r2=538431
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java Tue May 15 21:20:40 2007
@@ -196,13 +196,13 @@
                 }
                 if (exceptionType != null && !outbound && "inbound".equals(direction)) {
                     if ("RuntimeException".equals(exceptionType)) {
-                        throw new RuntimeException("HandleMessage throws runtime exception");
+                        throw new RuntimeException("HandleMessage throws RuntimeException exception");
                     } else if ("ProtocolException".equals(exceptionType)) {
-                        throw new ProtocolException("HandleMessage throws runtime exception");
+                        throw new ProtocolException("HandleMessage throws ProtocolException exception");
                     }
                 } else if (exceptionType != null && outbound && "outbound".equals(direction)) {
                     if ("RuntimeException".equals(exceptionType)) {
-                        throw new RuntimeException("HandleMessage throws ProtocolException exception");
+                        throw new RuntimeException("HandleMessage throws RuntimeException exception");
                     } else if ("ProtocolException".equals(exceptionType)) {
                         throw new ProtocolException("HandleMessage throws ProtocolException exception");
                     }