cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r749890 - in /cxf/trunk/rt/bindings/soap/src: main/java/org/apache/cxf/binding/soap/interceptor/ test/java/org/apache/cxf/binding/soap/interceptor/
Date Wed, 04 Mar 2009 03:38:11 GMT
Author: dkulp
Date: Wed Mar  4 03:38:10 2009
New Revision: 749890

URL: http://svn.apache.org/viewvc?rev=749890&view=rev
Log:
Fix issues where the response code for faults is potentially set AFTER data has already started
to stream back to the client.

Modified:
    cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java
    cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap12FaultOutInterceptor.java
    cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java

Modified: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java?rev=749890&r1=749889&r2=749890&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java
(original)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java
Wed Mar  4 03:38:10 2009
@@ -44,101 +44,110 @@
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(Soap11FaultOutInterceptor.class);
 
     public Soap11FaultOutInterceptor() {
-        super(Phase.MARSHAL);
+        super(Phase.PREPARE_SEND);
     }
-
     public void handleMessage(SoapMessage message) throws Fault {
         message.put(org.apache.cxf.message.Message.RESPONSE_CODE, new Integer(500));
-
-        XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
-        Fault f = (Fault) message.getContent(Exception.class);
-
-        SoapFault fault = SoapFault.createFault(f, message.getVersion());
-
-        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 defaultPrefix = writer.getPrefix(ns);
-            if (defaultPrefix == null) {
-                defaultPrefix = StaxUtils.getUniquePrefix(writer, ns, false);
-                writer.writeStartElement(defaultPrefix, "Fault", ns);
-                writer.writeNamespace(defaultPrefix, ns);
-            } else {
-                writer.writeStartElement(defaultPrefix, "Fault", ns);
-            }
-
-            writer.writeStartElement("faultcode");
-
-            String codeString = fault.getCodeString(getFaultCodePrefix(writer, fault.getFaultCode()),
-                    defaultPrefix);
-
-            writer.writeCharacters(codeString);
-            writer.writeEndElement();
-
-            writer.writeStartElement("faultstring");
-            if (fault.getMessage() != null) {
-                writer.writeCharacters(fault.getMessage());
-            } else {
-                writer.writeCharacters("Fault occurred while processing.");
-            }
-            writer.writeEndElement();
-            String config = (String)message.getContextualProperty(
-                    org.apache.cxf.message.Message.FAULT_STACKTRACE_ENABLED);
-            if (config != null && Boolean.valueOf(config).booleanValue() &&
fault.getCause() != null) {
-                StringBuffer sb = new StringBuffer();
-                for (StackTraceElement ste : fault.getCause().getStackTrace()) {        
           
-                    sb.append(ste.getClassName() + "!" + ste.getMethodName() + "!" + ste.getFileName()
 
-                            + "!" + ste.getLineNumber() + "\n");
-                }
-                try {
-                    Element detail = fault.getDetail(); 
-                    if (detail == null) {
-                        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-                        factory.setNamespaceAware(true);
-                        Document doc = factory.newDocumentBuilder().newDocument();
-                        Element stackTrace = doc.createElementNS(Soap11.SOAP_NAMESPACE, Fault.STACKTRACE);
-                        stackTrace.setTextContent(sb.toString());
-                        detail = doc.createElementNS(Soap11.SOAP_NAMESPACE, "detail");
-                        fault.setDetail(detail);
-                        detail.appendChild(stackTrace);
-                    } else {
-                        Element stackTrace = detail.getOwnerDocument().createElementNS(
-                                Soap11.SOAP_NAMESPACE, Fault.STACKTRACE);
-                        detail.appendChild(stackTrace);
-                    }                    
-                } catch (ParserConfigurationException pe) {
-                    // move on...
+        message.getInterceptorChain().add(Soap11FaultOutInterceptorInternal.INSTANCE);
+    }
+    
+    static class Soap11FaultOutInterceptorInternal extends AbstractSoapInterceptor {
+        static final Soap11FaultOutInterceptorInternal INSTANCE = new Soap11FaultOutInterceptorInternal();
+        
+        public Soap11FaultOutInterceptorInternal() {
+            super(Phase.MARSHAL);
+        }
+        public void handleMessage(SoapMessage message) throws Fault {    
+            XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
+            Fault f = (Fault) message.getContent(Exception.class);
+    
+            SoapFault fault = SoapFault.createFault(f, message.getVersion());
+    
+            try {
+                Map<String, String> namespaces = fault.getNamespaces();
+                for (Map.Entry<String, String> e : namespaces.entrySet()) {
+                    writer.writeNamespace(e.getKey(), e.getValue());
                 }
-            }
-
-            if (fault.hasDetails()) {
-                Element detail = fault.getDetail();
-                writer.writeStartElement("detail");
-                
-                Node node = detail.getFirstChild();
-                while (node != null) {
-                    StaxUtils.writeNode(node, writer, true);
-                    node = node.getNextSibling();
+    
+                String ns = message.getVersion().getNamespace();            
+                String defaultPrefix = writer.getPrefix(ns);
+                if (defaultPrefix == null) {
+                    defaultPrefix = StaxUtils.getUniquePrefix(writer, ns, false);
+                    writer.writeStartElement(defaultPrefix, "Fault", ns);
+                    writer.writeNamespace(defaultPrefix, ns);
+                } else {
+                    writer.writeStartElement(defaultPrefix, "Fault", ns);
                 }
-
-                // Details
+    
+                writer.writeStartElement("faultcode");
+    
+                String codeString = fault.getCodeString(getFaultCodePrefix(writer, fault.getFaultCode()),
+                        defaultPrefix);
+    
+                writer.writeCharacters(codeString);
                 writer.writeEndElement();
-            }
-
-            if (fault.getRole() != null) {
-                writer.writeStartElement("faultactor");
-                writer.writeCharacters(fault.getRole());
+    
+                writer.writeStartElement("faultstring");
+                if (fault.getMessage() != null) {
+                    writer.writeCharacters(fault.getMessage());
+                } else {
+                    writer.writeCharacters("Fault occurred while processing.");
+                }
+                writer.writeEndElement();
+                String config = (String)message.getContextualProperty(
+                        org.apache.cxf.message.Message.FAULT_STACKTRACE_ENABLED);
+                if (config != null && Boolean.valueOf(config).booleanValue() &&
fault.getCause() != null) {
+                    StringBuffer sb = new StringBuffer();
+                    for (StackTraceElement ste : fault.getCause().getStackTrace()) {    
               
+                        sb.append(ste.getClassName() + "!" + ste.getMethodName() + "!" +
ste.getFileName()  
+                                + "!" + ste.getLineNumber() + "\n");
+                    }
+                    try {
+                        Element detail = fault.getDetail(); 
+                        if (detail == null) {
+                            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+                            factory.setNamespaceAware(true);
+                            Document doc = factory.newDocumentBuilder().newDocument();
+                            Element stackTrace = doc.createElementNS(Soap11.SOAP_NAMESPACE,
Fault.STACKTRACE);
+                            stackTrace.setTextContent(sb.toString());
+                            detail = doc.createElementNS(Soap11.SOAP_NAMESPACE, "detail");
+                            fault.setDetail(detail);
+                            detail.appendChild(stackTrace);
+                        } else {
+                            Element stackTrace = detail.getOwnerDocument().createElementNS(
+                                    Soap11.SOAP_NAMESPACE, Fault.STACKTRACE);
+                            detail.appendChild(stackTrace);
+                        }                    
+                    } catch (ParserConfigurationException pe) {
+                        // move on...
+                    }
+                }
+    
+                if (fault.hasDetails()) {
+                    Element detail = fault.getDetail();
+                    writer.writeStartElement("detail");
+                    
+                    Node node = detail.getFirstChild();
+                    while (node != null) {
+                        StaxUtils.writeNode(node, writer, true);
+                        node = node.getNextSibling();
+                    }
+    
+                    // 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);
             }
-
-            // Fault
-            writer.writeEndElement();
-        } catch (XMLStreamException xe) {
-            throw new Fault(new Message("XML_WRITE_EXC", BUNDLE), xe);
         }
     }
 }

Modified: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap12FaultOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap12FaultOutInterceptor.java?rev=749890&r1=749889&r2=749890&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap12FaultOutInterceptor.java
(original)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap12FaultOutInterceptor.java
Wed Mar  4 03:38:10 2009
@@ -34,97 +34,108 @@
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.interceptor.URIMappingInterceptor;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.staxutils.StaxUtils;
 
 public class Soap12FaultOutInterceptor extends AbstractSoapInterceptor {
-    private static final Logger LOG = LogUtils.getL7dLogger(URIMappingInterceptor.class);
+    private static final Logger LOG = LogUtils.getL7dLogger(Soap12FaultOutInterceptor.class);
 
     public Soap12FaultOutInterceptor() {
-        super(Phase.MARSHAL);
+        super(Phase.PREPARE_SEND);
     }
-
     public void handleMessage(SoapMessage message) throws Fault {
-        LOG.info(getClass() + (String) message.get(SoapMessage.CONTENT_TYPE));
         message.put(org.apache.cxf.message.Message.RESPONSE_CODE, new Integer(500));
+        message.getInterceptorChain().add(Soap12FaultOutInterceptorInternal.INSTANCE);
+    }
+    
+    static class Soap12FaultOutInterceptorInternal extends AbstractSoapInterceptor {
+        static final Soap12FaultOutInterceptorInternal INSTANCE = new Soap12FaultOutInterceptorInternal();
         
-        XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
-        Fault f = (Fault)message.getContent(Exception.class);
-
-        SoapFault fault = SoapFault.createFault(f, message.getVersion());       
-        
-        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 defaultPrefix = StaxUtils.getUniquePrefix(writer, ns, true);
-
-            writer.writeStartElement(defaultPrefix, "Fault", ns);
-
-            writer.writeStartElement(defaultPrefix, "Code", ns);
-            writer.writeStartElement(defaultPrefix, "Value", ns);
-       
-            writer.writeCharacters(fault.getCodeString(getFaultCodePrefix(writer, fault.getFaultCode()),

-                                                       defaultPrefix));
-            writer.writeEndElement();
+        public Soap12FaultOutInterceptorInternal() {
+            super(Phase.MARSHAL);
+        }
+        public void handleMessage(SoapMessage message) throws Fault {
+            LOG.info(getClass() + (String) message.get(SoapMessage.CONTENT_TYPE));
+            message.put(org.apache.cxf.message.Message.RESPONSE_CODE, new Integer(500));
             
-            if (fault.getSubCode() != null) {
-                writer.writeStartElement(defaultPrefix, "Subcode", ns);
+            XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
+            Fault f = (Fault)message.getContent(Exception.class);
+    
+            SoapFault fault = SoapFault.createFault(f, message.getVersion());       
+            
+            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 defaultPrefix = StaxUtils.getUniquePrefix(writer, ns, true);
+    
+                writer.writeStartElement(defaultPrefix, "Fault", ns);
+    
+                writer.writeStartElement(defaultPrefix, "Code", ns);
                 writer.writeStartElement(defaultPrefix, "Value", ns);
-                writer.writeCharacters(fault.getSubCodeString(getFaultCodePrefix(writer,
fault.getSubCode()), 
-                                                              defaultPrefix));          
     
+           
+                writer.writeCharacters(fault.getCodeString(getFaultCodePrefix(writer, fault.getFaultCode()),

+                                                           defaultPrefix));
                 writer.writeEndElement();
+                
+                if (fault.getSubCode() != null) {
+                    writer.writeStartElement(defaultPrefix, "Subcode", ns);
+                    writer.writeStartElement(defaultPrefix, "Value", ns);
+                    writer.writeCharacters(fault.getSubCodeString(getFaultCodePrefix(writer,

+                                                                                     fault.getSubCode()),

+                                                                  defaultPrefix));      
         
+                    writer.writeEndElement();
+                    writer.writeEndElement();
+                }
                 writer.writeEndElement();
-            }
-            writer.writeEndElement();
-
-            writer.writeStartElement(defaultPrefix, "Reason", ns);
-            writer.writeStartElement(defaultPrefix, "Text", ns);
-            writer.writeAttribute("xml", "http://www.w3.org/XML/1998/namespace", "lang ",
getLangCode());
-            if (fault.getMessage() != null) {
-                writer.writeCharacters(fault.getMessage());
-            } else {
-                writer.writeCharacters("Fault occurred while processing.");
-            }
-            writer.writeEndElement();
-            writer.writeEndElement();
-
-            if (fault.hasDetails()) {
-                Element detail = fault.getDetail();
-                writer.writeStartElement(defaultPrefix, "Detail", ns);
-
-                Node node = detail.getFirstChild();
-                while (node != null) {
-                    StaxUtils.writeNode(node, writer, true);
-                    node = node.getNextSibling();
+    
+                writer.writeStartElement(defaultPrefix, "Reason", ns);
+                writer.writeStartElement(defaultPrefix, "Text", ns);
+                writer.writeAttribute("xml", "http://www.w3.org/XML/1998/namespace", "lang
", getLangCode());
+                if (fault.getMessage() != null) {
+                    writer.writeCharacters(fault.getMessage());
+                } else {
+                    writer.writeCharacters("Fault occurred while processing.");
                 }
-
-                // Details
                 writer.writeEndElement();
-            }
-
-            if (fault.getRole() != null) {
-                writer.writeStartElement("faultactor");
-                writer.writeCharacters(fault.getRole());
                 writer.writeEndElement();
+    
+                if (fault.hasDetails()) {
+                    Element detail = fault.getDetail();
+                    writer.writeStartElement(defaultPrefix, "Detail", ns);
+    
+                    Node node = detail.getFirstChild();
+                    while (node != null) {
+                        StaxUtils.writeNode(node, writer, true);
+                        node = node.getNextSibling();
+                    }
+    
+                    // 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", LOG), xe);
             }
-
-            // Fault
-            writer.writeEndElement();
-        } catch (XMLStreamException xe) {
-            throw new Fault(new Message("XML_WRITE_EXC", LOG), xe);
         }
-    }
-    
-    private String getLangCode() {        
-        String code = LOG.getResourceBundle().getLocale().getDisplayLanguage();
-        if (StringUtils.isEmpty(code)) {
-            return "en";
+        
+        private String getLangCode() {        
+            String code = LOG.getResourceBundle().getLocale().getDisplayLanguage();
+            if (StringUtils.isEmpty(code)) {
+                return "en";
+            }
+            return code;
         }
-        return code;
     }
-}
+}
\ No newline at end of file

Modified: cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java?rev=749890&r1=749889&r2=749890&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
(original)
+++ cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
Wed Mar  4 03:38:10 2009
@@ -32,6 +32,8 @@
 import org.apache.cxf.binding.soap.Soap12;
 import org.apache.cxf.binding.soap.SoapFault;
 import org.apache.cxf.binding.soap.SoapMessage;
+import org.apache.cxf.binding.soap.interceptor.Soap11FaultOutInterceptor.Soap11FaultOutInterceptorInternal;
+import org.apache.cxf.binding.soap.interceptor.Soap12FaultOutInterceptor.Soap12FaultOutInterceptorInternal;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.ExchangeImpl;
@@ -58,8 +60,7 @@
 
         m.setContent(XMLStreamWriter.class, writer);
 
-        Soap11FaultOutInterceptor interceptor = new Soap11FaultOutInterceptor();
-        interceptor.handleMessage(m);
+        Soap11FaultOutInterceptorInternal.INSTANCE.handleMessage(m);
 
         writer.writeEndElement();
         writer.writeEndDocument();
@@ -103,8 +104,7 @@
 
         m.setContent(XMLStreamWriter.class, writer);
 
-        Soap12FaultOutInterceptor interceptor = new Soap12FaultOutInterceptor();
-        interceptor.handleMessage(m);
+        Soap12FaultOutInterceptorInternal.INSTANCE.handleMessage(m);
 
         writer.writeEndElement();
         writer.writeEndDocument();



Mime
View raw message