You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2009/05/08 19:09:48 UTC

svn commit: r773049 - in /cxf/trunk/rt/bindings/soap/src: main/java/org/apache/cxf/binding/soap/saaj/ test/java/org/apache/cxf/binding/soap/saaj/ test/resources/org/apache/cxf/binding/soap/

Author: dkulp
Date: Fri May  8 17:09:48 2009
New Revision: 773049

URL: http://svn.apache.org/viewvc?rev=773049&view=rev
Log:
[CXF-2212] Fix problem of only the first detail child being written out.
Patch from Colm O hEigeartaigh used as basis.


Added:
    cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/test-soap-fault-detail.xml   (with props)
Modified:
    cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
    cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptorTest.java

Modified: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java?rev=773049&r1=773048&r2=773049&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java (original)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java Fri May  8 17:09:48 2009
@@ -25,6 +25,7 @@
 
 import javax.xml.namespace.QName;
 import javax.xml.soap.AttachmentPart;
+import javax.xml.soap.Detail;
 import javax.xml.soap.MessageFactory;
 import javax.xml.soap.SOAPConstants;
 import javax.xml.soap.SOAPException;
@@ -146,9 +147,19 @@
                 }
                 if (fault.getDetail() != null
                     && fault.getDetail().getFirstChild() != null) {
-                    soapFault.addDetail().appendChild(
-                        soapMessage.getSOAPPart().importNode(
-                            fault.getDetail().getFirstChild(), true));
+                    
+                    Detail detail = null;
+                    Node child = fault.getDetail().getFirstChild();
+                    while (child != null) {
+                        if (Node.ELEMENT_NODE == child.getNodeType()) {
+                            if (detail == null) {
+                                detail = soapFault.addDetail();
+                            }
+                            Node importedChild = soapMessage.getSOAPPart().importNode(child, true);
+                            detail.appendChild(importedChild);
+                        }
+                        child = child.getNextSibling();
+                    }
                 }
 
                 DOMSource bodySource = new DOMSource(soapFault);

Modified: cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptorTest.java?rev=773049&r1=773048&r2=773049&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptorTest.java (original)
+++ cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptorTest.java Fri May  8 17:09:48 2009
@@ -26,9 +26,14 @@
 import java.util.List;
 
 import javax.mail.util.ByteArrayDataSource;
+import javax.xml.soap.Detail;
+import javax.xml.soap.DetailEntry;
+import javax.xml.soap.SOAPFault;
+import javax.xml.soap.SOAPMessage;
 import javax.xml.stream.XMLStreamReader;
 
 import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
 
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.binding.soap.Soap12;
@@ -59,7 +64,6 @@
         chain.add(saajIntc);
         
         chain.add(new CheckFaultInterceptor("phase3"));
-
     }
 
     @Test
@@ -93,6 +97,42 @@
         
         assertEquals(2, headerChilds.size());
     }
+    
+    @Test
+    public void testFaultDetail() throws Exception {
+        try {
+            prepareSoapMessage("../test-soap-fault-detail.xml");
+        } catch (IOException ioe) {
+            fail("Failed in creating soap message");
+        }
+
+        staxIntc.handleMessage(soapMessage);
+        rhi.handleMessage(soapMessage);
+
+        // check the xmlReader should be placed on the first entry of the body
+        // element
+        XMLStreamReader xmlReader = soapMessage.getContent(XMLStreamReader.class);
+        xmlReader.nextTag();
+        saajIntc.handleMessage(soapMessage);
+        
+        SOAPMessage parsedMessage = soapMessage.getContent(SOAPMessage.class);
+        SOAPFault fault = parsedMessage.getSOAPBody().getFault();
+        assertEquals("soap:Server", fault.getFaultCode());
+        assertEquals("This is a fault string", fault.getFaultString());
+        Detail faultDetail = fault.getDetail();
+        NodeList faultDetailChildNodes = faultDetail.getChildNodes();
+        assertEquals(2, faultDetailChildNodes.getLength());
+        
+        Iterator<?> detailEntries = faultDetail.getDetailEntries();
+        DetailEntry detailEntry = (DetailEntry)detailEntries.next();
+        assertEquals("errorcode", detailEntry.getLocalName());
+        assertEquals(3, Integer.valueOf(detailEntry.getTextContent()).intValue());
+        detailEntry = (DetailEntry)detailEntries.next();
+        assertEquals("errorstring", detailEntry.getLocalName());
+        assertEquals("This is a fault detail error string", detailEntry.getTextContent());
+        
+    }
+    
 
     private void prepareSoapMessage(String message) throws IOException {
 

Added: cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/test-soap-fault-detail.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/test-soap-fault-detail.xml?rev=773049&view=auto
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/test-soap-fault-detail.xml (added)
+++ cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/test-soap-fault-detail.xml Fri May  8 17:09:48 2009
@@ -0,0 +1,31 @@
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements. See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership. The ASF licenses this file
+    to you 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.
+-->
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+ <soap:Body>
+  <soap:Fault>
+   <faultcode>soap:Server</faultcode>
+   <faultstring>This is a fault string</faultstring>
+   <detail>
+    <errorcode>3</errorcode>
+    <errorstring>This is a fault detail error string</errorstring>
+   </detail>
+  </soap:Fault>
+ </soap:Body>
+</soap:Envelope>
+

Propchange: cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/test-soap-fault-detail.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/test-soap-fault-detail.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/test-soap-fault-detail.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml