cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r532798 - in /incubator/cxf/trunk: api/src/main/java/org/apache/cxf/interceptor/ common/common/src/main/java/org/apache/cxf/staxutils/ rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/ rt/bindings/soap/src/test/java/org/apache/cxf...
Date Thu, 26 Apr 2007 16:46:58 GMT
Author: dkulp
Date: Thu Apr 26 09:46:57 2007
New Revision: 532798

URL: http://svn.apache.org/viewvc?view=rev&rev=532798
Log:
Promote fault code up to Fault.   Add internal CLIENT/SERVER codes.
Map some "Client" errors to the approriate Fault code
Fix some problems with SAAJ handlers interacting funny with Provider based services

Modified:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/Fault.java
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapFault.java
    incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/BareInInterceptor.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/DocLiteralInInterceptor.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/WrappedInInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/LogicalMessageImpl.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/ProviderInDatabindingInterceptor.java

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/Fault.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/Fault.java?view=diff&rev=532798&r1=532797&r2=532798
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/Fault.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/Fault.java Thu Apr 26
09:46:57 2007
@@ -19,6 +19,8 @@
 
 package org.apache.cxf.interceptor;
 
+import javax.xml.namespace.QName;
+
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -30,19 +32,24 @@
  * A Fault that occurs during invocation processing.
  */
 public class Fault extends UncheckedException {
-
+    public static final QName FAULT_CODE_CLIENT = new QName("http://cxf.apache.org/faultcode",
"client");
+    public static final QName FAULT_CODE_SERVER = new QName("http://cxf.apache.org/faultcode",
"server");
+    
     public static final String STACKTRACE = "stackTrace";
     private Element detail;
     private String message;
+    private QName code;
     
     public Fault(Message message, Throwable throwable) {
         super(message, throwable);
         this.message = message.toString();
+        code = FAULT_CODE_SERVER;
     }
     
     public Fault(Message message) {
         super(message);
         this.message = message.toString();
+        code = FAULT_CODE_SERVER;
     }
 
     public Fault(Throwable t) {
@@ -52,14 +59,46 @@
         } else {
             message = t == null ? null : t.getMessage();
         }
+        code = FAULT_CODE_SERVER;
+    }
+    
+    public Fault(Message message, Throwable throwable, QName fc) {
+        super(message, throwable);
+        this.message = message.toString();
+        code = fc;
+    }
+    
+    public Fault(Message message, QName fc) {
+        super(message);
+        this.message = message.toString();
+        code = fc;
     }
 
+    public Fault(Throwable t, QName fc) {
+        super(t);
+        if (super.getMessage() != null) {
+            message = super.getMessage();
+        } else {
+            message = t == null ? null : t.getMessage();
+        }
+        code = fc;
+    }    
+
     public String getMessage() {
         return message;
     }
 
     public void setMessage(String message) {
         this.message = message;
+    }
+    
+    public QName getFaultCode() {
+        return code;
+    }
+    
+    public Fault setFaultCode(QName c) {
+        code = c;
+        return this;
     }
 
     /**

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java?view=diff&rev=532798&r1=532797&r2=532798
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java
(original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java
Thu Apr 26 09:46:57 2007
@@ -121,7 +121,7 @@
         super.endElement();
     }
 
-    final Element getCurrentElement() {
+    public final Element getCurrentElement() {
         return (Element)getCurrentFrame().element;
     }
 

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapFault.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapFault.java?view=diff&rev=532798&r1=532797&r2=532798
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapFault.java
(original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapFault.java
Thu Apr 26 09:46:57 2007
@@ -46,38 +46,27 @@
      * FaultHandler) be mapped to "Sender" instead.
      */ 
 
-    private QName faultCode;
     private QName subCode;
     private String role;
     private String node;
     private Map<String, String> namespaces = new HashMap<String, String>();
 
     public SoapFault(Message message, Throwable throwable, QName faultCode) {
-        super(message, throwable);
-        this.faultCode = faultCode;
+        super(message, throwable, faultCode);
     }
 
     public SoapFault(Message message, QName faultCode) {
-        super(message);
-        this.faultCode = faultCode;
+        super(message, faultCode);
     }
 
     public SoapFault(String message, QName faultCode) {
-        super(new Message(message, (ResourceBundle)null));
-        this.faultCode = faultCode;
+        super(new Message(message, (ResourceBundle)null), faultCode);
     }
 
