cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t..@apache.org
Subject svn commit: r465545 - in /incubator/cxf/trunk: distribution/src/main/release/samples/hello_world_xml_wrapped/src/demo/hw/client/ rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/ rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/intercep...
Date Thu, 19 Oct 2006 09:43:37 GMT
Author: tli
Date: Thu Oct 19 02:43:36 2006
New Revision: 465545

URL: http://svn.apache.org/viewvc?view=rev&rev=465545
Log:
support xml binding fault processing

Modified:
    incubator/cxf/trunk/distribution/src/main/release/samples/hello_world_xml_wrapped/src/demo/hw/client/Client.java
    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/XMLFault.java
    incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/Messages.properties
    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/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptor.java
    incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageOutInterceptor.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerXMLWrapTest.java

Modified: incubator/cxf/trunk/distribution/src/main/release/samples/hello_world_xml_wrapped/src/demo/hw/client/Client.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/hello_world_xml_wrapped/src/demo/hw/client/Client.java?view=diff&rev=465545&r1=465544&r2=465545
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/hello_world_xml_wrapped/src/demo/hw/client/Client.java
(original)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/hello_world_xml_wrapped/src/demo/hw/client/Client.java
Thu Oct 19 02:43:36 2006
@@ -24,10 +24,9 @@
 import javax.xml.namespace.QName;
 
 import org.apache.hello_world_xml_http.wrapped.Greeter;
+import org.apache.hello_world_xml_http.wrapped.PingMeFault;
 import org.apache.hello_world_xml_http.wrapped.XMLService;
 
-// import org.apache.hello_world_xml_http.wrapped.PingMeFault;
-
 public final class Client {
 
     public static final QName SERVICE_NAME = new QName("http://apache.org/hello_world_xml_http/wrapped",
@@ -74,14 +73,14 @@
         System.out.println("No response from server as method is OneWay");
         System.out.println();
 
-        /*
-         * try { System.out.println("Invoking pingMe, expecting exception...");
-         * port.pingMe(); } catch (PingMeFault ex) {
-         * System.out.println("Expected exception: " + ex.getMessage()); }
-         */
-
+        try {
+            System.out.println("Invoking pingMe, expecting exception...");
+            port.pingMe();
+        } catch (PingMeFault ex) {
+            System.out.println("Expected exception: " + ex.getMessage());
+        }
+    
         System.exit(0);
-
     }
 
 }

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=465545&r1=465544&r2=465545
==============================================================================
--- 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
Thu Oct 19 02:43:36 2006
@@ -29,6 +29,8 @@
 import org.apache.cxf.binding.AbstractBindingFactory;
 import org.apache.cxf.binding.Binding;
 import org.apache.cxf.binding.BindingFactoryManager;
+import org.apache.cxf.binding.xml.interceptor.XMLFaultInInterceptor;
+import org.apache.cxf.binding.xml.interceptor.XMLFaultOutInterceptor;
 import org.apache.cxf.binding.xml.interceptor.XMLMessageInInterceptor;
 import org.apache.cxf.binding.xml.interceptor.XMLMessageOutInterceptor;
 import org.apache.cxf.interceptor.StaxInInterceptor;
@@ -77,11 +79,13 @@
         xb.getInInterceptors().add(new XMLMessageInInterceptor());
         
         xb.getInFaultInterceptors().add(new StaxInInterceptor());
+        xb.getInFaultInterceptors().add(new XMLFaultInInterceptor());
         
         xb.getOutInterceptors().add(new StaxOutInterceptor());
         xb.getOutInterceptors().add(new XMLMessageOutInterceptor());
         
         xb.getOutFaultInterceptors().add(new StaxOutInterceptor());
+        xb.getOutFaultInterceptors().add(new XMLFaultOutInterceptor());
 
         return xb;
     }

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=465545&r1=465544&r2=465545
==============================================================================
--- 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
Thu Oct 19 02:43:36 2006
@@ -21,8 +21,6 @@
 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.interceptor.Fault;
 
