cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dand...@apache.org
Subject svn commit: r447027 - in /incubator/cxf/trunk: api/src/main/java/org/apache/cxf/interceptor/ rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/ rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ rt/core/src/main/java/org/a...
Date Sun, 17 Sep 2006 09:41:02 GMT
Author: dandiep
Date: Sun Sep 17 02:41:01 2006
New Revision: 447027

URL: http://svn.apache.org/viewvc?view=rev&rev=447027
Log:
Finish server side fault handling for JAX-WS. Throwing JAX-WS generated faults now works.

Added:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
      - copied, changed from r446583, incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/OutFaultConverterInterceptor.java
Removed:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/OutFaultConverterInterceptor.java
Modified:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/Fault.java
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapFault.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/service/invoker/AbstractInvoker.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/SoapFaultTest.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=447027&r1=447026&r2=447027
==============================================================================
--- 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 Sun Sep 17
02:41:01 2006
@@ -19,10 +19,12 @@
 
 package org.apache.cxf.interceptor;
 
+import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.i18n.UncheckedException;
+import org.apache.cxf.helpers.DOMUtils;
 
 /**
  * A Fault that occurs during invocation processing.
@@ -30,20 +32,31 @@
 public class Fault extends UncheckedException {
 
     private Element detail;
+    private String message;
     
     public Fault(Message message, Throwable throwable) {
         super(message, throwable);
+        this.message = message.toString();
     }
     
     public Fault(Message message) {
         super(message);
+        this.message = message.toString();
     }
 
     public Fault(Throwable t) {
         super(t);
+        message = super.getMessage();
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
     }
 
-    
     /**
      * Returns the detail node. If no detail node has been set, an empty
      * <code>&lt;detail&gt;</code> is created.
@@ -70,7 +83,13 @@
      *         <code>false</code> otherwise.
      */
     public boolean hasDetails() {
-        return detail == null ? false : true;
+        return this.detail != null;
     }
 
+    public Element getOrCreateDetail() {
+        Document d = DOMUtils.createDocument();
+        Element element = d.createElement("Fault");
+        this.detail = element;
+        return 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=447027&r1=447026&r2=447027
==============================================================================
--- 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
Sun Sep 17 02:41:01 2006
@@ -59,7 +59,7 @@
     private QName subCode;
     private String role;
     private Map<String, String> namespaces = new HashMap<String, String>();
-    
+
     public SoapFault(Message message, Throwable throwable, QName type) {
         super(message, throwable);
         this.faultCode = type;
@@ -132,7 +132,7 @@
     public void setSubCode(QName subCode) {
         this.subCode = subCode;
     }
-    
+
     public Map<String, String> getNamespaces() {
         return namespaces;
     }
@@ -143,12 +143,12 @@
 
     public static SoapFault createFault(Fault f) {
         if (f instanceof SoapFault) {
-            return (SoapFault) f;
+            return (SoapFault)f;
         }
-        
-        SoapFault soapFault = new SoapFault(new Message(f.getMessage(), (ResourceBundle)null),
f
-            .getCause(), RECEIVER);
-        
+
+        SoapFault soapFault = new SoapFault(new Message(f.getMessage(), (ResourceBundle)null),
f.getCause(),
+                                            RECEIVER);
+        soapFault.setDetail(f.getDetail());
         return soapFault;
     }
 }

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=447027&r1=447026&r2=447027
==============================================================================
--- 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
Sun Sep 17 02:41:01 2006
@@ -99,7 +99,6 @@
 
             if (fault.hasDetails()) {
                 Element detail = fault.getDetail();
-
                 writer.writeStartElement("detail");
 
                 NodeList details = detail.getChildNodes();

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/AbstractInvoker.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/AbstractInvoker.java?view=diff&rev=447027&r1=447026&r2=447027
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/AbstractInvoker.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/invoker/AbstractInvoker.java
Sun Sep 17 02:41:01 2006
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.service.invoker;
 
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.util.ArrayList;
@@ -60,6 +61,12 @@
                 retList.add(res);
             }
             return Arrays.asList(retList.toArray());
+        } catch (InvocationTargetException e) {
+            Throwable t = e.getCause();
+            if (t == null) {
+                t = e;
+            }
+            throw new Fault(t);
         } catch (Exception e) {
             throw new Fault(e);
         }

Copied: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
(from r446583, incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/OutFaultConverterInterceptor.java)
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java?view=diff&rev=447027&p1=incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/OutFaultConverterInterceptor.java&r1=446583&p2=incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java&r2=447027
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/OutFaultConverterInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
Sun Sep 17 02:41:01 2006
@@ -19,21 +19,68 @@
 
 package org.apache.cxf.jaxws.interceptors;
 
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ResourceBundle;
+
+import javax.xml.namespace.QName;
 import javax.xml.ws.WebFault;
 
+import org.w3c.dom.Node;
+
+import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.databinding.DataWriter;
+import org.apache.cxf.databinding.DataWriterFactory;
 import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.jaxws.support.JaxWsServiceConfiguration;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.service.Service;
+
+public class WebFaultOutInterceptor extends AbstractPhaseInterceptor<Message> {
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JaxWsServiceConfiguration.class);
 
-public class OutFaultConverterInterceptor extends AbstractPhaseInterceptor<Message>
{
+    public WebFaultOutInterceptor() {
+        super();
+        setPhase(Phase.PRE_PROTOCOL);
+    }
 
     public void handleMessage(Message message) throws Fault {
         Fault f = (Fault)message.getContent(Exception.class);
 
         Throwable cause = f.getCause();
         if (cause instanceof Exception && cause.getClass().isAnnotationPresent(WebFault.class))
{
-            // serialize to details
+            Exception ex = (Exception)cause;
+            try {
+                Method method = cause.getClass().getMethod("getFaultInfo", new Class[0]);
+                Object faultInfo = method.invoke(cause, new Object[0]);
+
+                Service service = message.getExchange().get(Service.class);
+
+                DataWriterFactory writerFactory = service.getDataWriterFactory();
+                DataWriter<Node> writer = writerFactory.createWriter(Node.class);
+
+                QName faultName = getFaultName(ex);
+                writer.write(faultInfo, faultName, f.getOrCreateDetail());
+
+                f.setMessage(ex.getMessage());
+            } catch (InvocationTargetException e) {
+                throw new Fault(new org.apache.cxf.common.i18n.Message("INVOCATION_TARGET_EXC",
BUNDLE), e);
+            } catch (NoSuchMethodException e) {
+                throw new Fault(new org.apache.cxf.common.i18n.Message("NO_GETFAULTINFO_METHOD",
BUNDLE), e);
+            } catch (IllegalArgumentException e) {
+                throw new Fault(new org.apache.cxf.common.i18n.Message("COULD_NOT_INVOKE",
BUNDLE), e);
+            } catch (IllegalAccessException e) {
+                throw new Fault(new org.apache.cxf.common.i18n.Message("COULD_NOT_INVOKE",
BUNDLE), e);
+            }
         }
+    }
+
+    private QName getFaultName(Exception webFault) {
+        WebFault wf = webFault.getClass().getAnnotation(WebFault.class);
+
+        return new QName(wf.targetNamespace(), wf.name());
     }
 
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java?view=diff&rev=447027&r1=447026&r2=447027
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
Sun Sep 17 02:41:01 2006
@@ -42,6 +42,7 @@
 import org.apache.cxf.endpoint.ServerImpl;
 import org.apache.cxf.interceptor.WrappedInInterceptor;
 import org.apache.cxf.jaxb.JAXBDataBinding;
+import org.apache.cxf.jaxws.interceptors.WebFaultOutInterceptor;
 import org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor;
 import org.apache.cxf.service.Service;
 import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
@@ -72,6 +73,13 @@
     public JaxWsServiceFactoryBean(JaxwsImplementorInfo i) {
         this();
         this.implInfo = i;
+    }
+
+    @Override
+    protected void initializeDefaultInterceptors() {
+        super.initializeDefaultInterceptors();
+        
+        getService().getOutFaultInterceptors().add(new WebFaultOutInterceptor());
     }
 
     public void activateEndpoints() throws IOException, WSDLException, BusException, EndpointException
{

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/SoapFaultTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/SoapFaultTest.java?view=diff&rev=447027&r1=447026&r2=447027
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/SoapFaultTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/SoapFaultTest.java
Sun Sep 17 02:41:01 2006
@@ -99,13 +99,14 @@
      * We need to get the jaxws fault -> soap fault conversion working for this
      * @throws Exception
      */
-    public void xtestWebServiceException() throws Exception {
+    public void testWebServiceException() throws Exception {
         Node response = invoke("http://localhost:9000/SoapContext/SoapPort",
                                LocalTransportFactory.TRANSPORT_ID, "GreeterGetFaultMessage.xml");
 
         assertNotNull(response);
 
-        assertValid("/s:Envelope/s:Body/s:Fault/faultstring[text()='I blame Hadrian.']",
response);
+        assertValid("/s:Envelope/s:Body/s:Fault/faultstring[text()='TestBadRecordLit']",
response);
+        assertValid("/s:Envelope/s:Body/s:Fault/detail", response);
     }
 
     public class FaultThrowingInterceptor extends AbstractSoapInterceptor {



Mime
View raw message