cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dand...@apache.org
Subject svn commit: r441613 - in /incubator/cxf/trunk: rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/ rt/core/src/main/java/org/apache/cxf/test/ tools/common/src/m...
Date Fri, 08 Sep 2006 18:49:57 GMT
Author: dandiep
Date: Fri Sep  8 11:49:56 2006
New Revision: 441613

URL: http://svn.apache.org/viewvc?view=rev&rev=441613
Log:
Add soap fault serializer test. Also tone down tool debug messages.

Added:
    incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/
    incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
  (with props)
Modified:
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultInInterceptor.java
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/XPathAssert.java
    incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/Form.java

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultInInterceptor.java?view=diff&rev=441613&r1=441612&r2=441613
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultInInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultInInterceptor.java
Fri Sep  8 11:49:56 2006
@@ -17,64 +17,51 @@
  * under the License.
  */
 
-package org.apache.cxf.binding.soap.interceptor;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
-import org.w3c.dom.Element;
-
-import org.apache.cxf.binding.soap.SoapFault;
-import org.apache.cxf.binding.soap.SoapMessage;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.staxutils.FragmentStreamReader;
-import org.apache.cxf.staxutils.StaxUtils;
-
-public class Soap11FaultInInterceptor extends AbstractSoapInterceptor {
-
-    public void handleMessage(SoapMessage message) throws Fault {
-        String exMessage = null;
-        QName faultCode = null;
-        String role = null;
-        Element detail = null;
-
-        XMLStreamReader reader = message.getContent(XMLStreamReader.class);
-
-        try {
-            boolean end = false;
-            while (!end && reader.hasNext()) {
-                int event = reader.next();
-                switch (event) {
-                case XMLStreamReader.END_DOCUMENT:
-                    end = true;
-                    break;
-                case XMLStreamReader.END_ELEMENT:
-                    break;
-                case XMLStreamReader.START_ELEMENT:
-                    if (reader.getLocalName().equals("faultcode")) {
-                        faultCode = StaxUtils.readQName(reader);
-                    } else if (reader.getLocalName().equals("faultstring")) {
-                        exMessage = reader.getElementText();
-                    } else if (reader.getLocalName().equals("faultactor")) {
-                        role = reader.getElementText();
-                    } else if (reader.getLocalName().equals("detail")) {
-                        detail = StaxUtils.read(new FragmentStreamReader(reader)).getDocumentElement();
-                    }
-                    break;
-                default:
-                    break;
-                }
-            }
-        } catch (XMLStreamException e) {
-            throw new SoapFault("Could not parse message.", SoapFault.SENDER);
-        }
-
-        SoapFault fault = new SoapFault(exMessage, faultCode);
-        fault.setDetail(detail);
-        fault.setRole(role);
-
-        message.setContent(Exception.class, fault);
-    }
-
-}
+package org.apache.cxf.binding.soap.interceptor;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.w3c.dom.Element;
+
+import org.apache.cxf.binding.soap.SoapFault;
+import org.apache.cxf.binding.soap.SoapMessage;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.staxutils.FragmentStreamReader;
+import org.apache.cxf.staxutils.StaxUtils;
+
+public class Soap11FaultInInterceptor extends AbstractSoapInterceptor {
+
+    public void handleMessage(SoapMessage message) throws Fault {
+        String exMessage = null;
+        QName faultCode = null;
+        String role = null;
+        Element detail = null;
+
+        XMLStreamReader reader = message.getContent(XMLStreamReader.class);
+
+        try {
+            while (reader.nextTag() == XMLStreamReader.START_ELEMENT) {
+                if (reader.getLocalName().equals("faultcode")) {
+                    faultCode = StaxUtils.readQName(reader);
+                } else if (reader.getLocalName().equals("faultstring")) {
+                    exMessage = reader.getElementText();
+                } else if (reader.getLocalName().equals("faultactor")) {
+                    role = reader.getElementText();
+                } else if (reader.getLocalName().equals("detail")) {
+                    detail = StaxUtils.read(new FragmentStreamReader(reader)).getDocumentElement();
+                }
+            }
+        } catch (XMLStreamException e) {
+            throw new SoapFault("Could not parse message.", SoapFault.SENDER);
+        }
+
+        SoapFault fault = new SoapFault(exMessage, faultCode);
+        fault.setDetail(detail);
+        fault.setRole(role);
+
+        message.setContent(Exception.class, fault);
+    }
+
+}

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java?view=diff&rev=441613&r1=441612&r2=441613
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java
Fri Sep  8 11:49:56 2006
@@ -17,98 +17,99 @@
  * under the License.
  */
 