@@ -30,15 +28,15 @@
 
     public static final String XML_FAULT_PREFIX = "xfns";
 
-    public static final QName XML_FAULT_ROOT = new QName(XMLConstants.NS_XML_FORMAT, "XMLFault");
+    public static final String XML_FAULT_ROOT = "XMLFault";
 
-    public static final QName XML_FAULT_STRING = new QName(XMLConstants.NS_XML_FORMAT, "faultstring");
+    public static final String XML_FAULT_STRING = "faultstring";
 
-    public static final QName XML_FAULT_DETAIL = new QName(XMLConstants.NS_XML_FORMAT, "detail");
+    public static final String XML_FAULT_DETAIL = "detail";
 
-    public static final QName XML_FAULT_CODE_SERVER = new QName(XMLConstants.NS_XML_FORMAT,
"SERVER");
+    public static final String XML_FAULT_CODE_SERVER = "SERVER";
 
-    public static final QName XML_FAULT_CODE_CLIENT = new QName(XMLConstants.NS_XML_FORMAT,
"CLIENT");
+    public static final String XML_FAULT_CODE_CLIENT = "CLIENT";
 
     
     static final long serialVersionUID = 100000;

Modified: incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/Messages.properties?view=diff&rev=465545&r1=465544&r2=465545
==============================================================================
--- incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/Messages.properties
(original)
+++ incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/Messages.properties
Thu Oct 19 02:43:36 2006
@@ -27,3 +27,4 @@
 NO_DATAWRITER=No DataWriter is available for Service: {0}
 COULD_NOT_UNRWAP=Could not unrwap message parts.
 REQ_NOT_UNDERSTOOD=Could not read request. Operation {0} is unknown.
+ILLEAGAL_XMLFAULT_FORMAT=Illeagal xml fault message format.
\ No newline at end of file

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=465545&r1=465544&r2=465545
==============================================================================
--- 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
Thu Oct 19 02:43:36 2006
@@ -19,13 +19,56 @@
 
 package org.apache.cxf.binding.xml.interceptor;
 
+import java.util.ResourceBundle;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.w3c.dom.Element;
+
+import org.apache.cxf.binding.xml.XMLFault;
+import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.interceptor.AbstractInDatabindingInterceptor;
+import org.apache.cxf.interceptor.ClientFaultConverter;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.staxutils.DepthXMLStreamReader;
+import org.apache.cxf.staxutils.FragmentStreamReader;
+import org.apache.cxf.staxutils.StaxUtils;
 
 public class XMLFaultInInterceptor extends AbstractInDatabindingInterceptor {
 
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(XMLFaultInInterceptor.class);
+
+    public XMLFaultInInterceptor() {
+        super();
+        setPhase(Phase.MARSHAL);
+        addBefore(ClientFaultConverter.class.getName());
+    }
+    
     public void handleMessage(Message message) throws Fault {
+
+        XMLStreamReader xsr = message.getContent(XMLStreamReader.class);
+        DepthXMLStreamReader reader = new DepthXMLStreamReader(xsr);
+
+        try {
+            reader.nextTag();
+            if (!StaxUtils.toNextElement(reader)) {
+                throw new Fault(new org.apache.cxf.common.i18n.Message("ILLEAGAL_XMLFAULT_FORMAT",
BUNDLE));
+            }
+            String exMessage = reader.getElementText();
+            Fault fault = new XMLFault(exMessage);
+            reader.next();
+            if (StaxUtils.toNextElement(reader)) {
+                // handling detail
+                Element detail = StaxUtils.read(new FragmentStreamReader(reader)).getDocumentElement();
+                fault.setDetail(detail);
+            }
+            message.setContent(Exception.class, fault);
+        } catch (XMLStreamException xse) {
+            throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_READ_EXC", BUNDLE));
+        }
 
     }
 }

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=465545&r1=465544&r2=465545
==============================================================================
--- 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
Thu Oct 19 02:43:36 2006
@@ -30,6 +30,7 @@
 import org.apache.cxf.binding.xml.XMLFault;
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.databinding.DataWriter;
+import org.apache.cxf.helpers.NSStack;
 import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Message;
