You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2008/05/28 17:48:41 UTC

svn commit: r660989 - in /webservices/axis2/trunk/java/modules: jaxws-integration/test-resources/ jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/clientTests/dispatch/datasource/ jaxws/src/org/apache/axis2/jaxws/client/dispatch/ jaxws/src/org/apa...

Author: dims
Date: Wed May 28 08:48:40 2008
New Revision: 660989

URL: http://svn.apache.org/viewvc?rev=660989&view=rev
Log:
part of fix for AXIS2-3805. got a sample test case working. please see JIRA for more TODO items

Added:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/DataSourceBlock.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockFactoryImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/DataSourceBlockFactory.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/DataSourceFormatter.java
Modified:
    webservices/axis2/trunk/java/modules/jaxws-integration/test-resources/axis2.xml
    webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/clientTests/dispatch/datasource/DispatchXMessageDataSourceTests.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/XMLDispatch.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageFactoryImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/registry/FactoryRegistry.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java

Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test-resources/axis2.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test-resources/axis2.xml?rev=660989&r1=660988&r2=660989&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test-resources/axis2.xml (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test-resources/axis2.xml Wed May 28 08:48:40 2008
@@ -109,6 +109,8 @@
                          class="org.apache.axis2.builder.ApplicationXMLBuilder"/>
         <messageBuilder contentType="application/x-www-form-urlencoded"
                          class="org.apache.axis2.builder.XFormURLEncodedBuilder"/>
+        <messageBuilder contentType=".*"
+                         class="org.apache.axis2.builder.DataSourceBuilder"/>
         <!--Left commented because it adds the depandancy of servlet-api to other modules.
         Please uncomment to Receive messages in multipart/form-data format-->
         <!--<messageBuilder contentType="multipart/form-data"-->

Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/clientTests/dispatch/datasource/DispatchXMessageDataSourceTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/clientTests/dispatch/datasource/DispatchXMessageDataSourceTests.java?rev=660989&r1=660988&r2=660989&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/clientTests/dispatch/datasource/DispatchXMessageDataSourceTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/clientTests/dispatch/datasource/DispatchXMessageDataSourceTests.java Wed May 28 08:48:40 2008
@@ -23,8 +23,10 @@
 import junit.framework.TestSuite;
 import org.apache.axis2.jaxws.framework.AbstractTestCase;
 import org.apache.axis2.jaxws.provider.DataSourceImpl;
+import org.apache.axiom.attachments.utils.IOUtils;
 
 import javax.activation.DataSource;
+import javax.activation.FileDataSource;
 import javax.imageio.ImageIO;
 import javax.imageio.stream.FileImageInputStream;
 import javax.imageio.stream.ImageInputStream;
@@ -34,6 +36,8 @@
 import javax.xml.ws.http.HTTPBinding;
 import java.awt.*;
 import java.io.File;
+import java.io.FileInputStream;
+import java.util.Arrays;
 
 public class DispatchXMessageDataSourceTests extends AbstractTestCase {
 
@@ -44,6 +48,7 @@
     private QName PORT_NAME  = new QName("http://ws.apache.org/axis2", "XMessageDataSourceProviderPort");
  
     private DataSource imageDS;
+    private DataSource xmlDS;
 
     public static Test suite() {
         return getTestSetup(new TestSuite(DispatchXMessageDataSourceTests.class));
@@ -51,12 +56,15 @@
  
     public void setUp() throws Exception {
         String imageResourceDir = System.getProperty("basedir",".")+"/"+"test-resources"+File.separator+"image";
-        
         //Create a DataSource from an image 
         File file = new File(imageResourceDir+File.separator+"test.jpg");
         ImageInputStream fiis = new FileImageInputStream(file);
         Image image = ImageIO.read(fiis);
         imageDS = new DataSourceImpl("image/jpeg","test.jpg",image);
+
+        String xmlResourceDir = System.getProperty("basedir",".")+"/"+"test-resources";
+        File file2 = new File(xmlResourceDir+File.separator+"axis2.xml");
+        xmlDS = new FileDataSource(file2);
     }
     
     public Dispatch<DataSource> getDispatch() {
@@ -70,14 +78,25 @@
      * Simple XML/HTTP Message Test
      * @throws Exception
      */
-    public void testSimple() throws Exception {
+    public void testDataSourceWithXML() throws Exception {
+        Dispatch<DataSource> dispatch = getDispatch();
+        DataSource request = xmlDS;
+        DataSource response = dispatch.invoke(request);
+        assertTrue(response != null);
+        String req = new String(IOUtils.getStreamAsByteArray(request.getInputStream()));
+        String res = new String(IOUtils.getStreamAsByteArray(response.getInputStream()));
+        assertEquals(req, res);
+    }
+
+    /**
+     * Simple XML/HTTP Message Test with an Image
+     * @throws Exception
+     */
+    public void testDataSourceWithImage() throws Exception {
         Dispatch<DataSource> dispatch = getDispatch();
         DataSource request = imageDS;
-        
-        // TODO NOT IMPLEMENTED
-        
-        //DataSource response = dispatch.invoke(request);
-        //assertTrue(response != null);
-        //assertTrue(request.equals(response));
+        DataSource response = dispatch.invoke(request);
+        assertTrue(response != null);
+        Arrays.equals(IOUtils.getStreamAsByteArray(request.getInputStream()), IOUtils.getStreamAsByteArray(response.getInputStream()));
     }
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java?rev=660989&r1=660988&r2=660989&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/BaseDispatch.java Wed May 28 08:48:40 2008
@@ -137,10 +137,7 @@
             Binding binding = (Binding) getBinding();
             invocationContext.setHandlers(binding.getHandlerChain());
 
-            Message requestMsg = createRequestMessage(obj);
-           
-            setupMessageProperties(requestMsg);
-            requestMsgCtx.setMessage(requestMsg);
+            initMessageContext(obj, requestMsgCtx);
 
             // Migrate the properties from the client request context bag to
             // the request MessageContext.
@@ -187,6 +184,12 @@
         }
     }
 
+    protected void initMessageContext(Object obj, MessageContext requestMsgCtx) {
+        Message requestMsg = createRequestMessage(obj);
+        setupMessageProperties(requestMsg);
+        requestMsgCtx.setMessage(requestMsg);
+    }
+
     public void invokeOneWay(Object obj) throws WebServiceException {
 
         // All exceptions are caught and rethrown as a WebServiceException
@@ -221,10 +224,7 @@
             Binding binding = (Binding) getBinding();
             invocationContext.setHandlers(binding.getHandlerChain());
 
-            Message requestMsg = createRequestMessage(obj);
-
-            setupMessageProperties(requestMsg);
-            requestMsgCtx.setMessage(requestMsg);
+            initMessageContext(obj, requestMsgCtx);
 
             // Migrate the properties from the client request context bag to
             // the request MessageContext.
@@ -288,10 +288,7 @@
             Binding binding = (Binding) getBinding();
             invocationContext.setHandlers(binding.getHandlerChain());
 
-            Message requestMsg = createRequestMessage(obj);
-
-            setupMessageProperties(requestMsg);
-            requestMsgCtx.setMessage(requestMsg);
+            initMessageContext(obj, requestMsgCtx);
 
             // Migrate the properties from the client request context bag to
             // the request MessageContext.
@@ -366,10 +363,7 @@
             Binding binding = (Binding) getBinding();
             invocationContext.setHandlers(binding.getHandlerChain());
 
-            Message requestMsg = createRequestMessage(obj);
-
-            setupMessageProperties(requestMsg);
-            requestMsgCtx.setMessage(requestMsg);
+            initMessageContext(obj, requestMsgCtx);
 
             // Migrate the properties from the client request context bag to
             // the request MessageContext.

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/XMLDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/XMLDispatch.java?rev=660989&r1=660988&r2=660989&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/XMLDispatch.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/XMLDispatch.java Wed May 28 08:48:40 2008
@@ -21,21 +21,26 @@
 
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.utility.DataSourceFormatter;
 import org.apache.axis2.jaxws.client.async.AsyncResponse;
+import org.apache.axis2.jaxws.core.MessageContext;
 import org.apache.axis2.jaxws.description.EndpointDescription;
 import org.apache.axis2.jaxws.message.Block;
 import org.apache.axis2.jaxws.message.Message;
 import org.apache.axis2.jaxws.message.Protocol;
 import org.apache.axis2.jaxws.message.factory.BlockFactory;
+import org.apache.axis2.jaxws.message.factory.DataSourceBlockFactory;
 import org.apache.axis2.jaxws.message.factory.MessageFactory;
 import org.apache.axis2.jaxws.message.factory.SOAPEnvelopeBlockFactory;
 import org.apache.axis2.jaxws.message.factory.SourceBlockFactory;
 import org.apache.axis2.jaxws.message.factory.XMLStringBlockFactory;
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
 import org.apache.axis2.jaxws.spi.ServiceDelegate;
+import org.apache.axis2.Constants;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import javax.activation.DataSource;
 import javax.xml.soap.SOAPEnvelope;
 import javax.xml.soap.SOAPMessage;
 import javax.xml.stream.XMLStreamException;
@@ -224,6 +229,11 @@
                 log.debug(">> returning SourceBlockFactory");
             }
             return SourceBlockFactory.class;
+        } else if (DataSource.class.isAssignableFrom(o.getClass())) {
+            if (log.isDebugEnabled()) {
+                log.debug(">> returning DataSourceBlockFactory");
+            }
+            return DataSourceBlockFactory.class;
         } else if (SOAPMessage.class.isAssignableFrom(o.getClass())) {
             if (log.isDebugEnabled()) {
                 log.debug(">> returning SOAPMessageFactory");
@@ -278,4 +288,12 @@
     }
 
 
+    protected void initMessageContext(Object obj, MessageContext requestMsgCtx) {
+        super.initMessageContext(obj, requestMsgCtx);
+        if(obj instanceof DataSource){
+            requestMsgCtx.setProperty(Constants.Configuration.MESSAGE_FORMATTER, 
+                    new DataSourceFormatter(((DataSource)obj).getContentType()));    
+        }
+    }
+
 }

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/DataSourceBlock.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/DataSourceBlock.java?rev=660989&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/DataSourceBlock.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/DataSourceBlock.java Wed May 28 08:48:40 2008
@@ -0,0 +1,27 @@
+/*
+ * 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.axis2.jaxws.message.databinding;
+
+import org.apache.axis2.jaxws.message.Block;
+
+/** DataSourceBlock Block with a business object that is a javax.activation.DataSource */
+public interface DataSourceBlock extends Block {
+
+}
\ No newline at end of file

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockFactoryImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockFactoryImpl.java?rev=660989&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockFactoryImpl.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockFactoryImpl.java Wed May 28 08:48:40 2008
@@ -0,0 +1,67 @@
+/*
+ * 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.axis2.jaxws.message.databinding.impl;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.jaxws.message.Block;
+import org.apache.axis2.jaxws.message.factory.SourceBlockFactory;
+import org.apache.axis2.jaxws.message.factory.DataSourceBlockFactory;
+import org.apache.axis2.jaxws.message.impl.BlockFactoryImpl;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.transform.Source;
+import javax.xml.ws.WebServiceException;
+import javax.activation.DataSource;
+
+/**
+ * SourceBlockFactoryImpl
+ * <p/>
+ * Creates a SourceBlock
+ */
+public class DataSourceBlockFactoryImpl extends BlockFactoryImpl implements DataSourceBlockFactory {
+
+    /** Default Constructor required for Factory */
+    public DataSourceBlockFactoryImpl() {
+        super();
+    }
+
+    /* (non-Javadoc)
+      * @see org.apache.axis2.jaxws.message.BlockFactory#createFrom(java.lang.Object, java.lang.Object, javax.xml.namespace.QName)
+      */
+    public Block createFrom(Object businessObject, Object context, QName qName)
+            throws WebServiceException {
+        return new DataSourceBlockImpl((DataSource)businessObject, qName, this);
+    }
+
+
+    /* (non-Javadoc)
+      * @see org.apache.axis2.jaxws.message.BlockFactory#createFrom(org.apache.axiom.om.OMElement, java.lang.Object, javax.xml.namespace.QName)
+      */
+    public Block createFrom(OMElement omElement, Object context, QName qName)
+            throws XMLStreamException {
+        return new DataSourceBlockImpl(omElement, qName, this);
+    }
+
+    public boolean isElement() {
+        return false;
+    }
+
+}
\ No newline at end of file

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockImpl.java?rev=660989&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockImpl.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockImpl.java Wed May 28 08:48:40 2008
@@ -0,0 +1,375 @@
+/*
+ * 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.axis2.jaxws.message.databinding.impl;
+
+import org.apache.axiom.om.OMDataSource;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMSourcedElement;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.ds.ByteArrayDataSource;
+import org.apache.axiom.om.impl.OMNamespaceImpl;
+import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.attachments.utils.IOUtils;
+import org.apache.axis2.datasource.SourceDataSource;
+import org.apache.axis2.java.security.AccessController;
+import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.i18n.Messages;
+import org.apache.axis2.jaxws.message.databinding.SourceBlock;
+import org.apache.axis2.jaxws.message.databinding.DataSourceBlock;
+import org.apache.axis2.jaxws.message.factory.BlockFactory;
+import org.apache.axis2.jaxws.message.impl.BlockImpl;
+import org.apache.axis2.jaxws.message.util.Reader2Writer;
+import org.apache.axis2.jaxws.utility.ConvertUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.bind.util.JAXBSource;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.WebServiceException;
+import javax.activation.DataSource;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.io.IOException;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ * SourceBlock
+ * <p/>
+ * Block containing a business object that is a javax.activation.DataSource
+ * <p/>
+ */
+public class DataSourceBlockImpl extends BlockImpl implements DataSourceBlock {
+
+    private static final Log log = LogFactory.getLog(DataSourceBlockImpl.class);
+
+    /**
+     * Constructor called from factory
+     *
+     * @param busObject
+     * @param qName
+     * @param factory
+     */
+    DataSourceBlockImpl(DataSource busObject, QName qName, BlockFactory factory)
+            throws WebServiceException {
+        super(busObject, null, qName, factory);
+        // Check validity of DataSource
+        if (!(busObject instanceof DataSource)) {
+            throw ExceptionFactory.makeWebServiceException(
+                    Messages.getMessage("SourceNotSupported", busObject.getClass().getName()));
+        }
+    }
+
+
+    /**
+     * Constructor called from factory
+     *
+     * @param reader
+     * @param qName
+     * @param factory
+     */
+    public DataSourceBlockImpl(OMElement omElement, QName qName, BlockFactory factory) {
+        super(omElement, null, qName, factory);
+    }
+
+    protected Object _getBOFromReader(XMLStreamReader reader, Object busContext) throws XMLStreamException, WebServiceException {
+        // Best solution is to use a StAXSource
+        // However StAXSource is not widely accepted.  
+        // For now, a StreamSource is always returned
+        /*
+        if (staxSource != null) {
+            try {
+                // TODO Constructor should be statically cached for performance
+                Constructor c =
+                        staxSource.getDeclaredConstructor(new Class[] { XMLStreamReader.class });
+                return c.newInstance(new Object[] { reader });
+            } catch (Exception e) {
+            }
+        }
+        */
+
+        // TODO StreamSource is not performant...work is needed here to make this faster
+        Reader2Writer r2w = new Reader2Writer(reader);
+        String text = r2w.getAsString();
+        StringReader sr = new StringReader(text);
+        return new StreamSource(sr);
+
+    }
+
+    public OMElement getOMElement() throws XMLStreamException, WebServiceException {
+        OMNamespace ns = new OMNamespaceImpl("", "");
+        OMFactory factory = OMAbstractFactory.getOMFactory();
+        if(busObject instanceof OMDataSource) {
+            return new OMSourcedElementImpl("dummy", ns, factory, (OMDataSource) busObject);
+        }
+        return new OMSourcedElementImpl("dummy", ns, factory, new OMDataSource() {
+            public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {
+                try {
+                    InputStream in = ((DataSource)busObject).getInputStream();
+                    int ch;
+                    while((ch = in.read())!=-1){
+                        output.write(ch);
+                    }
+                } catch (IOException e) {
+                    throw new XMLStreamException(e);
+                }
+            }
+
+            public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException {
+                throw new UnsupportedOperationException("FIXME");
+            }
+
+            public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
+                throw new UnsupportedOperationException("FIXME");
+            }
+
+            public XMLStreamReader getReader() throws XMLStreamException {
+                throw new UnsupportedOperationException("FIXME");
+            }
+        });
+    }
+
+    @Override
+    protected Object _getBOFromOM(OMElement omElement, Object busContext)
+        throws XMLStreamException, WebServiceException {
+        Object busObject;
+        
+        // Shortcut to get business object from existing data source
+        if (omElement instanceof OMSourcedElement) {
+            OMDataSource ds = ((OMSourcedElement) omElement).getDataSource();
+            if (ds instanceof SourceDataSource) {
+                return ((SourceDataSource) ds).getObject();
+            }
+        }
+        
+        // If the message is a fault, there are some special gymnastics that we have to do
+        // to get this working for all of the handler scenarios.  
+        boolean hasFault = false;
+        if ((parent != null && parent.isFault()) || 
+            omElement.getQName().getLocalPart().equals(SOAP11Constants.SOAPFAULT_LOCAL_NAME)) {
+            hasFault = true;
+        }
+        
+        // Transform reader into business object
+        if (!hasFault) {
+            busObject = ((OMSourcedElement)omElement).getDataSource();
+        }
+        else {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            omElement.serialize(baos);
+            busObject = new ByteArrayDataSource(baos.toByteArray(), "UTF-8");
+        }
+        return busObject;
+    }
+
+    @Override
+    protected XMLStreamReader _getReaderFromBO(Object busObj, Object busContext)
+            throws XMLStreamException, WebServiceException {
+        try {
+            // TODO not sure if this is always the most performant way to do this.
+            /* The following code failed in some (CTS) environments. 
+	        if (busObj instanceof DOMSource) {
+	            // Let's use our own DOMReader for now...
+	            Element element = null;
+	            
+	            // Business Object msut be a Document or Element
+	            Node node = ((DOMSource)busObj).getNode();
+	            if(node instanceof Document){
+	                element = ((Document)node).getDocumentElement();
+	            }else{
+	                element = (Element) ((DOMSource)busObj).getNode();
+	            }
+	            
+	            // We had some problems with testers producing DOMSources w/o Namespaces.  
+	            // It's easy to catch this here.
+	            if (element.getLocalName() == null) {
+	                throw new XMLStreamException(ExceptionFactory.
+                           makeWebServiceException(Messages.getMessage("JAXBSourceNamespaceErr")));
+	            }
+	            
+	            return new DOMReader(element);
+	        } 
+            */
+
+            if (busObj instanceof StreamSource) {
+                XMLInputFactory f = StAXUtils.getXMLInputFactory();
+
+                XMLStreamReader reader = f.createXMLStreamReader((Source)busObj);
+                StAXUtils.releaseXMLInputFactory(f);
+                return reader;
+            }
+            //TODO: For GM we need to only use this approach when absolutely necessary.
+            // For example, we don't want to do this if this is a (1.6) StaxSource or if the 
+            // installed parser provides a better solution.
+            //TODO: Uncomment this code if woodstock parser handles 
+            // JAXBSource and SAXSource correctly.
+            //return inputFactory.createXMLStreamReader((Source) busObj);
+            return _slow_getReaderFromSource((Source)busObj);
+        } catch (Exception e) {
+            String className = (busObj == null) ? "none" : busObj.getClass().getName();
+            throw ExceptionFactory
+                    .makeWebServiceException(Messages.getMessage("SourceReadErr", className), e);
+        }
+    }
+
+    /** Creates an XMLStreamReader from a Source using a slow but proven algorithm. */
+    private XMLStreamReader _slow_getReaderFromSource(Source src) throws XMLStreamException {
+        if (log.isDebugEnabled()) {
+            log.debug("Start _slow_getReaderFromSource");
+        }
+        byte[] bytes = (byte[]) ConvertUtils.convert(src, byte[].class);
+        if (log.isDebugEnabled()) {
+            log.debug("Successfully converted to ByteArray");
+        }
+        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+        XMLStreamReader reader = StAXUtils.createXMLStreamReader(bais);
+        if (log.isDebugEnabled()) {
+            log.debug("End _slow_getReaderFromSource =" + reader);
+        }
+        return reader;
+    }
+
+    @Override
+    protected void _outputFromBO(Object busObject, Object busContext, XMLStreamWriter writer)
+            throws XMLStreamException, WebServiceException {
+        // There is no fast way to output the Source to a writer, so get the reader
+        // and pass use the default reader->writer.
+        if (log.isDebugEnabled()) {
+            log.debug("Start _outputFromBO");
+        }
+        XMLStreamReader reader = _getReaderFromBO(busObject, busContext);
+        if (log.isDebugEnabled()) {
+            log.debug("Obtained reader=" + reader);
+        }
+        _outputFromReader(reader, writer);
+        if (log.isDebugEnabled()) {
+            log.debug("End _outputReaderFromBO");
+        }
+        // REVIEW Should we call close() on the Source ?
+    }
+
+
+    @Override
+    protected Object _getBOFromBO(Object busObject, Object busContext, boolean consume) {
+        if (consume) {
+            return busObject;
+        } else {
+            // TODO Missing Impl
+            throw ExceptionFactory.makeWebServiceException(
+                    Messages.getMessage("SourceMissingSupport", busObject.getClass().getName()));
+        }
+    }
+
+    public boolean isElementData() {
+        return false;  // The source could be a text or element etc.
+    }
+
+    /**
+     * Return the class for this name
+     * @return Class
+     */
+    private static Class forName(final String className) throws ClassNotFoundException {
+        // NOTE: This method must remain private because it uses AccessController
+        Class cl = null;
+        try {
+            cl = (Class)AccessController.doPrivileged(
+                    new PrivilegedExceptionAction() {
+                        public Object run() throws ClassNotFoundException {
+                            return Class.forName(className);
+                        }
+                    }
+            );
+        } catch (PrivilegedActionException e) {
+            if (log.isDebugEnabled()) {
+                log.debug("Exception thrown from AccessController: " + e);
+            }
+            throw (ClassNotFoundException)e.getException();
+        }
+
+        return cl;
+    }
+    
+    
+    public void close() {
+        return; // Nothing to close
+    }
+
+    public InputStream getXMLInputStream(String encoding) throws UnsupportedEncodingException {
+        try {
+            byte[] bytes = (byte[]) 
+                ConvertUtils.convert(getBusinessObject(false), byte[].class);
+            return new ByteArrayInputStream(bytes);
+        } catch (XMLStreamException e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        }
+    }
+
+    public Object getObject() {
+        try {
+            return getBusinessObject(false);
+        } catch (XMLStreamException e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        }
+    }
+
+    public boolean isDestructiveRead() {
+        return true;
+    }
+
+    public boolean isDestructiveWrite() {
+        return true;
+    }
+
+
+    public byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException {
+        if (log.isDebugEnabled()) {
+            log.debug("Start getXMLBytes");
+        }
+        byte[] bytes = null;
+        try {
+            bytes = (byte[]) 
+                ConvertUtils.convert(getBusinessObject(false), byte[].class);
+        } catch (XMLStreamException e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        }
+        if (log.isDebugEnabled()) {
+            log.debug("End getXMLBytes");
+        }
+        return bytes;
+    }
+}
\ No newline at end of file

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/DataSourceBlockFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/DataSourceBlockFactory.java?rev=660989&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/DataSourceBlockFactory.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/factory/DataSourceBlockFactory.java Wed May 28 08:48:40 2008
@@ -0,0 +1,34 @@
+/*
+ * 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.axis2.jaxws.message.factory;
+
+
+/**
+ * DataSourceBlockFactory
+ * <p/>
+ * Creates a SourceBlock
+ * <p/>
+ * The FactoryRegistry should be used to get access to the Factory
+ *
+ * @see org.apache.axis2.jaxws.registry.FactoryRegistry
+ */
+public interface DataSourceBlockFactory extends BlockFactory {
+
+}
\ No newline at end of file

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageFactoryImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageFactoryImpl.java?rev=660989&r1=660988&r2=660989&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageFactoryImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageFactoryImpl.java Wed May 28 08:48:40 2008
@@ -20,7 +20,12 @@
 package org.apache.axis2.jaxws.message.impl;
 
 import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.OMNamespaceImpl;
+import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
 import org.apache.axis2.jaxws.ExceptionFactory;
@@ -28,6 +33,7 @@
 import org.apache.axis2.jaxws.message.Message;
 import org.apache.axis2.jaxws.message.Protocol;
 import org.apache.axis2.jaxws.message.databinding.SOAPEnvelopeBlock;
+import org.apache.axis2.jaxws.message.databinding.DataSourceBlock;
 import org.apache.axis2.jaxws.message.factory.MessageFactory;
 import org.apache.axis2.transport.http.HTTPConstants;
 
@@ -129,6 +135,8 @@
         // Small optimization to quickly consider the SOAPEnvelope case
         if (block instanceof SOAPEnvelopeBlock) {
             return new MessageImpl((SOAPEnvelope)block.getBusinessObject(true), protocol);
+        } else if (block instanceof DataSourceBlock) {
+            return createFrom(block.getOMElement(), protocol);
         }
         return createFrom(block.getXMLStreamReader(true), protocol);
     }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/registry/FactoryRegistry.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/registry/FactoryRegistry.java?rev=660989&r1=660988&r2=660989&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/registry/FactoryRegistry.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/registry/FactoryRegistry.java Wed May 28 08:48:40 2008