-package org.apache.cxf.binding.soap.interceptor;
-
-import java.util.Map;
-import java.util.ResourceBundle;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
-import org.apache.cxf.binding.soap.SoapFault;
-import org.apache.cxf.binding.soap.SoapMessage;
-import org.apache.cxf.common.i18n.BundleUtils;
-import org.apache.cxf.common.i18n.Message;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.staxutils.StaxUtils;
-
-public class Soap11FaultOutInterceptor extends AbstractSoapInterceptor {
-    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(Soap11FaultOutInterceptor.class);
-
-    public void handleMessage(SoapMessage message) throws Fault {
-        XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
-        SoapFault fault = (SoapFault) message.getContent(Exception.class);
-
-        try {
-            Map<String, String> namespaces = fault.getNamespaces();
-            for (Map.Entry<String, String> e : namespaces.entrySet()) {
-                writer.writeNamespace(e.getKey(), e.getValue());
-            }
-
-            String prefix = message.getVersion().getPrefix();
-            
-            writer.writeStartElement(prefix, "Fault");
-
-            writer.writeStartElement("faultcode");
-
-            QName faultCode = fault.getFaultCode();
-            String codeString;
-            if (faultCode.equals(SoapFault.RECEIVER)) {
-                codeString = prefix + ":Server";
-            } else if (faultCode.equals(SoapFault.SENDER)) {
-                codeString = prefix + ":Client";
-            } else if (faultCode.equals(SoapFault.VERSION_MISMATCH)) {
-                codeString = prefix + ":VersionMismatch";
-            } else if (faultCode.equals(SoapFault.MUST_UNDERSTAND)) {
-                codeString = prefix + ":MustUnderstand";
-            } else if (faultCode.equals(SoapFault.DATA_ENCODING_UNKNOWN)) {
-                codeString = prefix + ":Client";
-            } else {
-                String ns = faultCode.getNamespaceURI();
-                String codePrefix = "";
-                if (ns.length() > 0) {
-                    codePrefix = StaxUtils.getUniquePrefix(writer, ns, true) + ":";
-                }
-
-                codeString = codePrefix + faultCode.getLocalPart();
-            }
-
-            writer.writeCharacters(codeString);
-            writer.writeEndElement();
-
-            writer.writeStartElement("faultstring");
-            writer.writeCharacters(fault.getMessage());
-            writer.writeEndElement();
-
-            if (fault.hasDetails()) {
-                Element detail = fault.getDetail();
-
-                writer.writeStartElement("detail");
-
-                NodeList details = detail.getChildNodes();
-                for (int i = 0; i < details.getLength(); i++) {
-                    StaxUtils.writeNode(details.item(i), writer, true);
-                }
-
-                // Details
-                writer.writeEndElement();
-            }
-
-            if (fault.getRole() != null) {
-                writer.writeStartElement("faultactor");
-                writer.writeCharacters(fault.getRole());
-                writer.writeEndElement();
-            }
-
-            // Fault
-            writer.writeEndElement();
-        } catch (XMLStreamException xe) {
-            throw new Fault(new Message("XML_WRITE_EXC", BUNDLE), xe);
-        }
-    }
-
-}
+package org.apache.cxf.binding.soap.interceptor;
+
+import java.util.Map;
+import java.util.ResourceBundle;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import org.apache.cxf.binding.soap.SoapFault;
+import org.apache.cxf.binding.soap.SoapMessage;
+import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.staxutils.StaxUtils;
+
+public class Soap11FaultOutInterceptor extends AbstractSoapInterceptor {
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(Soap11FaultOutInterceptor.class);
+
+    public void handleMessage(SoapMessage message) throws Fault {
+        XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
+        SoapFault fault = (SoapFault)message.getContent(Exception.class);
+
+        try {
+            Map<String, String> namespaces = fault.getNamespaces();
+            for (Map.Entry<String, String> e : namespaces.entrySet()) {
+                writer.writeNamespace(e.getKey(), e.getValue());
+            }
+
+            String ns = message.getVersion().getNamespace();
+            String prefix = StaxUtils.getUniquePrefix(writer, ns, true);
+
+            writer.writeStartElement(prefix, "Fault", ns);
+
+            writer.writeStartElement("faultcode");
+
+            QName faultCode = fault.getFaultCode();
+            String codeString;
+            if (faultCode.equals(SoapFault.RECEIVER)) {
+                codeString = prefix + ":Server";
+            } else if (faultCode.equals(SoapFault.SENDER)) {
+                codeString = prefix + ":Client";
+            } else if (faultCode.equals(SoapFault.VERSION_MISMATCH)) {
+                codeString = prefix + ":VersionMismatch";
+            } else if (faultCode.equals(SoapFault.MUST_UNDERSTAND)) {
+                codeString = prefix + ":MustUnderstand";
+            } else if (faultCode.equals(SoapFault.DATA_ENCODING_UNKNOWN)) {
+                codeString = prefix + ":Client";
+            } else {
+                String codeNs = faultCode.getNamespaceURI();
+                String codePrefix = faultCode.getPrefix();
+                if (codeNs.length() > 0) {
+                    codePrefix = StaxUtils.getUniquePrefix(writer, codeNs, true) + ":";
+                }
+
+                codeString = codePrefix + faultCode.getLocalPart();
+            }
+
+            writer.writeCharacters(codeString);
+            writer.writeEndElement();
+
+            writer.writeStartElement("faultstring");
+            writer.writeCharacters(fault.getMessage());
+            writer.writeEndElement();
+
+            if (fault.hasDetails()) {
+                Element detail = fault.getDetail();
+
+                writer.writeStartElement("detail");
+
+                NodeList details = detail.getChildNodes();
+                for (int i = 0; i < details.getLength(); i++) {
+                    StaxUtils.writeNode(details.item(i), writer, true);
+                }
+
+                // Details
+                writer.writeEndElement();
+            }
+
+            if (fault.getRole() != null) {
+                writer.writeStartElement("faultactor");
+                writer.writeCharacters(fault.getRole());
+                writer.writeEndElement();
+            }
+
+            // Fault
+            writer.writeEndElement();
+        } catch (XMLStreamException xe) {
+            throw new Fault(new Message("XML_WRITE_EXC", BUNDLE), xe);
+        }
+    }
+
+}