@@ -37,6 +38,7 @@
 import org.apache.cxf.service.model.BindingOperationInfo;
 import org.apache.cxf.service.model.FaultInfo;
 import org.apache.cxf.service.model.MessagePartInfo;
+import org.apache.cxf.staxutils.StaxUtils;
 
 public class XMLFaultOutInterceptor extends AbstractOutDatabindingInterceptor {
 
@@ -49,21 +51,23 @@
 
     public void handleMessage(Message message) throws Fault {
 
+        NSStack nsStack = new NSStack();
+        nsStack.push();
+
         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);
+            nsStack.add(XMLConstants.NS_XML_FORMAT);
+            String prefix = nsStack.getPrefix(XMLConstants.NS_XML_FORMAT);
 
-            writer.writeStartElement(XMLFault.XML_FAULT_PREFIX, XMLFault.XML_FAULT_STRING.getLocalPart(),
-                            XMLConstants.NS_XML_FORMAT);
+            StaxUtils.writeStartElement(writer, prefix, XMLFault.XML_FAULT_ROOT, XMLConstants.NS_XML_FORMAT);
 
+            StaxUtils.writeStartElement(writer, prefix, XMLFault.XML_FAULT_STRING, 
+                    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();
@@ -95,13 +99,20 @@
             writer.writeCharacters(str.toString());
             // fault string
             writer.writeEndElement();
+            
             // call data writer to marshal exception
             if (elName != null) {
-                DataWriter<Message> dataWriter = getMessageDataWriter(message);   
        
+                StaxUtils.writeStartElement(writer, prefix, XMLFault.XML_FAULT_DETAIL,
+                        XMLConstants.NS_XML_FORMAT);
+                DataWriter<Message> dataWriter = getMessageDataWriter(message);
                 dataWriter.write(getFaultInfo(t), elName, message);
+                writer.writeEndElement();
             }
             // fault root
             writer.writeEndElement();
+            
+            writer.flush();
+
         } catch (XMLStreamException xe) {
             throw new Fault(new org.apache.cxf.common.i18n.Message("XML_WRITE_EXC", BUNDLE),
xe);
         }

Modified: incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptor.java?view=diff&rev=465545&r1=465544&r2=465545
==============================================================================
--- incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptor.java
Thu Oct 19 02:43:36 2006
@@ -27,6 +27,7 @@
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamReader;
 
+import org.apache.cxf.binding.xml.XMLFault;
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.interceptor.AbstractInDatabindingInterceptor;
@@ -47,7 +48,7 @@
 
 public class XMLMessageInInterceptor extends AbstractInDatabindingInterceptor {
 
-    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(WrappedInInterceptor.class);
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(XMLMessageInInterceptor.class);
     
     // TODO: this should be part of the chain!!
     private BareInInterceptor bareInterceptor = new BareInInterceptor();
@@ -68,8 +69,17 @@
             throw new Fault(new org.apache.cxf.common.i18n.Message("NO_OPERATION_ELEMENT",
BUNDLE));
         }
         
-        QName startQName = reader.getName();
         Exchange ex = message.getExchange();
+        QName startQName = reader.getName();
+        // handling xml fault message
+        if (startQName.getLocalPart().equals(XMLFault.XML_FAULT_ROOT)) {            
+            message.getInterceptorChain().abort();
+            if (ep.getInFaultObserver() != null) {
+                ep.getInFaultObserver().onMessage(message);
+                return;
+            }
+        }
+        // handling xml normal inbound message
         BindingOperationInfo bop = ex.get(BindingOperationInfo.class);
         MessagePartInfo part = null;
         if (bop == null) {

Modified: incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageOutInterceptor.java?view=diff&rev=465545&r1=465544&r2=465545
==============================================================================
--- incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageOutInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageOutInterceptor.java
Thu Oct 19 02:43:36 2006
@@ -30,7 +30,6 @@
 import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
 import org.apache.cxf.interceptor.BareOutInterceptor;
 import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.interceptor.WrappedOutInterceptor;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.service.model.BindingMessageInfo;
@@ -40,7 +39,7 @@
 
 public class XMLMessageOutInterceptor extends AbstractOutDatabindingInterceptor {
 
-    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(WrappedOutInterceptor.class);
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(XMLMessageOutInterceptor.class);
     
     public XMLMessageOutInterceptor() {
         super();

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerXMLWrapTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerXMLWrapTest.java?view=diff&rev=465545&r1=465544&r2=465545
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerXMLWrapTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerXMLWrapTest.java
Thu Oct 19 02:43:36 2006
@@ -33,19 +33,20 @@
 import org.apache.cxf.systest.common.TestServerBase;
 import org.apache.hello_world_xml_http.wrapped.Greeter;
 import org.apache.hello_world_xml_http.wrapped.GreeterImpl;
+import org.apache.hello_world_xml_http.wrapped.PingMeFault;
 import org.apache.hello_world_xml_http.wrapped.XMLService;
 
-
 public class ClientServerXMLWrapTest extends TestCase {
-    private final QName serviceName = 
-        new QName("http://apache.org/hello_world_xml_http/wrapped", "XMLService");
-    private final QName portName = 
-        new QName("http://apache.org/hello_world_xml_http/wrapped", "XMLPort");
+
+    private final QName serviceName = new QName("http://apache.org/hello_world_xml_http/wrapped",
+            "XMLService");
+
+    private final QName portName = new QName("http://apache.org/hello_world_xml_http/wrapped",
"XMLPort");
+
     private final QName fakePortName = 
-        new QName("http://apache.org/hello_world_xml_http/wrapped", "FackPort");
+        new QName("http://apache.org/hello_world_xml_http/wrapped", "FakePort");
 
     public static class Server extends TestServerBase {
-        
 
         protected void run() {
             Object implementor = new GreeterImpl();
@@ -77,7 +78,8 @@
 
     public void testBasicConnection() throws Exception {
 
-        XMLService service = new XMLService();
+        XMLService service = new XMLService(
+                this.getClass().getResource("/wsdl/hello_world_xml_wrapped.wsdl"), serviceName);
         assertNotNull(service);
 
         String response1 = new String("Hello ");
@@ -100,13 +102,12 @@
             throw (Exception) ex.getCause();
         }
     }
-    
+
     public void testAddPort() throws Exception {
 
         Service service = Service.create(serviceName);
-        service.addPort(fakePortName, 
-                        "http://cxf.apache.org/bindings/xformat",
-                        "http://localhost:9032/XMLService/XMLPort");
+        service.addPort(fakePortName, "http://cxf.apache.org/bindings/xformat",
+                "http://localhost:9032/XMLService/XMLPort");
         assertNotNull(service);
 
         String response1 = new String("Hello ");
@@ -129,16 +130,20 @@
             throw (Exception) ex.getCause();
         }
     }
-    
-// public void testXMLFault() throws Exception {
-//        XMLService service = new XMLService();
-//        assertNotNull(service);
-//        try {
-//            Greeter greeter = service.getPort(portName, Greeter.class);            
-//            greeter.pingMe();            
-//        } catch (UndeclaredThrowableException ex) {
-//            System.out.println(ex.getMessage());
-//            throw (Exception) ex.getCause();
-//        }
-//    }
+
+    public void testXMLFault() throws Exception {
+        XMLService service = new XMLService(
+                this.getClass().getResource("/wsdl/hello_world_xml_wrapped.wsdl"), serviceName);
+        assertNotNull(service);
+        try {
+            Greeter greeter = service.getPort(portName, Greeter.class);
+            greeter.pingMe();
+            fail("did not catch expected PingMeFault exception");
+        } catch (PingMeFault ex) {
+            assertEquals("minor value", 1, ex.getFaultInfo().getMinor());
+            assertEquals("major value", 2, ex.getFaultInfo().getMajor());
+        } catch (Exception ex) {
+            fail("did not catch expected PingMeFault exception");
+        }
+    }
 }



Mime
View raw message