-    /**
-     * Returns the fault code of this fault.
-     * 
-     * @return the fault code.
-     */
-    public QName getFaultCode() {
-        return faultCode;
-    }
+
     
     public String getCodeString(String prefix, String defaultPrefix) {
-        return getFaultCodeString(prefix, defaultPrefix, faultCode);
+        return getFaultCodeString(prefix, defaultPrefix, getFaultCode());
     }
     
     public String getSubCodeString(String prefix, String defaultPrefix) {
@@ -98,15 +87,6 @@
         return prefix + ":" + fCode.getLocalPart();        
     }
 
-    /**
-     * Sets the fault code of this fault.
-     * 
-     * @param faultCode the fault code.
-     */
-    public void setFaultCode(QName faultCode) {
-        this.faultCode = faultCode;
-    }
-
     public String getReason() {
         return getMessage();
     }
@@ -168,8 +148,15 @@
             return (SoapFault)f;
         }
 
-        SoapFault soapFault = new SoapFault(new Message(f.getMessage(), (ResourceBundle)null),
f.getCause(),
-                                            v.getReceiver());
+        QName fc = f.getFaultCode();
+        if (Fault.FAULT_CODE_CLIENT.equals(fc)) {
+            fc = v.getSender();
+        } else if (Fault.FAULT_CODE_SERVER.equals(fc)) { 
+            fc = v.getReceiver();
+        }
+        SoapFault soapFault = new SoapFault(new Message(f.getMessage(), (ResourceBundle)null),
+                                            f.getCause(),
+                                            fc);
         
         soapFault.setDetail(f.getDetail());
         return soapFault;

Modified: 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=diff&rev=532798&r1=532797&r2=532798
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
(original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/interceptor/SoapFaultSerializerTest.java
Thu Apr 26 09:46:57 2007
@@ -33,6 +33,7 @@
 import org.apache.cxf.binding.soap.SoapFault;
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.staxutils.StaxUtils;
@@ -134,4 +135,23 @@
         assertEquals(fault.getMessage(), fault2.getMessage());        
     }
     
+    @Test
+    public void testFaultToSoapFault() throws Exception {
+        Exception ex = new Exception();
+        Fault fault = new Fault(ex, Fault.FAULT_CODE_CLIENT);
+        
+        SoapFault sf = SoapFault.createFault(fault, Soap11.getInstance());
+        assertEquals(Soap11.getInstance().getSender(), sf.getFaultCode());
+        
+        sf = SoapFault.createFault(fault, Soap12.getInstance());
+        assertEquals(Soap12.getInstance().getSender(), sf.getFaultCode());
+        
+        fault = new Fault(ex, Fault.FAULT_CODE_SERVER);
+        sf = SoapFault.createFault(fault, Soap11.getInstance());
+        assertEquals(Soap11.getInstance().getReceiver(), sf.getFaultCode());
+        
+        sf = SoapFault.createFault(fault, Soap12.getInstance());
+        assertEquals(Soap12.getInstance().getReceiver(), sf.getFaultCode());
+        
+    }
 }

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/BareInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/BareInInterceptor.java?view=diff&rev=532798&r1=532797&r2=532798
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/BareInInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/BareInInterceptor.java
Thu Apr 26 09:46:57 2007
@@ -132,7 +132,8 @@
             }
 
             if (p == null) {
-                throw new Fault(new org.apache.cxf.common.i18n.Message("NO_PART_FOUND", BUNDLE,
elName));
+                throw new Fault(new org.apache.cxf.common.i18n.Message("NO_PART_FOUND", BUNDLE,
elName),
+                                Fault.FAULT_CODE_CLIENT);
             }
 
             o = dr.read(p, xmlReader);

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/DocLiteralInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/DocLiteralInInterceptor.java?view=diff&rev=532798&r1=532797&r2=532798
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/DocLiteralInInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/DocLiteralInInterceptor.java
Thu Apr 26 09:46:57 2007
@@ -177,7 +177,8 @@
                 }
 
                 if (p == null) {
-                    throw new Fault(new org.apache.cxf.common.i18n.Message("NO_PART_FOUND",
BUNDLE, elName));
+                    throw new Fault(new org.apache.cxf.common.i18n.Message("NO_PART_FOUND",
BUNDLE, elName),
+                                    Fault.FAULT_CODE_CLIENT);
                 }
 
                 o = dr.read(p, xmlReader);

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/WrappedInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/WrappedInInterceptor.java?view=diff&rev=532798&r1=532797&r2=532798
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/WrappedInInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/WrappedInInterceptor.java
Thu Apr 26 09:46:57 2007
@@ -82,7 +82,8 @@
             // TODO: Allow overridden methods.
             operation = ServiceModelUtil.getOperation(message.getExchange(), local);
             if (operation == null) {
-                throw new Fault(new org.apache.cxf.common.i18n.Message("NO_OPERATION", BUNDLE,
local));
+                throw new Fault(new org.apache.cxf.common.i18n.Message("NO_OPERATION", BUNDLE,
local),
+                                Fault.FAULT_CODE_CLIENT);
             }
 
         }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/LogicalMessageImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/LogicalMessageImpl.java?view=diff&rev=532798&r1=532797&r2=532798
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/LogicalMessageImpl.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/LogicalMessageImpl.java
Thu Apr 26 09:46:57 2007
@@ -25,6 +25,8 @@
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.Source;
@@ -60,22 +62,32 @@
                 msgContext.getWrappedMessage().setContent(List.class, list);
             }
             