Added: incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java?view=auto&rev=441613
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
(added)
+++ incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
Fri Sep  8 11:49:56 2006
@@ -0,0 +1,76 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.binding.soap.interceptor;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.w3c.dom.Document;
+
+import org.apache.cxf.binding.soap.SoapFault;
+import org.apache.cxf.binding.soap.SoapMessage;
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.test.AbstractCXFTest;
+
+public class SoapFaultSerializerTest extends AbstractCXFTest {
+    public void testSoap11Out() throws Exception {
+        String faultString = "Hadrian caused this Fault!";
+        SoapFault fault = new SoapFault(faultString, SoapFault.SENDER);
+
+        SoapMessage m = new SoapMessage(new MessageImpl());
+        m.setContent(Exception.class, fault);
+
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out);
+        writer.writeStartDocument();
+        writer.writeStartElement("Body");
+
+        m.setContent(XMLStreamWriter.class, writer);
+
+        Soap11FaultOutInterceptor interceptor = new Soap11FaultOutInterceptor();
+        interceptor.handleMessage(m);
+
+        writer.writeEndElement();
+        writer.writeEndDocument();
+        writer.close();
+
+        Document faultDoc = DOMUtils.readXml(new ByteArrayInputStream(out.toByteArray()));
+        assertValid("//s:Fault/faultcode[text()='ns1:Client']", faultDoc);
+        assertValid("//s:Fault/faultstring[text()='" + faultString + "']", faultDoc);
+
+        XMLStreamReader reader = StaxUtils.createXMLStreamReader(new ByteArrayInputStream(out.toByteArray()));
+        m.setContent(XMLStreamReader.class, reader);
+
+        reader.nextTag();
+
+        Soap11FaultInInterceptor inInterceptor = new Soap11FaultInInterceptor();
+        inInterceptor.handleMessage(m);
+
+        SoapFault fault2 = (SoapFault)m.getContent(Exception.class);
+        assertNotNull(fault2);
+        assertEquals(fault.getMessage(), fault2.getMessage());
+        assertEquals(SoapFault.SOAP11_CLIENT, fault2.getFaultCode());
+    }
+}

