cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r507355 - in /incubator/cxf/trunk/rt: bindings/soap/src/main/java/org/apache/cxf/binding/soap/ bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ core/src/main/java/org/apache/cxf/interceptor/ frontend/jaxws/src/main/java/...
Date Wed, 14 Feb 2007 02:07:16 GMT
Author: jliu
Date: Tue Feb 13 18:07:15 2007
New Revision: 507355

URL: http://svn.apache.org/viewvc?view=rev&rev=507355
Log:
CXF-249. Replace XMLStreamWriter with DOMStreamWriter when JAX-WS Soap handlers are registered
with the chain. The idea is to create a SAAJ DOM model up front if we know that we are going
to need a SAAJ tree in a later stage anyway, then let interceptors use a DOMXMLStreamWriter
to write content into this SAAJ DOM model directly. This can avoid the unnecessary parsing
time from Stax output stream to SAAJ model. 

Modified:
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPMessageContextImpl.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java?view=diff&rev=507355&r1=507354&r2=507355
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java
(original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java
Tue Feb 13 18:07:15 2007
@@ -54,6 +54,8 @@
 import org.apache.cxf.interceptor.AttachmentOutInterceptor;
 import org.apache.cxf.interceptor.BareOutInterceptor;
 import org.apache.cxf.interceptor.DocLiteralInInterceptor;
+import org.apache.cxf.interceptor.LoggingInInterceptor;
+import org.apache.cxf.interceptor.LoggingOutInterceptor;
 import org.apache.cxf.interceptor.StaxInInterceptor;
 import org.apache.cxf.interceptor.StaxOutInterceptor;
 import org.apache.cxf.interceptor.URIMappingInterceptor;
@@ -122,12 +124,16 @@
         sb.getInInterceptors().add(new StaxInInterceptor());        
         sb.getInInterceptors().add(new SoapHeaderInterceptor());
         
+        sb.getInInterceptors().add(new LoggingInInterceptor());
+      
         sb.getOutInterceptors().add(new SoapActionInterceptor());
         sb.getOutInterceptors().add(new AttachmentOutInterceptor());
         
         sb.getOutInterceptors().add(new StaxOutInterceptor());
         sb.getOutInterceptors().add(new SoapPreProtocolOutInterceptor());
         sb.getOutInterceptors().add(new SoapOutInterceptor());
+
+        sb.getOutInterceptors().add(new LoggingOutInterceptor());
 
         sb.getOutFaultInterceptors().add(new StaxOutInterceptor());
         sb.getOutFaultInterceptors().add(new SoapOutInterceptor());

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java?view=diff&rev=507355&r1=507354&r2=507355
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
Tue Feb 13 18:07:15 2007
@@ -59,7 +59,6 @@
         SoapVersion soapVersion = message.getVersion();
         try {            
             XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);
-            message.setContent(XMLStreamWriter.class, xtw);            
             xtw.setPrefix(soapVersion.getPrefix(), soapVersion.getNamespace());
             xtw.writeStartElement(soapVersion.getPrefix(), 
                                   soapVersion.getEnvelope().getLocalPart(),

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java?view=diff&rev=507355&r1=507354&r2=507355
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
Tue Feb 13 18:07:15 2007
@@ -79,8 +79,9 @@
         boolean result = message.getInterceptorChain().doIntercept(message);
         
         try {
-            if (writer != null) {
-                writer.close();
+            XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);
+            if (xtw != null) {
+                xtw.close();
             }
             
             if (!result && message.getContent(Exception.class) != null) {

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java?view=diff&rev=507355&r1=507354&r2=507355
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java
Tue Feb 13 18:07:15 2007
@@ -27,6 +27,7 @@
 import java.util.Set;
 
 import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.soap.SOAPBody;
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPMessage;
@@ -34,6 +35,7 @@
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
 import javax.xml.ws.Binding;
 import javax.xml.ws.handler.Handler;
 import javax.xml.ws.handler.MessageContext;
@@ -51,6 +53,7 @@
 import org.apache.cxf.jaxws.handler.AbstractProtocolHandlerInterceptor;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.Phase;
+import org.apache.cxf.staxutils.W3CDOMStreamWriter;
 
 public class SOAPHandlerInterceptor extends
         AbstractProtocolHandlerInterceptor<SoapMessage> implements
@@ -62,7 +65,7 @@
     public SOAPHandlerInterceptor(Binding binding) {
         super(binding);
         setPhase(Phase.PRE_PROTOCOL);
-        addBefore((new StaxOutInterceptor()).getId());
+        addAfter((new StaxOutInterceptor()).getId());
     }
 
     public Set<URI> getRoles() {
@@ -91,10 +94,16 @@
             return;
         }
         if (getInvoker(message).isOutbound()) {
-            OutputStream os = message.getContent(OutputStream.class);
-            CachedStream cs = new CachedStream();
-            message.setContent(OutputStream.class, cs);
-
+            try {
+                // Replace stax writer with DomStreamWriter
+                W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
+                message.setContent(XMLStreamWriter.class, writer);
+            } catch (ParserConfigurationException e) {
+                throw new SoapFault(new org.apache.cxf.common.i18n.Message(
+                    "SOAPHANDLERINTERCEPTOR_EXCEPTION", BUNDLE), e,
+                    message.getVersion().getSender());
+            }
+            
             message.getInterceptorChain().doInterceptInSubChain(message);
 
             super.handleMessage(message);
@@ -102,19 +111,13 @@
             try {
                 // Stream SOAPMessage back to output stream if necessary
                 SOAPMessage soapMessage = message.getContent(SOAPMessage.class);
+
                 if (soapMessage != null) {
+                    OutputStream os = message.getContent(OutputStream.class);
                     soapMessage.writeTo(os);
-                } else {
-                    cs.flush();
-                    AbstractCachedOutputStream csnew = (AbstractCachedOutputStream) message
-                            .getContent(OutputStream.class);
-                    AbstractCachedOutputStream.copyStream(csnew
-                            .getInputStream(), os, 64 * 1024);
-                    cs.close();
-                }
-
-                os.flush();
-                message.setContent(OutputStream.class, os);
+                    os.flush();
+                } 
+                
             } catch (IOException ioe) {
                 throw new SoapFault(new org.apache.cxf.common.i18n.Message(
                         "SOAPHANDLERINTERCEPTOR_EXCEPTION", BUNDLE), ioe,

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPMessageContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPMessageContextImpl.java?view=diff&rev=507355&r1=507354&r2=507355
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPMessageContextImpl.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPMessageContextImpl.java
Tue Feb 13 18:07:15 2007
@@ -21,8 +21,6 @@
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
-//import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.ResourceBundle;
@@ -34,26 +32,33 @@
 import javax.xml.soap.MessageFactory;
 import javax.xml.soap.MimeHeaders;
 import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPConstants;
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.SOAPPart;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.dom.DOMSource;
 import javax.xml.ws.handler.MessageContext;
 import javax.xml.ws.handler.soap.SOAPMessageContext;
 
+import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
+
 import org.apache.cxf.binding.soap.Soap11;
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.binding.soap.SoapVersion;
 import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.helpers.XMLUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.io.AbstractCachedOutputStream;
 import org.apache.cxf.jaxws.context.WrappedMessageContext;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.XMLMessage;
 import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.staxutils.W3CDOMStreamWriter;
 
 public class SOAPMessageContextImpl extends WrappedMessageContext implements SOAPMessageContext
{
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(SOAPMessageContextImpl.class);
@@ -74,14 +79,31 @@
                 Boolean outboundProperty = (Boolean)get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
 
                 if (outboundProperty) {
-                    MessageFactory factory = MessageFactory.newInstance();
-                    MimeHeaders mhs = null;
-                    //Safe to do this cast as SOAPHandlerInterceptor has explictly 
-                    //replaced OutputStream with AbstractCachedOutputStream.
-                    AbstractCachedOutputStream out = (AbstractCachedOutputStream)getWrappedMessage()
-                        .getContent(OutputStream.class);
-                    InputStream is = out.getInputStream();
-                    message = factory.createMessage(mhs, is);
+                    SoapVersion soapVersion = ((SoapMessage)getWrappedMessage()).getVersion();
+                    
+                    if (soapVersion == null) {
+                        soapVersion = Soap11.getInstance();
+                    }
+                    soapVersion = ((SoapMessage)getWrappedMessage()).getVersion();
+                 
+                    XMLStreamWriter xtw = getWrappedMessage().getContent(XMLStreamWriter.class);
+                    Document doc = ((W3CDOMStreamWriter)xtw).getDocument();
+                    
+                    XMLUtils.printDOM(doc);
+               
+                    MessageFactory factory = null;
+                    if (soapVersion.getVersion() == 1.1) {
+                        factory = MessageFactory.newInstance();
+                    } else {
+                        factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+                    }
+                    message = factory.createMessage();
+
+                    SOAPPart soapPart = message.getSOAPPart();
+                    DOMSource preppedMsgSrc = new DOMSource(doc.getDocumentElement());
+                    soapPart.setContent(preppedMsgSrc);
+                    message.saveChanges();
+
                 } else {
                     
                     if (getWrappedMessage().getContent(Object.class) != null) {

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java?view=diff&rev=507355&r1=507354&r2=507355
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java
Tue Feb 13 18:07:15 2007
@@ -40,6 +40,7 @@
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
 import javax.xml.ws.Binding;
 import javax.xml.ws.handler.Handler;
 import javax.xml.ws.handler.MessageContext;
@@ -82,71 +83,7 @@
     public void tearDown() {
     }
 
-    // SAAJ tree is created on demand. SAAJ wont be created without
-    // the calling of SOAPMessageContext.getMessage().
-    public void testNoCallToGetMessageOutBound() throws Exception {
-        List<Handler> list = new ArrayList<Handler>();
-        list.add(new SOAPHandler<SOAPMessageContext>() {
-            public boolean handleMessage(SOAPMessageContext smc) {
-                return true;
-            }
-
-            public boolean handleFault(SOAPMessageContext smc) {
-                return true;
-            }
-
-            public Set<QName> getHeaders() {
-                return null;
-            }
-
-            public void close(MessageContext messageContext) {
-            }
-        });
-        HandlerChainInvoker invoker = new HandlerChainInvoker(list);
-
-        IMocksControl control = createNiceControl();
-        Binding binding = control.createMock(Binding.class);
-        Exchange exchange = control.createMock(Exchange.class);
-        expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker).anyTimes();
-        SoapMessage message = new SoapMessage(new MessageImpl());
-        message.setExchange(exchange);        
-        // This is to set direction to outbound
-        expect(exchange.getOutMessage()).andReturn(message).anyTimes();
-        CachedStream originalEmptyOs = new CachedStream();
-        message.setContent(OutputStream.class, originalEmptyOs);
-
-        InterceptorChain chain = new PhaseInterceptorChain((new PhaseManagerImpl()).getOutPhases());
-        // This is to simulate interceptors followed by SOAPHandlerInterceptor
-        // write outputStream
-        chain.add(new AbstractProtocolHandlerInterceptor<SoapMessage>(binding) {
-            public void handleMessage(SoapMessage message) throws Fault {
-                try {
-                    CachedStream os = prepareOutputStreamFromResource("resources/greetMeRpcLitResp.xml");
-                    message.setContent(OutputStream.class, os);
-                } catch (Exception e) {
-                    // do nothing
-                }
-            }
-
-        });
-        message.setInterceptorChain(chain);
-        control.replay();
-
-        SOAPHandlerInterceptor li = new SOAPHandlerInterceptor(binding);
-        li.handleMessage(message);
-        control.verify();
-
-        // Verify outputStream
-        CachedStream expectedOs = prepareOutputStreamFromResource("resources/greetMeRpcLitResp.xml");
-        assertTrue("The content of outputStream should remain unchanged", compareInputStream(expectedOs
-            .getInputStream(), originalEmptyOs.getInputStream()));
-        // Verify SOAPMessage
-        SOAPMessage resultedMessage = message.getContent(SOAPMessage.class);
-        assertNull(resultedMessage);
-    }
-
-    // SAAJ tree is created on if SOAPMessageContext.getMessage() is
-    // called. Any changes to SOAPMessage should be streamed back to
+    // SAAJ tree is created from DOMXMLStreamWriter. Any changes to SOAPMessage should be
streamed back to
     // outputStream
     public void testChangeSOAPBodyOutBound() throws Exception {
         List<Handler> list = new ArrayList<Handler>();
@@ -190,14 +127,20 @@
         message.setContent(OutputStream.class, originalEmptyOs);
 
         InterceptorChain chain = new PhaseInterceptorChain((new PhaseManagerImpl()).getOutPhases());
-        // This is to simulate interceptors followed by SOAPHandlerInterceptor
-        // write outputStream
+        //Interceptors after SOAPHandlerInterceptor DOMXMLStreamWriter to write
         chain.add(new AbstractProtocolHandlerInterceptor<SoapMessage>(binding) {
             public void handleMessage(SoapMessage message) throws Fault {
                 try {
-                    CachedStream os = prepareOutputStreamFromResource(
-                        "resources/greetMeRpcLitRespChanged.xml");
-                    message.setContent(OutputStream.class, os);
+                    XMLStreamWriter writer = message.getContent(XMLStreamWriter.class); 
+                    SoapVersion soapVersion = Soap11.getInstance();
+                    writer.setPrefix(soapVersion.getPrefix(), soapVersion.getNamespace());
+                    writer.writeStartElement(soapVersion.getPrefix(), 
+                                          soapVersion.getEnvelope().getLocalPart(),
+                                          soapVersion.getNamespace());
+                    writer.writeNamespace(soapVersion.getPrefix(), soapVersion.getNamespace());
+                    writer.writeEndElement();
+                    
+                    writer.flush();
                 } catch (Exception e) {
                     // do nothing
                 }
@@ -360,14 +303,24 @@
         message.setContent(OutputStream.class, originalEmptyOs);
 
         InterceptorChain chain = new PhaseInterceptorChain((new PhaseManagerImpl()).getOutPhases());
-        // This is to simulate interceptors followed by SOAPHandlerInterceptor
-        // write outputStream
+        //Interceptors after SOAPHandlerInterceptor DOMXMLStreamWriter to write
         chain.add(new AbstractProtocolHandlerInterceptor<SoapMessage>(binding) {
             public void handleMessage(SoapMessage message) throws Fault {
                 try {
-                    CachedStream os = prepareOutputStreamFromResource(
-                        "resources/greetMeRpcLitRespWithHeader.xml");
-                    message.setContent(OutputStream.class, os);
+                    XMLStreamWriter writer = message.getContent(XMLStreamWriter.class); 
+                    SoapVersion soapVersion = Soap11.getInstance();
+                    writer.setPrefix(soapVersion.getPrefix(), soapVersion.getNamespace());
+                    writer.writeStartElement(soapVersion.getPrefix(), 
+                                          soapVersion.getEnvelope().getLocalPart(),
+                                          soapVersion.getNamespace());
+                    writer.writeNamespace(soapVersion.getPrefix(), soapVersion.getNamespace());
+                    
+                    Element headerElement = preparemSOAPHeader();
+                    StaxUtils.writeElement(headerElement, writer, true, false);
+                    
+                    writer.writeEndElement();
+                    
+                    writer.flush();
                 } catch (Exception e) {
                     // do nothing
                 }



Mime
View raw message