@@ -37,6 +37,7 @@
 import org.apache.axis2.jaxws.message.databinding.impl.SOAPEnvelopeBlockFactoryImpl;
 import org.apache.axis2.jaxws.message.databinding.impl.SourceBlockFactoryImpl;
 import org.apache.axis2.jaxws.message.databinding.impl.XMLStringBlockFactoryImpl;
+import org.apache.axis2.jaxws.message.databinding.impl.DataSourceBlockFactoryImpl;
 import org.apache.axis2.jaxws.message.factory.ClassFinderFactory;
 import org.apache.axis2.jaxws.message.factory.JAXBBlockFactory;
 import org.apache.axis2.jaxws.message.factory.MessageFactory;
@@ -46,6 +47,7 @@
 import org.apache.axis2.jaxws.message.factory.SourceBlockFactory;
 import org.apache.axis2.jaxws.message.factory.XMLPartFactory;
 import org.apache.axis2.jaxws.message.factory.XMLStringBlockFactory;
+import org.apache.axis2.jaxws.message.factory.DataSourceBlockFactory;
 import org.apache.axis2.jaxws.message.impl.MessageFactoryImpl;
 import org.apache.axis2.jaxws.message.impl.XMLPartFactoryImpl;
 import org.apache.axis2.jaxws.message.util.impl.SAAJConverterFactoryImpl;