-            W3CDOMStreamWriter writer;
-            try {
-                writer = new W3CDOMStreamWriter();
-            } catch (ParserConfigurationException e) {
-                throw new WebServiceException(e);
+            SOAPMessage msg = msgContext.getWrappedMessage().getContent(SOAPMessage.class);
+            if (msg != null) {
+                try {
+                    source = new DOMSource(msg.getSOAPBody().getFirstChild());
+                } catch (SOAPException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+            } else {
+                W3CDOMStreamWriter writer;
+                try {
+                    writer = new W3CDOMStreamWriter();
+                } catch (ParserConfigurationException e) {
+                    throw new WebServiceException(e);
+                }
+                XMLStreamWriter orig = msgContext.getWrappedMessage().getContent(XMLStreamWriter.class);
+                try {
+                    msgContext.getWrappedMessage().setContent(XMLStreamWriter.class, writer);
+                    BareOutInterceptor bi = new BareOutInterceptor();
+                    bi.handleMessage(msgContext.getWrappedMessage());
+                } finally {
+                    msgContext.getWrappedMessage().setContent(XMLStreamWriter.class, orig);

+                }
+                
+                source = new DOMSource(writer.getDocument().getDocumentElement());
             }
-            XMLStreamWriter orig = msgContext.getWrappedMessage().getContent(XMLStreamWriter.class);
-            try {
-                msgContext.getWrappedMessage().setContent(XMLStreamWriter.class, writer);
-                BareOutInterceptor bi = new BareOutInterceptor();
-                bi.handleMessage(msgContext.getWrappedMessage());
-            } finally {
-                msgContext.getWrappedMessage().setContent(XMLStreamWriter.class, orig); 
-            }
-            
-            source = new DOMSource(writer.getDocument().getDocumentElement());
             msgContext.getWrappedMessage().setContent(Source.class, source);
         }
         return source;

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/ProviderInDatabindingInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/ProviderInDatabindingInterceptor.java?view=diff&rev=532798&r1=532797&r2=532798
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/ProviderInDatabindingInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/ProviderInDatabindingInterceptor.java
Thu Apr 26 09:46:57 2007
@@ -24,6 +24,8 @@
 import javax.xml.soap.SOAPMessage;
 import javax.xml.stream.XMLStreamReader;
 
+import org.w3c.dom.Node;
+
 import org.apache.cxf.databinding.DataReader;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.interceptor.AbstractInDatabindingInterceptor;
@@ -34,6 +36,7 @@
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.service.Service;
 import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.staxutils.W3CDOMStreamReader;
 
 public class ProviderInDatabindingInterceptor extends AbstractInDatabindingInterceptor {
 
@@ -62,21 +65,29 @@
         }
         
         Service s = ex.get(Service.class);
-        SOAPMessage sm = message.getContent(SOAPMessage.class);
-        if (sm != null) {
-            params.add(sm);
+        
+        if (SOAPMessage.class.equals(type)) {
+            SOAPMessage msg = message.getContent(SOAPMessage.class);
+            params.add(msg);
         } else {
+
             XMLStreamReader r = message.getContent(XMLStreamReader.class);
-            
             if (r != null) {
-                DataReader<XMLStreamReader> reader = 
-                    s.getDataBinding().createReader(XMLStreamReader.class);
-                
-                Object object = reader.read(null, r, type);
-                params.add(object);
+                if (r instanceof W3CDOMStreamReader) {
+                    Node nd = ((W3CDOMStreamReader)r).getCurrentElement();
+                    DataReader<Node> reader = 
+                        s.getDataBinding().createReader(Node.class);
+                    Object object = reader.read(null, nd, type);
+                    params.add(object);
+                } else {
+                    DataReader<XMLStreamReader> reader = 
+                        s.getDataBinding().createReader(XMLStreamReader.class);
+                    
+                    Object object = reader.read(null, r, type);
+                    params.add(object);
+                }
             }
         }
-        
         message.setContent(Object.class, params);
 
     }



Mime
View raw message