cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t..@apache.org
Subject svn commit: r448037 - in /incubator/cxf/trunk/rt: bindings/xml/src/main/java/org/apache/cxf/binding/xml/ bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/ frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/
Date Wed, 20 Sep 2006 03:00:17 GMT
Author: tli
Date: Tue Sep 19 20:00:16 2006
New Revision: 448037

URL: http://svn.apache.org/viewvc?view=rev&rev=448037
Log:
add xml fault interceptor processing

Modified:
    incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLBindingFactory.java
    incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLConstants.java
    incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLFault.java
    incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultInInterceptor.java
    incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsUtils.java

Modified: incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLBindingFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLBindingFactory.java?view=diff&rev=448037&r1=448036&r2=448037
==============================================================================
--- incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLBindingFactory.java
(original)
+++ incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLBindingFactory.java
Tue Sep 19 20:00:16 2006
@@ -67,10 +67,14 @@
         
         xb.getInInterceptors().add(new StaxInInterceptor());
         xb.getInInterceptors().add(new XMLMessageInInterceptor());
+        
+        xb.getInFaultInterceptors().add(new StaxInInterceptor());
         xb.getInFaultInterceptors().add(xb.getInFaultInterceptor());
         
         xb.getOutInterceptors().add(new StaxOutInterceptor());
         xb.getOutInterceptors().add(new XMLMessageOutInterceptor());
+        
+        xb.getOutFaultInterceptors().add(new StaxOutInterceptor());
         xb.getOutFaultInterceptors().add(xb.getOutFaultInterceptor());
 
         return xb;

Modified: incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLConstants.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLConstants.java?view=diff&rev=448037&r1=448036&r2=448037
==============================================================================
--- incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLConstants.java
(original)
+++ incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLConstants.java
Tue Sep 19 20:00:16 2006
@@ -19,16 +19,8 @@
 
 package org.apache.cxf.binding.xml;
 
-import javax.xml.namespace.QName;
 
 public final class XMLConstants {
     public static final String NS_XML_FORMAT = "http://celtix.objectweb.org/bindings/xformat";
 
-    public static final QName XML_FAULT_ROOT = new QName(NS_XML_FORMAT, "XMLFault");
-    public static final QName XML_FAULT_CODE = new QName(NS_XML_FORMAT, "faultcode");
-    public static final QName XML_FAULT_STRING = new QName(NS_XML_FORMAT, "faultstring");
-    public static final QName XML_FAULT_DETAIL = new QName(NS_XML_FORMAT, "detail");
-
-    public static final QName XML_FAULT_CODE_SERVER = new QName(NS_XML_FORMAT, "SERVER");
-    public static final QName XML_FAULT_CODE_CLIENT = new QName(NS_XML_FORMAT, "CLIENT");
 }

Modified: incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLFault.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLFault.java?view=diff&rev=448037&r1=448036&r2=448037
==============================================================================
--- incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLFault.java
(original)
+++ incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLFault.java
Tue Sep 19 20:00:16 2006
@@ -18,111 +18,54 @@
  */
 package org.apache.cxf.binding.xml;
 
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Text;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ResourceBundle;
+
+import javax.xml.namespace.QName;
 
 import org.apache.cxf.common.i18n.Message;
-import org.apache.cxf.helpers.XMLUtils;
 import org.apache.cxf.interceptor.Fault;
 
 public class XMLFault extends Fault {
 
-    static final long serialVersionUID = 100000;
+    public static final String XML_FAULT_PREFIX = "xfns";
 
-    private Node faultRoot;
+    public static final QName XML_FAULT_ROOT = new QName(XMLConstants.NS_XML_FORMAT, "XMLFault");
 
-    // private QNname faultCode;
-    private String faultString;
+    public static final QName XML_FAULT_STRING = new QName(XMLConstants.NS_XML_FORMAT, "faultstring");
 
-    private Node faultDetail;
+    public static final QName XML_FAULT_DETAIL = new QName(XMLConstants.NS_XML_FORMAT, "detail");
 
-    private Node detailRoot;
+    public static final QName XML_FAULT_CODE_SERVER = new QName(XMLConstants.NS_XML_FORMAT,
"SERVER");
+
+    public static final QName XML_FAULT_CODE_CLIENT = new QName(XMLConstants.NS_XML_FORMAT,
"CLIENT");
 
     
+    static final long serialVersionUID = 100000;
 
     public XMLFault(Message message, Throwable throwable) {
-        super(message, throwable);
+        super(message, throwable);        
     }
 
     public XMLFault(Message message) {
-        super(message);
-    }
-
-    public XMLFault(Throwable t) {
-        super(t);
-    }
-
-    public void setFaultString(String str) {
-        this.faultString = str;
+        super(message);        
     }
 
-    public void addFaultString(String str) {
-        assert faultRoot != null;
-
-        Text text = XMLUtils.createTextNode(this.faultRoot, str);
-        Node faultStringNode = XMLUtils.createElementNS(this.faultRoot, XMLConstants.XML_FAULT_STRING);
-        faultStringNode.appendChild(text);
-        this.faultRoot.appendChild(faultStringNode);
-
-        this.faultString = str;
+    public XMLFault(String message) {
+        super(new Message(message, (ResourceBundle) null));        
     }
 
-    public void setFaultDetail(Node detail) {
-        this.detailRoot = detail;
-
-        NodeList list = detail.getChildNodes();
-        for (int i = 0; i < list.getLength(); i++) {
-            Node entry = list.item(i);
-            if (entry.getNodeType() != Node.ELEMENT_NODE) {
-                continue;
-            }
-            this.faultDetail = detail;
+    public static XMLFault createFault(Fault f) {
+        if (f instanceof XMLFault) {
+            return (XMLFault) f;
         }
-    }
-
-    public void appendFaultDetail(Node detail) {
-        assert faultRoot != null;
-        assert detailRoot != null;
-
-        this.detailRoot.appendChild(detail);
-        this.faultDetail = detail;
-    }
-
-    public Node addFaultDetail() {
-        assert faultRoot != null;
-
-        this.detailRoot = XMLUtils.createElementNS(this.faultRoot, XMLConstants.XML_FAULT_DETAIL);
-        this.faultRoot.appendChild(this.detailRoot);
-        return this.detailRoot;
-    }
-
-    public String getFaultString() {
-        return this.faultString;
-    }
-
-    public Node getFaultDetail() {
-        return this.faultDetail;
-    }
-
-    public Node getFaultDetailRoot() {
-        return this.detailRoot;
-    }
-
-    public Node getFaultRoot() {
-        return this.faultRoot;
-    }
-
-    protected void setFaultRoot(Node root) {
-        this.faultRoot = root;
-    }
-
-    public void removeChild(Node node) {
-        this.faultRoot.removeChild(node);
-    }
-
-    public boolean hasChildNodes() {
-        return this.faultRoot.hasChildNodes();
+        Throwable th = f.getCause();
+        if (f.getCause() instanceof InvocationTargetException) {
+            th = th.getCause();
+        }
+        XMLFault xmlFault = new XMLFault(new Message(f.getMessage(), (ResourceBundle) null),
th);
+        xmlFault.setDetail(f.getDetail());
+        return xmlFault;
     }
 
 }

Modified: incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultInInterceptor.java?view=diff&rev=448037&r1=448036&r2=448037
==============================================================================
--- incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultInInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultInInterceptor.java
Tue Sep 19 20:00:16 2006
@@ -19,33 +19,13 @@
 
 package org.apache.cxf.binding.xml.interceptor;
 
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamReader;
-
-import org.apache.cxf.binding.xml.XMLConstants;
 import org.apache.cxf.interceptor.AbstractInDatabindingInterceptor;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Message;
-import org.apache.cxf.staxutils.DepthXMLStreamReader;
-import org.apache.cxf.staxutils.StaxUtils;
 
 public class XMLFaultInInterceptor extends AbstractInDatabindingInterceptor {
 
     public void handleMessage(Message message) throws Fault {
 
-        XMLStreamReader reader = message.getContent(XMLStreamReader.class);
-        DepthXMLStreamReader dr = new DepthXMLStreamReader(reader);
-        // List<Exception> exlist = new ArrayList<Exception>();
-
-        StaxUtils.nextEvent(dr);
-        if (StaxUtils.toNextElement(dr)) {
-            QName startQName = new QName(dr.getNamespaceURI(), dr.getLocalName());
-            if (startQName.equals(XMLConstants.XML_FAULT_ROOT)) {
-                while (StaxUtils.toNextElement(dr)) {
-                    // marshall exception detail by jaxb, and add into exList
-
-                }
-            }
-        }
     }
 }

Modified: incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptor.java?view=diff&rev=448037&r1=448036&r2=448037
==============================================================================
--- incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptor.java
Tue Sep 19 20:00:16 2006
@@ -18,15 +18,106 @@
  */
 package org.apache.cxf.binding.xml.interceptor;
 
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import java.util.ResourceBundle;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.cxf.binding.xml.XMLConstants;
+import org.apache.cxf.binding.xml.XMLFault;
+import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.databinding.DataWriter;
+import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.FaultInfo;
+import org.apache.cxf.service.model.MessagePartInfo;
+
+public class XMLFaultOutInterceptor extends AbstractOutDatabindingInterceptor {
 
-public class XMLFaultOutInterceptor extends AbstractPhaseInterceptor {
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(XMLFaultOutInterceptor.class);
+
+    public XMLFaultOutInterceptor() {
+        super();
+        setPhase(Phase.MARSHAL);
+    }
 
     public void handleMessage(Message message) throws Fault {
-        // TODO Auto-generated method stub
+
+        XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
+        Fault f = (Fault) message.getContent(Exception.class);
+        XMLFault xmlFault = XMLFault.createFault(f);
+        try {
+            writer.writeStartElement(XMLFault.XML_FAULT_PREFIX, XMLFault.XML_FAULT_ROOT.getLocalPart(),
+                            XMLConstants.NS_XML_FORMAT);
+
+            writer.writeStartElement(XMLFault.XML_FAULT_PREFIX, XMLFault.XML_FAULT_STRING.getLocalPart(),
+                            XMLConstants.NS_XML_FORMAT);
+
+            Throwable t = xmlFault.getCause();
+            StringBuffer str = new StringBuffer(t.toString());
+            
+            QName elName = null;
+            
+            BindingOperationInfo bop = message.getExchange().get(BindingOperationInfo.class);
+            if (!bop.isUnwrappedCapable()) {
+                bop = bop.getUnwrappedOperation();
+            }
+            Iterator<FaultInfo> it = bop.getOperationInfo().getFaults().iterator();
+            Boolean isWebFault = null;
+            while (it.hasNext()) {
+                FaultInfo fi = it.next();
+                for (MessagePartInfo mpi : fi.getMessageParts()) {
+                    Class cls = mpi.getProperty(Class.class.getName(), Class.class);
+                    if (cls != null && cls.equals(t.getClass())) {
+                        if (mpi.isElement()) {
+                            elName = mpi.getElementQName();
+                        } else {
+                            elName = mpi.getTypeQName();
+                        }
+                        isWebFault = mpi.getProperty("javax.xml.ws.WebFault", Boolean.class);
+                        break;
+                    }
+                }
+            }
+            if (!(isWebFault != null && isWebFault.booleanValue())) {
+                str.append("\n");
+                for (StackTraceElement s : t.getStackTrace()) {
+                    str.append(s.toString());
+                    str.append("\n");
+                }
+            }
+            writer.writeCharacters(str.toString());
+            // fault string
+            writer.writeEndElement();
+            // call data writer to marshal exception
+            if (elName != null) {
+                DataWriter<Message> dataWriter = getMessageDataWriter(message);   
        
+                dataWriter.write(getFaultInfo(t), elName, message);
+            }
+            // fault root
+            writer.writeEndElement();
+        } catch (XMLStreamException xe) {
+            throw new Fault(new org.apache.cxf.common.i18n.Message("XML_WRITE_EXC", BUNDLE),
xe);
+        }
 
     }
 
+    private static Object getFaultInfo(Throwable fault) {
+        try {
+            Method faultInfoMethod = fault.getClass().getMethod("getFaultInfo");
+            if (faultInfoMethod != null) {
+                return faultInfoMethod.invoke(fault);
+            }
+        } catch (Exception ex) {
+            throw new RuntimeException("Could not get faultInfo out of Exception", ex);
+        }
+
+        return null;
+    }
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsUtils.java?view=diff&rev=448037&r1=448036&r2=448037
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsUtils.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsUtils.java
Tue Sep 19 20:00:16 2006
@@ -22,6 +22,9 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 
+import javax.xml.ws.WebFault;
+
+import org.apache.cxf.service.model.FaultInfo;
 import org.apache.cxf.service.model.MessagePartInfo;
 import org.apache.cxf.service.model.OperationInfo;
 
@@ -82,7 +85,7 @@
                 if (selected == seiMethod) {
                     Object[] paraType = selected.getGenericParameterTypes();
                     ParameterizedType paramType = (ParameterizedType) paraType[idx];
-                    if (((Class)paramType.getRawType()).getName().equals("javax.xml.ws.Holder"))
{
+                    if (((Class) paramType.getRawType()).getName().equals("javax.xml.ws.Holder"))
{
                         mpiOut.setProperty(Class.class.getName(),
                                         (Class) paramType.getActualTypeArguments()[0]);
                         mpiInHolder.setProperty(Class.class.getName(), (Class) paramType
@@ -101,6 +104,15 @@
                 mpiOut.setProperty(Class.class.getName(), selected.getReturnType());
             }
         }
-
+        for (FaultInfo fi : o.getFaults()) {
+            int i = 0;
+            Class cls = selected.getExceptionTypes()[i];
+            fi.getMessagePartByIndex(0).setProperty(Class.class.getName(), cls);        
       
+            if (cls.isAnnotationPresent(WebFault.class)) {
+                fi.getMessagePartByIndex(i).setProperty(WebFault.class.getName(), Boolean.TRUE);
+            }
+            i++;
+        }
     }
+    
 }



Mime
View raw message