You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by jl...@apache.org on 2007/06/24 20:39:24 UTC

svn commit: r550274 - in /incubator/cxf/trunk: rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/ rt/frontend/ja...

Author: jliu
Date: Sun Jun 24 11:39:23 2007
New Revision: 550274

URL: http://svn.apache.org/viewvc?view=rev&rev=550274
Log:
CXF-732: make logical/soap handler's getPayload/getMessage works with various combinations of input format and message mode using Dispatch. Note, there is still some work to do for XML binding.

Added:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/DispatchSOAPHandlerInterceptor.java   (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/dispatch/Server.java   (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/DispatchHandlerInvocationTest.java   (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/resources/
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/resources/GreetMeDocLiteralReq.xml   (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/resources/GreetMeDocLiteralReqPayload.xml   (with props)
Modified:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/DispatchLogicalHandlerOutInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.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/main/java/org/apache/cxf/jaxws/interceptors/DispatchInInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainInvokerTest.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/LogicalMessageImplTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/dispatch/DispatchXMLClientServerTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java
    incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_xml_http/wrapped/GreeterImpl.java

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java?view=diff&rev=550274&r1=550273&r2=550274
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java Sun Jun 24 11:39:23 2007
@@ -61,6 +61,7 @@
 import org.apache.cxf.interceptor.MessageSenderInterceptor;
 import org.apache.cxf.jaxws.handler.logical.DispatchLogicalHandlerOutInterceptor;
 import org.apache.cxf.jaxws.handler.logical.LogicalHandlerInInterceptor;
+import org.apache.cxf.jaxws.handler.soap.DispatchSOAPHandlerInterceptor;
 import org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor;
 import org.apache.cxf.jaxws.interceptors.DispatchInInterceptor;
 import org.apache.cxf.jaxws.interceptors.DispatchOutInterceptor;
@@ -237,7 +238,7 @@
         if (endpoint instanceof JaxWsEndpointImpl) {
             Binding jaxwsBinding = ((JaxWsEndpointImpl)endpoint).getJaxwsBinding();
             if (endpoint.getBinding() instanceof SoapBinding) {
-                chain.add(new SOAPHandlerInterceptor(jaxwsBinding));
+                chain.add(new DispatchSOAPHandlerInterceptor(jaxwsBinding));
             } else {
                 // TODO: what for non soap bindings?
             }       

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/DispatchLogicalHandlerOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/DispatchLogicalHandlerOutInterceptor.java?view=diff&rev=550274&r1=550273&r2=550274
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/DispatchLogicalHandlerOutInterceptor.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/DispatchLogicalHandlerOutInterceptor.java Sun Jun 24 11:39:23 2007
@@ -34,8 +34,6 @@
 
 public class DispatchLogicalHandlerOutInterceptor<T extends Message> 
     extends AbstractJAXWSHandlerInterceptor<T> {
-    
-    public static final String ORIGINAL_WRITER = "original_writer";
      
     public DispatchLogicalHandlerOutInterceptor(Binding binding) {
         super(binding, Phase.PRE_MARSHAL);
@@ -53,29 +51,23 @@
         
         ContextPropertiesMapping.mapCxf2Jaxws(message.getExchange(), lctx, requestor);          
         
-        if (!invoker.invokeLogicalHandlers(requestor, lctx)) {
-            if (requestor) {
-                // client side - abort
-                message.getInterceptorChain().abort();
-                Endpoint e = message.getExchange().get(Endpoint.class);
-                Message responseMsg = e.getBinding().createMessage();            
+        if (!invoker.invokeLogicalHandlers(requestor, lctx) && requestor) {
+            // client side - abort
+            message.getInterceptorChain().abort();
+            Endpoint e = message.getExchange().get(Endpoint.class);
+            Message responseMsg = e.getBinding().createMessage();
+
+            MessageObserver observer = (MessageObserver)message.getExchange().get(MessageObserver.class);
+            if (observer != null) {
+                //client side outbound, the request message becomes the response message
+                responseMsg.setContent(XMLStreamReader.class, message.getContent(XMLStreamReader.class));
 
-                MessageObserver observer = (MessageObserver)message.getExchange()
-                            .get(MessageObserver.class);
-                if (observer != null) {
-                    //client side outbound, the request message becomes the response message
-                    responseMsg.setContent(XMLStreamReader.class, message
-                        .getContent(XMLStreamReader.class));                        
-                    
-                    message.getExchange().setInMessage(responseMsg);
-                    responseMsg.put(PhaseInterceptorChain.STARTING_AT_INTERCEPTOR_ID,
-                                    LogicalHandlerInInterceptor.class.getName());
-                    observer.onMessage(responseMsg);
-                }
-            } else {
-                // server side - abort
-                //System.out.println("Logical handler server side aborting");
+                message.getExchange().setInMessage(responseMsg);
+                responseMsg.put(PhaseInterceptorChain.STARTING_AT_INTERCEPTOR_ID,
+                                LogicalHandlerInInterceptor.class.getName());
+                observer.onMessage(responseMsg);
             }
+
         }
     }
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java?view=diff&rev=550274&r1=550273&r2=550274
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java Sun Jun 24 11:39:23 2007
@@ -20,20 +20,39 @@
 package org.apache.cxf.jaxws.handler.logical;
 
 
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.activation.DataSource;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.soap.MessageFactory;
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPMessage;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
 import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
 import javax.xml.ws.LogicalMessage;
+import javax.xml.ws.Service;
 import javax.xml.ws.WebServiceException;
 
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import org.apache.cxf.binding.soap.SoapMessage;
+import org.apache.cxf.helpers.XMLUtils;
+import org.apache.cxf.io.CachedOutputStream;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.XMLMessage;
 import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.cxf.staxutils.W3CDOMStreamWriter;
+import org.apache.cxf.wsdl.WSDLConstants;
 
 
 public class LogicalMessageImpl implements LogicalMessage {
@@ -45,58 +64,110 @@
     }
 
     public Source getPayload() {
-        Source source = msgContext.getWrappedMessage().getContent(Source.class);
-        if (source == null) {
-            //need to convert
-            SOAPMessage msg = msgContext.getWrappedMessage().getContent(SOAPMessage.class);
-            XMLStreamReader reader = null;
-            if (msg != null) {
-                try {
-                    source = new DOMSource(msg.getSOAPBody().getFirstChild());
-                    reader = StaxUtils.createXMLStreamReader(source);
-                } catch (SOAPException e) {
-                    //ignore
+        Source source = null;
+
+        Service.Mode m = msgContext.getWrappedMessage().getExchange().get(Service.Mode.class);
+        Message message = msgContext.getWrappedMessage();
+        
+        //Have to handle Dispatch differently
+        if (m != null) {
+            //Dispatch case
+            Object obj = message.getContent(Object.class);
+            if (message instanceof SoapMessage) {
+                SOAPMessage soapMessage = (SOAPMessage)message.getContent(SOAPMessage.class);
+               
+                if (obj instanceof SOAPMessage || soapMessage != null) {
+                    try {
+                        if (!(obj instanceof SOAPMessage)) {
+                            obj = soapMessage;
+                        }
+                        source = new DOMSource(((SOAPMessage)obj).getSOAPBody().getFirstChild());
+                    } catch (SOAPException e) {
+                        // ignore
+                    }                  
+                } else if (obj instanceof Source) {
+                    try {
+                        CachedOutputStream cos = new CachedOutputStream();
+
+                        Transformer transformer = XMLUtils.newTransformer();
+                        transformer.transform((Source)obj, new StreamResult(cos));
+                        SOAPMessage msg = initSOAPMessage(cos.getInputStream());
+                        source = new DOMSource(((SOAPMessage)msg).getSOAPBody().getFirstChild());
+                    } catch (Exception e) {
+                        // ignore
+                    }                      
                 }
+            } else if (message instanceof XMLMessage) {
+                if (obj instanceof Source) {
+                    source = (Source)obj;
+                } else if (obj instanceof DataSource) {
+                    try {
+                        source = new StreamSource(((DataSource)obj).getInputStream());
+                    } catch (IOException e) {
+                        // ignore
+                    }
+                } else {
+                    //JAXBElement
+                    W3CDOMStreamWriter xmlWriter = (W3CDOMStreamWriter)message
+                        .getContent(XMLStreamWriter.class);
+                    source = new DOMSource(xmlWriter.getDocument().getDocumentElement());               
+                }              
             }
-
+        } else {
+            source = message.getContent(Source.class);
             if (source == null) {
+                // need to convert
+                SOAPMessage msg = message.getContent(SOAPMessage.class);
+                XMLStreamReader reader = null;
+                if (msg != null) {
+                    try {
+                        source = new DOMSource(msg.getSOAPBody().getFirstChild());
+                        reader = StaxUtils.createXMLStreamReader(source);
+                    } catch (SOAPException e) {
+                        // ignore
+                    }
+                }
+
+                if (source == null) {
+                    try {
+                        W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
+                        reader = message.getContent(XMLStreamReader.class);
+                        StaxUtils.copy(reader, writer);
+                        source = new DOMSource(writer.getDocument().getDocumentElement());
+                        reader = StaxUtils.createXMLStreamReader(writer.getDocument());
+                    } catch (ParserConfigurationException e) {
+                        throw new WebServiceException(e);
+                    } catch (XMLStreamException e) {
+                        throw new WebServiceException(e);
+                    }
+                }
+                message.setContent(XMLStreamReader.class, reader);
+                message.setContent(Source.class, source);
+            } else if (!(source instanceof DOMSource)) {
+                W3CDOMStreamWriter writer;
                 try {
-                    W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
-                    reader = msgContext.getWrappedMessage().getContent(XMLStreamReader.class);
-                    StaxUtils.copy(reader, writer);
-                    source = new DOMSource(writer.getDocument().getDocumentElement());
-                    reader = StaxUtils.createXMLStreamReader(writer.getDocument());
+                    writer = new W3CDOMStreamWriter();
                 } catch (ParserConfigurationException e) {
                     throw new WebServiceException(e);
+                }
+                XMLStreamReader reader = message.getContent(XMLStreamReader.class);
+                if (reader == null) {
+                    reader = StaxUtils.createXMLStreamReader(source);
+                }
+                try {
+                    StaxUtils.copy(reader, writer);
                 } catch (XMLStreamException e) {
                     throw new WebServiceException(e);
                 }
+
+                source = new DOMSource(writer.getDocument().getDocumentElement());
+
+                reader = StaxUtils.createXMLStreamReader(writer.getDocument());
+                message.setContent(XMLStreamReader.class, reader);
+                message.setContent(Source.class, source);
             }
-            msgContext.getWrappedMessage().setContent(XMLStreamReader.class, reader);
-            msgContext.getWrappedMessage().setContent(Source.class, source);
-        } else if (!(source instanceof DOMSource)) {
-            W3CDOMStreamWriter writer;
-            try {
-                writer = new W3CDOMStreamWriter();
-            } catch (ParserConfigurationException e) {
-                throw new WebServiceException(e);
-            }
-            XMLStreamReader reader = msgContext.getWrappedMessage().getContent(XMLStreamReader.class);
-            if (reader == null) {
-                reader = StaxUtils.createXMLStreamReader(source);
-            }
-            try {
-                StaxUtils.copy(reader, writer);
-            } catch (XMLStreamException e) {
-                throw new WebServiceException(e);
-            }
-            
-            source = new DOMSource(writer.getDocument().getDocumentElement());
-            
-            reader = StaxUtils.createXMLStreamReader(writer.getDocument());
-            msgContext.getWrappedMessage().setContent(XMLStreamReader.class, reader);
-            msgContext.getWrappedMessage().setContent(Source.class, source);
         }
+
         return source;
     }
 
@@ -129,4 +200,30 @@
     }
 
    
+    public void write(Source source, Node n) {
+        try {
+            if (source instanceof DOMSource && ((DOMSource)source).getNode() == null) {
+                return;
+            }
+
+            XMLStreamWriter writer = new W3CDOMStreamWriter((Element)n);
+            XMLStreamReader reader = StaxUtils.createXMLStreamReader(source);
+            StaxUtils.copy(reader, writer);
+            reader.close();
+        } catch (XMLStreamException e) {
+            // throw new Fault(new Message("COULD_NOT_READ_XML_STREAM",
+            // LOG), e);
+        }
+    }      
+    
+    private SOAPMessage initSOAPMessage(InputStream is) throws SOAPException, IOException {
+        SOAPMessage msg = MessageFactory.newInstance().createMessage(null, is);
+        msg.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true");
+        msg.getSOAPPart().getEnvelope().addNamespaceDeclaration(WSDLConstants.NP_SCHEMA_XSD,
+                                                                WSDLConstants.NU_SCHEMA_XSD);
+        msg.getSOAPPart().getEnvelope().addNamespaceDeclaration(WSDLConstants.NP_SCHEMA_XSI,
+                                                                WSDLConstants.NU_SCHEMA_XSI);
+
+        return msg;
+    }  
 }

Added: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/DispatchSOAPHandlerInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/DispatchSOAPHandlerInterceptor.java?view=auto&rev=550274
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/DispatchSOAPHandlerInterceptor.java (added)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/DispatchSOAPHandlerInterceptor.java Sun Jun 24 11:39:23 2007
@@ -0,0 +1,137 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxws.handler.soap;
+
+import java.net.URI;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.Binding;
+import javax.xml.ws.handler.Handler;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPHandler;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+import org.apache.cxf.binding.soap.SoapMessage;
+import org.apache.cxf.binding.soap.interceptor.SoapInterceptor;
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.jaxws.handler.AbstractProtocolHandlerInterceptor;
+import org.apache.cxf.jaxws.handler.HandlerChainInvoker;
+import org.apache.cxf.jaxws.support.ContextPropertiesMapping;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.phase.PhaseInterceptorChain;
+import org.apache.cxf.transport.MessageObserver;
+
+public class DispatchSOAPHandlerInterceptor extends
+        AbstractProtocolHandlerInterceptor<SoapMessage> implements
+        SoapInterceptor {
+
+    public DispatchSOAPHandlerInterceptor(Binding binding) {
+        super(binding, Phase.USER_PROTOCOL);
+    }
+
+    public Set<URI> getRoles() {
+        return new HashSet<URI>();
+    }
+
+    public Set<QName> getUnderstoodHeaders() {
+        Set<QName> understood = new HashSet<QName>();
+        for (Handler h : getBinding().getHandlerChain()) {
+            if (h instanceof SOAPHandler) {
+                Set<QName> headers = CastUtils.cast(((SOAPHandler) h).getHeaders());
+                if (headers != null) {
+                    understood.addAll(headers);
+                }
+            }
+        }
+        return understood;
+    }
+
+    public void handleMessage(SoapMessage message) {
+        if (getInvoker(message).getProtocolHandlers().isEmpty()) {
+            return;
+        }
+
+        MessageContext context = createProtocolMessageContext(message);
+        HandlerChainInvoker invoker = getInvoker(message);
+        invoker.setProtocolMessageContext(context);
+        
+        if (!invoker.invokeProtocolHandlers(isRequestor(message), context)) {
+            handleAbort(message, context);
+        } 
+        
+        // If this is the outbound and end of MEP, call MEP completion
+        if (isRequestor(message) && invoker.getLogicalHandlers().isEmpty() 
+            && !isOutbound(message) && isMEPComlete(message)) {
+            onCompletion(message);
+        } else if (isOutbound(message) && isMEPComlete(message)) {
+            onCompletion(message);
+        }
+    }
+    
+    private void handleAbort(SoapMessage message, MessageContext context) {
+        if (isRequestor(message)) {
+            // client side outbound
+            if (getInvoker(message).isOutbound()) {
+                message.getInterceptorChain().abort();
+                Endpoint e = message.getExchange().get(Endpoint.class);
+                Message responseMsg = e.getBinding().createMessage();
+
+                MessageObserver observer = (MessageObserver)message.getExchange().get(MessageObserver.class);
+                if (observer != null) {
+                    // the request message becomes the response message
+                    message.getExchange().setInMessage(responseMsg);
+                    SOAPMessage soapMessage = ((SOAPMessageContext)context).getMessage();
+
+                    if (soapMessage != null) {
+                        responseMsg.setContent(SOAPMessage.class, soapMessage);
+                    }
+                    responseMsg.put(PhaseInterceptorChain.STARTING_AT_INTERCEPTOR_ID,
+                                    SOAPHandlerInterceptor.class.getName());
+                    observer.onMessage(responseMsg);
+                }
+                
+                //We dont call onCompletion here, as onCompletion will be called by inbound 
+                //LogicalHandlerInterceptor
+            } else {
+                // client side inbound - Normal handler message processing
+                // stops, but the inbound interceptor chain still continues, dispatch the message
+                //By onCompletion here, we can skip following Logical handlers 
+                onCompletion(message);
+                //System.out.println("SOAP Handler handleMessage returns false on client inbound, aborting");
+            }
+        }
+    }
+    
+    @Override
+    protected MessageContext createProtocolMessageContext(SoapMessage message) {
+        SOAPMessageContextImpl sm = new SOAPMessageContextImpl(message);
+        boolean requestor = isRequestor(message);
+        ContextPropertiesMapping.mapCxf2Jaxws(message.getExchange(), sm, requestor);
+        return sm;
+    }
+
+    public void handleFault(SoapMessage message) {
+    }
+}

Propchange: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/DispatchSOAPHandlerInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/DispatchSOAPHandlerInterceptor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

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=550274&r1=550273&r2=550274
==============================================================================
--- 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 Sun Jun 24 11:39:23 2007
@@ -20,6 +20,8 @@
 package org.apache.cxf.jaxws.handler.soap;
 
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -27,13 +29,18 @@
 import java.util.Set;
 
 import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
 import javax.xml.namespace.QName;
+import javax.xml.soap.MessageFactory;
 import javax.xml.soap.SOAPBody;
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPHeader;
 import javax.xml.soap.SOAPHeaderElement;
 import javax.xml.soap.SOAPMessage;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.stream.StreamResult;
 import javax.xml.ws.WebServiceException;
 import javax.xml.ws.handler.MessageContext;
 import javax.xml.ws.handler.soap.SOAPMessageContext;
@@ -41,9 +48,12 @@
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor;
 import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.helpers.XMLUtils;
+import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.jaxws.context.WrappedMessageContext;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.XMLMessage;
+import org.apache.cxf.wsdl.WSDLConstants;
 
 public class SOAPMessageContextImpl extends WrappedMessageContext implements SOAPMessageContext {
     private static final SAAJInInterceptor SAAJ_IN = new SAAJInInterceptor();
@@ -80,6 +90,26 @@
                     SAAJ_IN.handleMessage(getWrappedSoapMessage());
                     message = getWrappedSoapMessage().getContent(SOAPMessage.class);
                 }
+            } else {
+                if (getWrappedMessage().getContent(Object.class) != null) {
+                    //The Dispatch/Provider case:
+                    Object obj = getWrappedMessage().getContent(Object.class);
+                    if (obj instanceof SOAPMessage) {
+                        message = (SOAPMessage)obj;
+                    } else if (obj instanceof Source) {
+                        try {
+                            CachedOutputStream cos = new CachedOutputStream();
+
+                            Transformer transformer = XMLUtils.newTransformer();
+                            transformer.transform((Source)obj, new StreamResult(cos));
+                            message = initSOAPMessage(cos.getInputStream());
+                        } catch (Exception e) {
+                            // ignore
+                        } 
+                    } else if (obj instanceof JAXBElement) {
+                        // what to do
+                    }
+                }
             }
            
         }
@@ -123,4 +153,15 @@
     private SoapMessage getWrappedSoapMessage() {
         return (SoapMessage)getWrappedMessage();
     }
+    
+    private SOAPMessage initSOAPMessage(InputStream is) throws SOAPException, IOException {
+        SOAPMessage msg = MessageFactory.newInstance().createMessage(null, is);
+        msg.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true");
+        msg.getSOAPPart().getEnvelope().addNamespaceDeclaration(WSDLConstants.NP_SCHEMA_XSD,
+                                                                WSDLConstants.NU_SCHEMA_XSD);
+        msg.getSOAPPart().getEnvelope().addNamespaceDeclaration(WSDLConstants.NP_SCHEMA_XSI,
+                                                                WSDLConstants.NU_SCHEMA_XSI);
+
+        return msg;
+    }     
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInInterceptor.java?view=diff&rev=550274&r1=550273&r2=550274
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInInterceptor.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInInterceptor.java Sun Jun 24 11:39:23 2007
@@ -95,6 +95,7 @@
                     }
                 }
                 message.setContent(Object.class, obj);
+                message.setContent(SOAPMessage.class, soapMessage);               
             } else if (message instanceof XMLMessage) {
                 new StaxInInterceptor().handleMessage(message);
                 

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutInterceptor.java?view=diff&rev=550274&r1=550273&r2=550274
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutInterceptor.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchOutInterceptor.java Sun Jun 24 11:39:23 2007
@@ -25,6 +25,7 @@
 import java.util.logging.Logger;
 
 import javax.activation.DataSource;
+import javax.xml.bind.JAXBElement;
 import javax.xml.soap.MessageFactory;
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPMessage;
@@ -72,54 +73,62 @@
 
         try {
             if (message instanceof SoapMessage) {
-                if (m == Service.Mode.MESSAGE) {
-                    if (obj instanceof DataSource) {
-                        throw new RuntimeException(obj.getClass()
-                                                   + " is not valid in Message mode for SOAP/HTTP");
-                    }
-                } else if (m == Service.Mode.PAYLOAD) {
+                if (m == Service.Mode.PAYLOAD) {
                     if (obj instanceof SOAPMessage || obj instanceof DataSource) {
                         throw new RuntimeException(obj.getClass()
-                                                   + " is not valid in PAYLOAD mode with SOAP/HTTP");
+                                                   + " is not valid in PAYLOAD mode with SOAP/HTTP binding");
+                    } else {
+                        // Input is Source or JAXB in payload mode, need to wrap it
+                        // with a SOAPMessage
+                        SOAPMessage msg = initSOAPMessage();
+                        DataWriter<Node> dataWriter = getDataWriter(message, service, Node.class);
+                        dataWriter.write(obj, msg.getSOAPBody());
+                        message.setContent(Object.class, msg);
+                        message.setContent(SOAPMessage.class, msg);
+                    }
+                } else {
+                    if (obj instanceof DataSource) {
+                        throw new RuntimeException(
+                            "DataSource is not valid in MESSAGE mode with SOAP/HTTP binding");
+                    } else if (obj instanceof JAXBElement) {
+                        // REVISIT: Not sure if this is a valid combination
+                    } else {
+                        //Input is Source or SOAPMessage, no conversion needed
                     }
-                    
-                    //Convert Source or JAXB element to SOAPMessage
-                    SOAPMessage msg = initSOAPMessage();
-                    DataWriter<Node> dataWriter = getDataWriter(message, service, Node.class);
-                    dataWriter.write(obj, msg.getSOAPBody());
-                    message.setContent(Object.class, msg);
-                    message.setContent(SOAPMessage.class, msg);   
-                    msg.writeTo(System.out);
-                    //msg.writeTo(os);
                 }
             } else if (message instanceof XMLMessage) {
-                if (m == Service.Mode.MESSAGE
-                    && obj instanceof SOAPMessage) {
-                    throw new RuntimeException("SOAPMessage is not valid in MESSAGE mode with XML/HTTP");
-                } else if (m == Service.Mode.PAYLOAD
-                           && (obj instanceof SOAPMessage
-                               || obj instanceof DataSource)) {
-                    throw new RuntimeException(obj.getClass()
-                                               + " is not valid in PAYLOAD mode with XML/HTTP");
-                }                
-
-                DataWriter<XMLStreamWriter> dataWriter = getDataWriter(message, service,
-                                                                       XMLStreamWriter.class);
-                XMLStreamWriter xmlWriter = message.getContent(XMLStreamWriter.class);
-                if (xmlWriter == null) {
-                    xmlWriter = StaxUtils.createXMLStreamWriter(os, "UTF-8");
+                if (obj instanceof SOAPMessage) {
+                    throw new RuntimeException("SOAPMessage is not valid with XML/HTTP binding");
+                }
+
+                if (m == Service.Mode.PAYLOAD && obj instanceof DataSource) {
+                    throw new RuntimeException(
+                        "DataSource is not valid in PAYLOAD mode with XML/HTTP binding");
                 }
-                dataWriter.write(obj, xmlWriter);
-                message.setContent(XMLStreamWriter.class, xmlWriter);
-                // xmlWriter.flush();
 
+                if (obj instanceof Source || obj instanceof DataSource) {
+                    // no conversion needed
+                } else {
+                    //JAXB element
+                    DataWriter<XMLStreamWriter> dataWriter = getDataWriter(message, service,
+                                                                           XMLStreamWriter.class);
+                    XMLStreamWriter xmlWriter = message.getContent(XMLStreamWriter.class);
+                    //W3CDOMStreamWriter xmlWriter = new W3CDOMStreamWriter();
+                    
+                    if (xmlWriter == null) { 
+                        xmlWriter = StaxUtils.createXMLStreamWriter(os, "UTF-8"); 
+                    }
+                     
+                    dataWriter.write(obj, xmlWriter);
+                    message.setContent(XMLStreamWriter.class, xmlWriter);
+
+                }
             }
-            // Finish the message processing, do flush
-            // os.flush();
-        } catch (Exception ex) {
+        } catch (Exception e) {
             throw new Fault(new org.apache.cxf.common.i18n.Message("EXCEPTION_WRITING_OBJECT", LOG));
+
         }
-        
+
         message.getInterceptorChain().add(ending);
     }
     
@@ -147,11 +156,8 @@
             } catch (Exception ex) {
                 throw new Fault(new org.apache.cxf.common.i18n.Message("EXCEPTION_WRITING_OBJECT", LOG));
             }
-
-        }
-      
+        }      
     }
-
         
     private SOAPMessage initSOAPMessage() throws SOAPException {
         SOAPMessage msg = MessageFactory.newInstance().createMessage();

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainInvokerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainInvokerTest.java?view=diff&rev=550274&r1=550273&r2=550274
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainInvokerTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainInvokerTest.java Sun Jun 24 11:39:23 2007
@@ -46,6 +46,8 @@
 import org.apache.cxf.jaxws.context.WrappedMessageContext;
 import org.apache.cxf.jaxws.handler.logical.LogicalMessageContextImpl;
 import org.apache.cxf.jaxws.handler.soap.SOAPMessageContextImpl;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
 import org.junit.Assert;
@@ -81,6 +83,8 @@
         invoker = new HandlerChainInvoker(handlers);
         
         message = new MessageImpl();
+        Exchange e = new ExchangeImpl();
+        message.setExchange(e);
         lmc = new LogicalMessageContextImpl(message);
         pmc = new WrappedMessageContext(message);      
 /*        

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/LogicalMessageImplTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/LogicalMessageImplTest.java?view=diff&rev=550274&r1=550273&r2=550274
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/LogicalMessageImplTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/LogicalMessageImplTest.java Sun Jun 24 11:39:23 2007
@@ -27,6 +27,8 @@
 
 import org.apache.cxf.jaxws.handler.logical.LogicalMessageContextImpl;
 import org.apache.cxf.jaxws.handler.logical.LogicalMessageImpl;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
 import org.apache.handlers.types.AddNumbers;
@@ -53,6 +55,8 @@
         //using Dispatch
         JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class);
         Message message = new MessageImpl();
+        Exchange e = new ExchangeImpl();
+        message.setExchange(e);
         LogicalMessageContextImpl lmci = new LogicalMessageContextImpl(message);
 
         JAXBElement<AddNumbers> el = new ObjectFactory().createAddNumbers(req);

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/dispatch/DispatchXMLClientServerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/dispatch/DispatchXMLClientServerTest.java?view=diff&rev=550274&r1=550273&r2=550274
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/dispatch/DispatchXMLClientServerTest.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/dispatch/DispatchXMLClientServerTest.java Sun Jun 24 11:39:23 2007
@@ -28,7 +28,6 @@
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.ws.Dispatch;
-import javax.xml.ws.Endpoint;
 import javax.xml.ws.Service;
 import javax.xml.ws.WebServiceException;
 
@@ -37,8 +36,6 @@
 
 import org.apache.cxf.helpers.XMLUtils;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
-import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
-import org.apache.hello_world_xml_http.wrapped.GreeterImpl;
 import org.apache.hello_world_xml_http.wrapped.XMLService;
 import org.apache.hello_world_xml_http.wrapped.types.GreetMe;
 import org.apache.hello_world_xml_http.wrapped.types.GreetMeResponse;
@@ -51,28 +48,6 @@
                                                 "XMLService");
     private final QName portName = new QName("http://apache.org/hello_world_xml_http/wrapped", 
                                              "XMLDispatchPort");
-
-    public static class Server extends AbstractBusTestServerBase {        
-
-        protected void run() {
-            Object implementor = new GreeterImpl();
-            String address = "http://localhost:9007/XMLService/XMLDispatchPort";
-            Endpoint.publish(address, implementor);
-
-        }
-
-        public static void main(String[] args) {
-            try {
-                Server s = new Server();
-                s.start();
-            } catch (Exception ex) {
-                ex.printStackTrace();
-                System.exit(-1);
-            } finally {
-                System.out.println("done!");
-            }
-        }
-    }
 
     @BeforeClass
     public static void startServers() throws Exception {

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/dispatch/Server.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/dispatch/Server.java?view=auto&rev=550274
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/dispatch/Server.java (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/dispatch/Server.java Sun Jun 24 11:39:23 2007
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.dispatch;
+
+
+import javax.xml.ws.Endpoint;
+
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.apache.hello_world_xml_http.wrapped.GreeterImpl;
+
+
+public class Server extends AbstractBusTestServerBase {        
+
+    protected void run() {
+        Object implementor = new GreeterImpl();
+        String address = "http://localhost:9007/XMLService/XMLDispatchPort";
+        Endpoint.publish(address, implementor);
+    }
+
+    public static void main(String[] args) {
+        try {
+            Server s = new Server();
+            s.start();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            System.exit(-1);
+        } finally {
+            System.out.println("done!");
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/dispatch/Server.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/dispatch/Server.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/DispatchHandlerInvocationTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/DispatchHandlerInvocationTest.java?view=auto&rev=550274
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/DispatchHandlerInvocationTest.java (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/DispatchHandlerInvocationTest.java Sun Jun 24 11:39:23 2007
@@ -0,0 +1,256 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.handlers;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.List;
+import java.util.Set;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.namespace.QName;
+
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.LogicalMessage;
+import javax.xml.ws.Service;
+import javax.xml.ws.Service.Mode;
+import javax.xml.ws.handler.Handler;
+import javax.xml.ws.handler.LogicalHandler;
+import javax.xml.ws.handler.LogicalMessageContext;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPHandler;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+import javax.xml.ws.soap.SOAPFaultException;
+
+
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.handlers.AddNumbersService;
+import org.apache.handlers.types.AddNumbersResponse;
+import org.apache.handlers.types.ObjectFactory;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+public class DispatchHandlerInvocationTest extends AbstractBusClientServerTestBase {
+
+    static QName serviceName = new QName("http://apache.org/handlers", "AddNumbersService");
+    static QName portName = new QName("http://apache.org/handlers", "AddNumbersPort");
+   
+    @BeforeClass
+    public static void startServers() throws Exception {
+        assertTrue("server did not launch correctly", launchServer(HandlerServer.class));
+    }
+    
+    @Test
+    public void testInvokeWithJAXBPayloadMode() throws Exception {
+        URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
+        assertNotNull(wsdl);
+
+        AddNumbersService service = new AddNumbersService(wsdl, serviceName);
+        assertNotNull(service);
+
+        JAXBContext jc = JAXBContext.newInstance("org.apache.handlers.types");
+        Dispatch<Object> disp = service.createDispatch(portName, jc, Service.Mode.PAYLOAD);
+ 
+        TestHandler handler = new TestHandler();
+        TestSOAPHandler soapHandler = new TestSOAPHandler();
+        addHandlersProgrammatically(disp, handler, soapHandler);
+      
+        org.apache.handlers.types.AddNumbers req = new org.apache.handlers.types.AddNumbers();        
+        req.setArg0(10);
+        req.setArg1(20);        
+        ObjectFactory factory = new ObjectFactory();        
+        JAXBElement e = factory.createAddNumbers(req);        
+
+        JAXBElement response = (JAXBElement)disp.invoke(e);
+        assertNotNull(response);
+        AddNumbersResponse value = (AddNumbersResponse)response.getValue();
+        assertEquals(200, value.getReturn());
+    }
+
+    @Test
+    public void testInvokeWithDOMSourcMessageMode() throws Exception {
+        URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
+        assertNotNull(wsdl);
+
+        AddNumbersService service = new AddNumbersService(wsdl, serviceName);
+        assertNotNull(service);
+
+        Dispatch<DOMSource> disp = service.createDispatch(portName, DOMSource.class, Mode.MESSAGE);
+ 
+        TestHandler handler = new TestHandler();
+        TestSOAPHandler soapHandler = new TestSOAPHandler();
+        addHandlersProgrammatically(disp, handler, soapHandler);
+      
+        InputStream is2 =  this.getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
+        MessageFactory factory = MessageFactory.newInstance();
+        SOAPMessage soapReq = factory.createMessage(null, is2);
+        DOMSource domReqMessage = new DOMSource(soapReq.getSOAPPart());   
+
+        //XMLUtils.writeTo(domReqMessage, System.out);
+        DOMSource response = disp.invoke(domReqMessage);
+        assertNotNull(response);
+    }
+
+    @Test
+    public void testInvokeWithDOMSourcPayloadMode() throws Exception {
+        URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
+        assertNotNull(wsdl);
+
+        AddNumbersService service = new AddNumbersService(wsdl, serviceName);
+        assertNotNull(service);
+
+        Dispatch<DOMSource> disp = service.createDispatch(portName, DOMSource.class, Mode.PAYLOAD);
+ 
+        TestHandler handler = new TestHandler();
+        TestSOAPHandler soapHandler = new TestSOAPHandler();
+        addHandlersProgrammatically(disp, handler, soapHandler);
+      
+        InputStream is2 =  this.getClass().getResourceAsStream("resources/GreetMeDocLiteralReqPayload.xml");
+        MessageFactory factory = MessageFactory.newInstance();
+        SOAPMessage soapReq = factory.createMessage(null, is2);
+        DOMSource domReqMessage = new DOMSource(soapReq.getSOAPPart());   
+
+        //XMLUtils.writeTo(domReqMessage, System.out);
+        DOMSource response = disp.invoke(domReqMessage);
+        assertNotNull(response);
+    }
+
+    @Test
+    public void testInvokeWithSOAPMessageMessageMode() throws Exception {
+        URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
+        assertNotNull(wsdl);
+
+        AddNumbersService service = new AddNumbersService(wsdl, serviceName);
+        assertNotNull(service);
+
+        Dispatch<SOAPMessage> disp = service.createDispatch(portName, SOAPMessage.class, Mode.MESSAGE);
+ 
+        TestHandler handler = new TestHandler();
+        TestSOAPHandler soapHandler = new TestSOAPHandler();
+        addHandlersProgrammatically(disp, handler, soapHandler);
+      
+        InputStream is2 =  this.getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
+        MessageFactory factory = MessageFactory.newInstance();
+        SOAPMessage soapReq = factory.createMessage(null, is2);
+  
+        SOAPMessage response = disp.invoke(soapReq);
+        assertNotNull(response);
+        //response.writeTo(System.out);
+    }
+    
+    @Test
+    public void testInvokeWithSOAPMessagePayloadMode() throws Exception {
+        URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
+        assertNotNull(wsdl);
+
+        AddNumbersService service = new AddNumbersService(wsdl, serviceName);
+        assertNotNull(service);
+
+        Dispatch<SOAPMessage> disp = service.createDispatch(portName, SOAPMessage.class, Mode.PAYLOAD);
+ 
+        TestHandler handler = new TestHandler();
+        TestSOAPHandler soapHandler = new TestSOAPHandler();
+        addHandlersProgrammatically(disp, handler, soapHandler);
+      
+        InputStream is2 =  this.getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
+        MessageFactory factory = MessageFactory.newInstance();
+        SOAPMessage soapReq = factory.createMessage(null, is2);
+  
+        try {
+            disp.invoke(soapReq);
+            fail("Did not get expected exception");
+        } catch (SOAPFaultException e) {
+            assertEquals("Exception occured while marshalling Dispatch object to stream", e.getMessage());
+            e.printStackTrace();
+        }
+    }
+     
+    public void addHandlersProgrammatically(BindingProvider bp, Handler...handlers) {
+        List<Handler> handlerChain = bp.getBinding().getHandlerChain();
+        assertNotNull(handlerChain);
+        for (Handler h : handlers) {
+            handlerChain.add(h);
+        }    
+    }
+    
+    class TestHandler implements LogicalHandler<LogicalMessageContext> {
+        public boolean handleMessage(LogicalMessageContext ctx) {
+            try {
+                Boolean outbound = (Boolean)ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+                if (outbound) {
+                    LogicalMessage msg = ctx.getMessage();                        
+                    JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
+                    Object payload = ((JAXBElement)msg.getPayload(jaxbContext)).getValue();
+                    org.apache.handlers.types.AddNumbers req = 
+                        (org.apache.handlers.types.AddNumbers)payload;
+
+                    assertEquals(10, req.getArg0());
+                    assertEquals(20, req.getArg1());
+                } else {
+                    LogicalMessage msg = ctx.getMessage();
+                    JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
+                    Object payload = ((JAXBElement)msg.getPayload(jaxbContext)).getValue();
+                    org.apache.handlers.types.AddNumbersResponse res = 
+                        (org.apache.handlers.types.AddNumbersResponse)payload;
+
+                    assertEquals(200, res.getReturn());
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                fail(e.toString());
+            }
+            return true;
+        }        
+        public boolean handleFault(LogicalMessageContext ctx) {
+            return true;
+        }        
+        public void close(MessageContext arg0) {
+        }
+    }
+    
+    class TestSOAPHandler implements SOAPHandler<SOAPMessageContext> {
+        public boolean handleMessage(SOAPMessageContext ctx) {
+            try {
+                SOAPMessage msg = ctx.getMessage();
+                //msg.writeTo(System.out);
+                assertNotNull(msg);
+            } catch (Exception e) {
+                e.printStackTrace();
+                fail(e.toString());
+            }
+
+            return true;
+        }
+        public final Set<QName> getHeaders() {
+            return null;
+        }
+        public boolean handleFault(SOAPMessageContext ctx) {
+            return true;
+        }        
+        public void close(MessageContext arg0) {
+        }     
+    }   
+}

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/DispatchHandlerInvocationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/DispatchHandlerInvocationTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java?view=diff&rev=550274&r1=550273&r2=550274
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java Sun Jun 24 11:39:23 2007
@@ -66,11 +66,9 @@
 
             if (outbound) {
                 // get the LogicalMessage from our context
-                //
                 LogicalMessage msg = messageContext.getMessage();
 
                 // check the payload, if its an AddNumbers request, we'll intervene
-                //
                 JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
                 Object payload = msg.getPayload(jaxbContext);
                 if (payload instanceof JAXBElement) {
@@ -81,7 +79,6 @@
                     AddNumbers req = (AddNumbers)payload;
 
                     // now, if the arguments are small, let's do the calculation here
-                    //
                     int a = req.getArg0();
                     int b = req.getArg1();
 

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/resources/GreetMeDocLiteralReq.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/resources/GreetMeDocLiteralReq.xml?view=auto&rev=550274
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/resources/GreetMeDocLiteralReq.xml (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/resources/GreetMeDocLiteralReq.xml Sun Jun 24 11:39:23 2007
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements. See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership. The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License. You may obtain a copy of the License at
+ 
+  http://www.apache.org/licenses/LICENSE-2.0
+ 
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied. See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Header/><SOAP-ENV:Body><ns4:addNumbers xmlns:ns4="http://apache.org/handlers/types"><ns4:arg0>10</ns4:arg0><ns4:arg1>20</ns4:arg1></ns4:addNumbers></SOAP-ENV:Body></SOAP-ENV:Envelope>
\ No newline at end of file

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/resources/GreetMeDocLiteralReq.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/resources/GreetMeDocLiteralReq.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/resources/GreetMeDocLiteralReq.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/resources/GreetMeDocLiteralReqPayload.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/resources/GreetMeDocLiteralReqPayload.xml?view=auto&rev=550274
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/resources/GreetMeDocLiteralReqPayload.xml (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/resources/GreetMeDocLiteralReqPayload.xml Sun Jun 24 11:39:23 2007
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements. See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership. The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License. You may obtain a copy of the License at
+ 
+  http://www.apache.org/licenses/LICENSE-2.0
+ 
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied. See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<ns4:addNumbers xmlns:ns4="http://apache.org/handlers/types"><ns4:arg0>10</ns4:arg0><ns4:arg1>20</ns4:arg1></ns4:addNumbers>
\ No newline at end of file

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/resources/GreetMeDocLiteralReqPayload.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/resources/GreetMeDocLiteralReqPayload.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/resources/GreetMeDocLiteralReqPayload.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_xml_http/wrapped/GreeterImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_xml_http/wrapped/GreeterImpl.java?view=diff&rev=550274&r1=550273&r2=550274
==============================================================================
--- incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_xml_http/wrapped/GreeterImpl.java (original)
+++ incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_xml_http/wrapped/GreeterImpl.java Sun Jun 24 11:39:23 2007
@@ -32,6 +32,7 @@
 public class GreeterImpl implements Greeter {
 
     public String greetMe(String me) {        
+        System.out.println("Executing operation greetMe\n");
         return "Hello " + me;
     }