@@ -103,6 +105,7 @@
         table.put(JAXBBlockFactory.class, new JAXBBlockFactoryImpl());
         table.put(OMBlockFactory.class, new OMBlockFactoryImpl());
         table.put(SourceBlockFactory.class, new SourceBlockFactoryImpl());
+        table.put(DataSourceBlockFactory.class, new DataSourceBlockFactoryImpl());
         table.put(SOAPEnvelopeBlockFactory.class, new SOAPEnvelopeBlockFactoryImpl());
         table.put(MessageFactory.class, new MessageFactoryImpl());
         table.put(XMLPartFactory.class, new XMLPartFactoryImpl());

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java?rev=660989&r1=660988&r2=660989&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java Wed May 28 08:48:40 2008
@@ -19,8 +19,8 @@
 
 package org.apache.axis2.jaxws.server.dispatcher;
 
+import org.apache.axis2.Constants;
 import org.apache.axis2.jaxws.ExceptionFactory;
-import org.apache.axis2.jaxws.binding.BindingUtils;
 import org.apache.axis2.jaxws.context.utils.ContextUtils;
 import org.apache.axis2.jaxws.core.MessageContext;
 import org.apache.axis2.jaxws.core.util.MessageContextUtils;
@@ -32,6 +32,7 @@
 import org.apache.axis2.jaxws.message.Protocol;
 import org.apache.axis2.jaxws.message.XMLFault;
 import org.apache.axis2.jaxws.message.factory.BlockFactory;
