cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r538795 - 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/
Date Thu, 17 May 2007 03:04:30 GMT
Author: jliu
Date: Wed May 16 20:04:29 2007
New Revision: 538795

URL: http://svn.apache.org/viewvc?view=rev&rev=538795
Log:
Minor fix to SOAP handler interceptors so that the case of SOAP Handlers handleFault throws
SOAPFaultException on server outbound works.

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=538795&r1=538794&r2=538795
==============================================================================
--- 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
Wed May 16 20:04:29 2007
@@ -131,34 +131,34 @@
                 //Replace SOAPFault with the exception thrown from HandleFault
                 
                 try {
-                    SOAPMessage msgFromHandleFault = message.getContent(SOAPMessage.class);
-
-                    SOAPBody body = msgFromHandleFault.getSOAPBody();
-                    
+                    SOAPMessage originalMsg = message.getContent(SOAPMessage.class);
+                    SOAPBody body = originalMsg.getSOAPBody();                    
                     body.removeContents();
-
+                    
                     SOAPFault soapFault = body.addFault();
 
                     if (exception instanceof SOAPFaultException) {
                         SOAPFaultException sf = (SOAPFaultException)exception;
                         soapFault.setFaultString(sf.getFault().getFaultString());
-                        soapFault.setFaultCode(sf.getFault().getFaultCode());
+                        soapFault.setFaultCode(sf.getFault().getFaultCodeAsQName());
                         soapFault.setFaultActor(sf.getFault().getFaultActor());
-                        Node nd = msgFromHandleFault.getSOAPPart().importNode(
-                                                                              sf.getFault().getDetail()
-                                                                                  .getFirstChild(),
true);
-                        soapFault.addDetail().appendChild(nd);
+                        if (sf.getFault().hasDetail()) {
+                            Node nd = originalMsg.getSOAPPart().importNode(
+                                                                           sf.getFault().getDetail()
+                                                                               .getFirstChild(),
true);
+                            soapFault.addDetail().appendChild(nd);
+                        }
                     } else if (exception instanceof Fault) {
                         SoapFault sf = SoapFault.createFault((Fault)exception, ((SoapMessage)message)
                             .getVersion());
                         soapFault.setFaultString(sf.getReason());
-                        soapFault.setFaultCode(sf.getFaultCode());
-                        Node nd = msgFromHandleFault.getSOAPPart().importNode(sf.getOrCreateDetail(),
true);
+                        soapFault.setFaultCode(sf.getFault().getFaultCodeAsQName());
+                        Node nd = originalMsg.getSOAPPart().importNode(sf.getOrCreateDetail(),
true);
                         soapFault.addDetail().appendChild(nd);
                     } else {
                         soapFault.setFaultString(exception.getMessage());
                         soapFault.setFaultCode(new QName("http://cxf.apache.org/faultcode",
"HandleFault"));
-                    }
+                    } 
                 } catch (SOAPException e) {
                     //do nothing
                     e.printStackTrace();

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=538795&r1=538794&r2=538795
==============================================================================
--- 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
Wed May 16 20:04:29 2007
@@ -41,6 +41,7 @@
 import javax.xml.ws.handler.MessageContext;
 import javax.xml.ws.handler.PortInfo;
 import javax.xml.ws.handler.soap.SOAPMessageContext;
+import javax.xml.ws.soap.SOAPFaultException;
 
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
@@ -788,6 +789,24 @@
             e.printStackTrace(ps);
             assertTrue("Did not get expected exception message",  baos.toString()
                 .indexOf("soapHandler4 HandleFault throws RuntimeException") > -1);
+            assertTrue("Did not get expected javax.xml.ws.soap.SOAPFaultException", baos.toString()
+                .indexOf("javax.xml.ws.soap.SOAPFaultException") > -1);*/
+        }        
+    }
+    
+    @Test
+    public void testSOAPHandlerHandleFaultThrowsSOAPFaultExceptionServerOutbound() throws
PingException {
+        try {
+            handlerTest.pingWithArgs("soapHandler3 inbound throw ProtocolException "
+                                     + "soapHandler4HandleFaultThrowsSOAPFaultException");
+            fail("did not get expected SOAPFaultException");
+        } catch (SOAPFaultException 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("soapHandler4 HandleFault throws SOAPFaultException") > -1);
             assertTrue("Did not get expected javax.xml.ws.soap.SOAPFaultException", baos.toString()
                 .indexOf("javax.xml.ws.soap.SOAPFaultException") > -1);*/
         }        

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=538795&r1=538794&r2=538795
==============================================================================
--- 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
Wed May 16 20:04:29 2007
@@ -26,11 +26,14 @@
 import javax.xml.namespace.QName;
 import javax.xml.soap.SOAPBody;
 import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFactory;
+import javax.xml.soap.SOAPFault;
 import javax.xml.soap.SOAPMessage;
 import javax.xml.ws.ProtocolException;
 import javax.xml.ws.handler.MessageContext;
 import javax.xml.ws.handler.soap.SOAPHandler;
 import javax.xml.ws.handler.soap.SOAPMessageContext;
+import javax.xml.ws.soap.SOAPFaultException;
 
 import org.w3c.dom.DOMException;
 import org.w3c.dom.Document;
@@ -129,7 +132,12 @@
             if ("soapHandler4HandleFaultThrowsRunException".equals(msg.getSOAPBody().getFault()
                 .getFaultString())) {
                 throw new RuntimeException("soapHandler4 HandleFault throws RuntimeException");
-            }
+            } else if ("soapHandler4HandleFaultThrowsSOAPFaultException".equals(msg.getSOAPBody().getFault()
+                .getFaultString())) {
+                SOAPFault fault = SOAPFactory.newInstance().createFault();
+                fault.setFaultString("soapHandler4 HandleFault throws SOAPFaultException");
+                throw new SOAPFaultException(fault);
+            } 
         } catch (SOAPException e) {
             // do nothing
         }



Mime
View raw message