Propchange: incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/XPathAssert.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/XPathAssert.java?view=diff&rev=441613&r1=441612&r2=441613
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/XPathAssert.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/XPathAssert.java Fri Sep
 8 11:49:56 2006
@@ -44,7 +44,7 @@
 public final class XPathAssert {
     private XPathAssert() {
     }
-    
+
     /**
      * Assert that the following XPath query selects one or more nodes.
      * 
@@ -59,10 +59,7 @@
         NodeList nodes = (NodeList)createXPath(namespaces).evaluate(xpath, node, XPathConstants.NODESET);
 
         if (nodes.getLength() == 0) {
-            String value = writeNodeToString(node);
-
-            throw new AssertionFailedError("Failed to select any nodes for expression:.\n"
+ xpath + "\n"
-                                           + value);
+            throw new AssertionFailedError("Failed to select any nodes for expression:\n"
+ xpath);
         }
 
         return nodes;

Modified: incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/Form.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/Form.java?view=diff&rev=441613&r1=441612&r2=441613
==============================================================================
--- incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/Form.java
(original)
+++ incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/Form.java
Fri Sep  8 11:49:56 2006
@@ -69,18 +69,18 @@
      * options, optionGroups and argument specified in the usage definition.
      */
     public boolean accept(TokenInputStream args, Element result, ErrorVisitor errors) {
-        if (LOG.isLoggable(Level.INFO)) {
-            LOG.info("Accepting token stream for form of usage: " + this + ", tokens are
" + args);
+        if (LOG.isLoggable(Level.FINE)) {
+            LOG.fine("Accepting token stream for form of usage: " + this + ", tokens are
" + args);
         }
         int oldpos = args.getPosition();
-        if (LOG.isLoggable(Level.INFO)) {
-            LOG.info("Position is: " + oldpos);
+        if (LOG.isLoggable(Level.FINE)) {
+            LOG.fine("Position is: " + oldpos);
         }
         boolean hasInfo = hasInfoOption(args);
         args.setPosition(oldpos);
         while (args.available() > 0) {
-            if (LOG.isLoggable(Level.INFO)) {
-                LOG.info("Args is available");
+            if (LOG.isLoggable(Level.FINE)) {
+                LOG.fine("Args is available");
             }
             boolean accepted = false;
             for (int i = 0; i < optionGroups.size(); i++) {
@@ -141,16 +141,16 @@
             } else {
                 errors.add(new ErrorVisitor.UnexpectedArgument(next));
             }
-            if (LOG.isLoggable(Level.INFO)) {
-                LOG.info(this + " form is returning false as there are more args available"
+            if (LOG.isLoggable(Level.FINE)) {
+                LOG.fine(this + " form is returning false as there are more args available"
                          + " that haven't been consumed");
             }
             args.setPosition(oldpos);
             return false;
         }
         // If we have got here than we have fully consumed all the arguments.
-        if (LOG.isLoggable(Level.INFO)) {
-            LOG.info("Form " + this + " is returning true");
+        if (LOG.isLoggable(Level.FINE)) {
+            LOG.fine("Form " + this + " is returning true");
         }
         return true;
     }



Mime
View raw message