+import org.apache.axis2.jaxws.message.factory.DataSourceBlockFactory;
 import org.apache.axis2.jaxws.message.factory.MessageFactory;
 import org.apache.axis2.jaxws.message.factory.SOAPEnvelopeBlockFactory;
 import org.apache.axis2.jaxws.message.factory.SourceBlockFactory;
@@ -42,6 +43,7 @@
 import org.apache.axis2.jaxws.server.InvocationHelper;
 import org.apache.axis2.jaxws.server.ServerConstants;
 import org.apache.axis2.jaxws.utility.ClassUtils;
+import org.apache.axis2.jaxws.utility.DataSourceFormatter;
 import org.apache.axis2.jaxws.utility.ExecutorFactory;
 import org.apache.axis2.jaxws.utility.SingleThreadedExecutor;
 import org.apache.commons.logging.Log;
@@ -343,7 +345,7 @@
             
 
             response = MessageContextUtils.createResponseMessageContext(request);
-            response.setMessage(m);
+            initMessageContext(response, m, output);
         } catch (RuntimeException e) {
             if (log.isDebugEnabled()) {
                 log.debug("Throwable caught creating Response MessageContext");
@@ -358,6 +360,14 @@
         return response;
     }
     
+    protected void initMessageContext(MessageContext responseMsgCtx, Message m, Object output) {
+        responseMsgCtx.setMessage(m);
+        if(output instanceof DataSource){
+            responseMsgCtx.setProperty(Constants.Configuration.MESSAGE_FORMATTER, 
+                    new DataSourceFormatter(((DataSource)output).getContentType()));
+        }
+    }
+    
     public MessageContext createFaultResponse(MessageContext request, Throwable fault) {
         if (log.isDebugEnabled()) {
             log.debug("Create XMLFault for createFaultResponse");
@@ -581,6 +591,9 @@
         if (type.equals(String.class)) {
             _blockFactory = (XMLStringBlockFactory)FactoryRegistry.getFactory(
                     XMLStringBlockFactory.class);
+        } else if (type.equals(DataSource.class)) {
+            _blockFactory = (DataSourceBlockFactory)FactoryRegistry.getFactory(
+                    DataSourceBlockFactory.class);
         } else if (type.equals(Source.class)) {
             _blockFactory = (SourceBlockFactory)FactoryRegistry.getFactory(
                     SourceBlockFactory.class);

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/DataSourceFormatter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/DataSourceFormatter.java?rev=660989&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/DataSourceFormatter.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/DataSourceFormatter.java Wed May 28 08:48:40 2008
@@ -0,0 +1,55 @@
+/*
+ * 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.axis2.jaxws.utility;
+
+import org.apache.axis2.transport.http.ApplicationXMLFormatter;
+import org.apache.axis2.AxisFault;
+import org.apache.axiom.om.OMOutputFormat;
+
+import java.io.OutputStream;
+import java.net.URL;
+
+public class DataSourceFormatter extends ApplicationXMLFormatter {
+    private final String contentType;
+
+    public DataSourceFormatter(String contentType) {
+        this.contentType = contentType;
+    }
+
+    public byte[] getBytes(org.apache.axis2.context.MessageContext messageContext, OMOutputFormat format) throws AxisFault {
+        return super.getBytes(messageContext, format);
+    }
+
+    public void writeTo(org.apache.axis2.context.MessageContext messageContext, OMOutputFormat format, OutputStream outputStream, boolean preserve) throws AxisFault {
+        super.writeTo(messageContext, format, outputStream, preserve);
+    }
+
+    public String getContentType(org.apache.axis2.context.MessageContext messageContext, OMOutputFormat format, String soapAction) {
+        return contentType;
+    }
+
+    public URL getTargetAddress(org.apache.axis2.context.MessageContext messageContext, OMOutputFormat format, URL targetURL) throws AxisFault {
+        return super.getTargetAddress(messageContext, format, targetURL);
+    }
+
+    public String formatSOAPAction(org.apache.axis2.context.MessageContext messageContext, OMOutputFormat format, String soapAction) {
+        return super.formatSOAPAction(messageContext, format, soapAction);
+    }
+}