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/30 19:18:15 UTC

svn commit: r661792 - in /webservices/axis2/trunk/java/modules: jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/clientTests/dispatch/datasource/ jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/provider/message/datasource/ jaxws/src/org/apac...

Author: dims
Date: Fri May 30 10:18:14 2008
New Revision: 661792

URL: http://svn.apache.org/viewvc?rev=661792&view=rev
Log:
Part of fix for AXIS2-3805 - Provider<DataSource> does not work. Adding support for sending/receiving multiple mime parts

Modified:
    webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/clientTests/dispatch/datasource/DispatchXMessageDataSourceTests.java
    webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/provider/message/datasource/XMessageDataSourceProvider.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/MEPContext.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/utility/DataSourceFormatter.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/DataSourceBuilder.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/MIMEBuilder.java

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=661792&r1=661791&r2=661792&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 Fri May 30 10:18:14 2008
@@ -24,20 +24,28 @@
 import org.apache.axis2.jaxws.framework.AbstractTestCase;
 import org.apache.axis2.jaxws.provider.DataSourceImpl;
 import org.apache.axiom.attachments.utils.IOUtils;
+import org.apache.axiom.attachments.impl.BufferUtils;
+import org.apache.axiom.om.util.UUIDGenerator;
 
 import javax.activation.DataSource;
 import javax.activation.FileDataSource;
+import javax.activation.DataHandler;
 import javax.imageio.ImageIO;
 import javax.imageio.stream.FileImageInputStream;
 import javax.imageio.stream.ImageInputStream;
 import javax.xml.namespace.QName;
 import javax.xml.ws.Dispatch;
 import javax.xml.ws.Service;
+import javax.xml.ws.handler.MessageContext;
 import javax.xml.ws.http.HTTPBinding;
 import java.awt.*;
 import java.io.File;
-import java.io.FileInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.IOException;
 import java.util.Arrays;
+import java.util.Map;
+import java.util.HashMap;
 
 public class DispatchXMessageDataSourceTests extends AbstractTestCase {
 
@@ -48,7 +56,8 @@
     private QName PORT_NAME  = new QName("http://ws.apache.org/axis2", "XMessageDataSourceProviderPort");
  
     private DataSource imageDS;
-    private DataSource xmlDS;
+    private FileDataSource txtDS;
+    private DataSource attachmentDS;
 
     public static Test suite() {
         return getTestSetup(new TestSuite(DispatchXMessageDataSourceTests.class));
@@ -56,15 +65,19 @@
  
     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);
+        String textResourceDir = System.getProperty("basedir",".")+"/"+"test/org/apache/axis2/jaxws/xmlhttp";
+        File file2 = new File(textResourceDir+File.separator+"README.txt");
+        txtDS = new FileDataSource(file2);
+
+        String resourceDir = System.getProperty("basedir",".")+"/"+"test-resources";
+        File file3 = new File(resourceDir+File.separator+"log4j.properties");
+        attachmentDS = new FileDataSource(file3);
     }
     
     public Dispatch<DataSource> getDispatch() {
@@ -74,29 +87,102 @@
        return dispatch;
     }
     
-    /**
-     * Simple XML/HTTP Message Test
-     * @throws Exception
-     */
-    public void testDataSourceWithXML() throws Exception {
+    public void testDataSourceWithTXT() throws Exception {
         Dispatch<DataSource> dispatch = getDispatch();
-        DataSource request = xmlDS;
+        DataSource request = txtDS;
         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(response.getContentType(),"text/plain");
+        String req = new String(getStreamAsByteArray(request.getInputStream()));
+        String res = new String(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;
         DataSource response = dispatch.invoke(request);
         assertTrue(response != null);
-        Arrays.equals(IOUtils.getStreamAsByteArray(request.getInputStream()), IOUtils.getStreamAsByteArray(response.getInputStream()));
+        assertEquals(response.getContentType(),"image/jpeg");
+        assertTrue(Arrays.equals(getStreamAsByteArray(request.getInputStream()), 
+                getStreamAsByteArray(response.getInputStream())));
+    }
+
+    public void testDataSourceWithTXTPlusAttachment() throws Exception {
+        Dispatch<DataSource> dispatch = getDispatch();
+
+        Map attachments = new HashMap();
+        Map requestContext = dispatch.getRequestContext();
+
+//        requestContext.put(org.apache.axis2.transport.http.HTTPConstants.SO_TIMEOUT , new 
+//        Integer(999999));
+//        requestContext.put(org.apache.axis2.transport.http.HTTPConstants.CONNECTION_TIMEOUT, new 
+//        Integer(999999));
+
+        requestContext.put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS,
+                attachments);
+        attachments.put(UUIDGenerator.getUUID(), new DataHandler(attachmentDS));
+
+        DataSource request = txtDS;
+        DataSource response = dispatch.invoke(request);
+        assertTrue(response != null);
+        assertEquals(response.getContentType(),"text/plain");
+        String req = new String(getStreamAsByteArray(request.getInputStream()));
+        String res = new String(getStreamAsByteArray(response.getInputStream()));
+        assertEquals(req, res);
+        Map attachments2 = (Map) dispatch.getResponseContext().get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS);
+        assertTrue(attachments2 != null);
+        assertEquals(attachments2.size(), 1);
+    }
+
+    public void testDataSourceWithImagePlusAttachment() throws Exception {
+        Dispatch<DataSource> dispatch = getDispatch();
+
+        Map attachments = new HashMap();
+        Map requestContext = dispatch.getRequestContext();
+
+        requestContext.put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS,
+                attachments);
+        attachments.put(UUIDGenerator.getUUID(), new DataHandler(attachmentDS));
+        
+        DataSource request = imageDS;
+        DataSource response = dispatch.invoke(request);
+        assertTrue(response != null);
+        assertEquals(response.getContentType(),"image/jpeg");
+        assertTrue(Arrays.equals(getStreamAsByteArray(request.getInputStream()), 
+                getStreamAsByteArray(response.getInputStream())));
+        Map attachments2 = (Map) dispatch.getResponseContext().get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS);
+        assertTrue(attachments2 != null);
+        assertEquals(attachments2.size(), 1);
+    }
+
+    public void testDataSourceWithTXTPlusTwoAttachments() throws Exception {
+        Dispatch<DataSource> dispatch = getDispatch();
+
+        Map attachments = new HashMap();
+        Map requestContext = dispatch.getRequestContext();
+
+        requestContext.put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS,
+                attachments);
+        attachments.put(UUIDGenerator.getUUID(), new DataHandler(attachmentDS));
+        attachments.put(UUIDGenerator.getUUID(), new DataHandler(imageDS));
+
+        DataSource request = txtDS;
+        DataSource response = dispatch.invoke(request);
+        assertTrue(response != null);
+        assertEquals(response.getContentType(),"text/plain");
+        String req = new String(getStreamAsByteArray(request.getInputStream()));
+        String res = new String(getStreamAsByteArray(response.getInputStream()));
+        assertEquals(req, res);
+        Map attachments2 = (Map) dispatch.getResponseContext().get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS);
+        assertTrue(attachments2 != null);
+        assertEquals(attachments2.size(), 2);
+    }
+    
+    private byte[] getStreamAsByteArray(InputStream is) throws IOException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
+        BufferUtils.inputStream2OutputStream(is, baos);
+        baos.flush();
+        return baos.toByteArray();
     }
 }

Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/provider/message/datasource/XMessageDataSourceProvider.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/provider/message/datasource/XMessageDataSourceProvider.java?rev=661792&r1=661791&r2=661792&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/provider/message/datasource/XMessageDataSourceProvider.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/xmlhttp/provider/message/datasource/XMessageDataSourceProvider.java Fri May 30 10:18:14 2008
@@ -25,7 +25,11 @@
 import javax.xml.ws.Service;
 import javax.xml.ws.ServiceMode;
 import javax.xml.ws.WebServiceProvider;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.MessageContext;
 import javax.xml.ws.http.HTTPBinding;
+import javax.annotation.Resource;
+import java.util.Map;
 
 /**
  * Sample XML/HTTP DataSource Provider 
@@ -34,8 +38,13 @@
 @BindingType(HTTPBinding.HTTP_BINDING)
 @ServiceMode(value=Service.Mode.MESSAGE)
 public class XMessageDataSourceProvider implements Provider<DataSource> {
-
+    @Resource
+    WebServiceContext wsContext;
+    
     public DataSource invoke(DataSource input) {
+        MessageContext ctx = wsContext.getMessageContext();
+        Map attachments = (Map) ctx.get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS);
+        ctx.put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS, attachments);
         return input;
     }
 

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/MEPContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/MEPContext.java?rev=661792&r1=661791&r2=661792&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/MEPContext.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/MEPContext.java Fri May 30 10:18:14 2008
@@ -90,6 +90,10 @@
     }
     
     public void setResponseMessageContext(MessageContext responseMC) {
+        if(this.responseMC != null) {
+            responseMC.setProperty(javax.xml.ws.handler.MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS, 
+                    this.responseMC.getProperty(javax.xml.ws.handler.MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS));
+        }
         // TODO does ApplicationAccessLocked mean anything here? -- method is protected, so probably not
         this.responseMC = responseMC;
         // if callers are being careful, the responseMC should not be set

Modified: 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=661792&r1=661791&r2=661792&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/DataSourceBlockImpl.java Fri May 30 10:18:14 2008
@@ -19,24 +19,22 @@
 
 package org.apache.axis2.jaxws.message.databinding.impl;
 
+import org.apache.axiom.attachments.impl.BufferUtils;
+import org.apache.axiom.om.OMAbstractFactory;
 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.OMNamespace;
 import org.apache.axiom.om.OMOutputFormat;
-import org.apache.axiom.om.ds.ByteArrayDataSource;
+import org.apache.axiom.om.OMSourcedElement;
 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;
@@ -45,26 +43,20 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import javax.xml.bind.util.JAXBSource;
+import javax.activation.DataSource;
+import javax.mail.util.ByteArrayDataSource;
 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.IOException;
 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.io.UnsupportedEncodingException;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 
@@ -108,60 +100,19 @@
     }
 
     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);
+        try {
+            return new ByteArrayDataSource(r2w.getAsString(), "application/octet-stream");
+        } catch (IOException e) {
+            throw new XMLStreamException(e);
+        }
 
     }
 
     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");
-            }
-        });
+        return new OMSourcedElementImpl("dummy", ns, factory, this);
     }
 
     @Override
@@ -201,69 +152,30 @@
     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) {
+            if (busObj instanceof DataSource) {
                 XMLInputFactory f = StAXUtils.getXMLInputFactory();
 
-                XMLStreamReader reader = f.createXMLStreamReader((Source)busObj);
+                XMLStreamReader reader = f.createXMLStreamReader(((DataSource)busObj).getInputStream());
                 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);
+            throw ExceptionFactory.makeWebServiceException(
+                    Messages.getMessage("SourceNotSupported", busObject.getClass().getName()));
         } 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);
+    
+    public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {
+        try {
+            BufferUtils.inputStream2OutputStream(((DataSource)busObject).getInputStream(), output);
+        } catch (IOException e) {
+            throw new XMLStreamException(e);
         }
-        return reader;
     }
-
+    
     @Override
     protected void _outputFromBO(Object busObject, Object busContext, XMLStreamWriter writer)
             throws XMLStreamException, WebServiceException {

Modified: 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=661792&r1=661791&r2=661792&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/DataSourceFormatter.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/DataSourceFormatter.java Fri May 30 10:18:14 2008
@@ -19,14 +19,29 @@
 
 package org.apache.axis2.jaxws.utility;
 
-import org.apache.axis2.transport.http.ApplicationXMLFormatter;
-import org.apache.axis2.AxisFault;
+import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMOutputFormat;
-
+import org.apache.axiom.om.OMSourcedElement;
+import org.apache.axiom.om.impl.MIMEOutputUtils;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.jaxws.handler.AttachmentsAdapter;
+import org.apache.axis2.jaxws.message.databinding.DataSourceBlock;
+import org.apache.axis2.transport.MessageFormatter;
+import org.apache.axis2.transport.http.ApplicationXMLFormatter;
+import org.apache.axis2.transport.http.util.URLTemplatingUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.ws.handler.MessageContext;
+import java.io.IOException;
 import java.io.OutputStream;
 import java.net.URL;
 
-public class DataSourceFormatter extends ApplicationXMLFormatter {
+public class DataSourceFormatter implements MessageFormatter {
+    private static final Log log = LogFactory.getLog(ApplicationXMLFormatter.class);
     private final String contentType;
 
     public DataSourceFormatter(String contentType) {
@@ -34,22 +49,71 @@
     }
 
     public byte[] getBytes(org.apache.axis2.context.MessageContext messageContext, OMOutputFormat format) throws AxisFault {
-        return super.getBytes(messageContext, format);
+        throw new UnsupportedOperationException("FIXME");
     }
 
     public void writeTo(org.apache.axis2.context.MessageContext messageContext, OMOutputFormat format, OutputStream outputStream, boolean preserve) throws AxisFault {
-        super.writeTo(messageContext, format, outputStream, preserve);
+        AttachmentsAdapter attachments = (AttachmentsAdapter) messageContext.getProperty(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
+        try {
+            if (log.isDebugEnabled()) {
+                log.debug("start writeTo()");
+            }
+            if (attachments != null && !attachments.isEmpty()) {
+                OMElement omElement = messageContext.getEnvelope().getBody().getFirstElement();
+                DataSource busObject;
+                try {
+                    busObject = (DataSource)((DataSourceBlock)((OMSourcedElement) omElement).getDataSource()).getBusinessObject(true);
+                } catch (XMLStreamException e) {
+                    throw AxisFault.makeFault(e);
+                }
+                MIMEOutputUtils.writeDataHandlerWithAttachmentsMessage(
+                        new DataHandler(busObject), 
+                        contentType, 
+                        outputStream, 
+                        attachments, 
+                        format);
+            } else { 
+                    OMElement omElement = messageContext.getEnvelope().getBody().getFirstElement();
+                    if (omElement != null) {
+                        try {
+                            if (preserve) {
+                                omElement.serialize(outputStream, format);
+                            } else {
+                                omElement.serializeAndConsume(outputStream, format);
+                            }
+                        } catch (XMLStreamException e) {
+                            throw AxisFault.makeFault(e);
+                        }
+                    }
+                    try {
+                        outputStream.flush();
+                    } catch (IOException e) {
+                        throw AxisFault.makeFault(e);
+                    }
+            }
+        } finally {
+            if (log.isDebugEnabled()) {
+                log.debug("end writeTo()");
+            }
+        }
     }
 
     public String getContentType(org.apache.axis2.context.MessageContext messageContext, OMOutputFormat format, String soapAction) {
+        AttachmentsAdapter attachments = (AttachmentsAdapter) messageContext.getProperty(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
+        if (attachments != null && !attachments.isEmpty()) {
+            return format.getContentTypeForSwA(contentType);
+        }
         return contentType;
     }
 
     public URL getTargetAddress(org.apache.axis2.context.MessageContext messageContext, OMOutputFormat format, URL targetURL) throws AxisFault {
-        return super.getTargetAddress(messageContext, format, targetURL);
+        // Check whether there is a template in the URL, if so we have to replace then with data
+        // values and create a new target URL.
+        targetURL = URLTemplatingUtil.getTemplatedURL(targetURL, messageContext, false);
+        return targetURL;
     }
 
     public String formatSOAPAction(org.apache.axis2.context.MessageContext messageContext, OMOutputFormat format, String soapAction) {
-        return super.formatSOAPAction(messageContext, format, soapAction);
+        return null;
     }
 }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/DataSourceBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/DataSourceBuilder.java?rev=661792&r1=661791&r2=661792&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/DataSourceBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/DataSourceBuilder.java Fri May 30 10:18:14 2008
@@ -1,24 +1,33 @@
 package org.apache.axis2.builder;
 
 import org.apache.axiom.attachments.utils.IOUtils;
+import org.apache.axiom.attachments.Attachments;
+import org.apache.axiom.attachments.impl.BufferUtils;
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMDataSource;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.impl.OMNamespaceImpl;
+import org.apache.axiom.om.impl.MTOMConstants;
 import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
 import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.axis2.context.MessageContext;
 
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
+import javax.mail.internet.ContentType;
+import javax.mail.internet.ParseException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.Writer;
+import java.io.ByteArrayOutputStream;
 
 public class DataSourceBuilder implements Builder {
 
@@ -26,11 +35,15 @@
                                      MessageContext msgContext)
             throws AxisFault {
         msgContext.setDoingREST(true);
+        
         OMNamespace ns = new OMNamespaceImpl("", "");
         OMFactory factory = OMAbstractFactory.getOMFactory();
         byte[] bytes;
         try {
-            bytes = IOUtils.getStreamAsByteArray(inputStream);
+            ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
+            BufferUtils.inputStream2OutputStream(inputStream, baos);
+            baos.flush();
+            bytes = baos.toByteArray();
         } catch (IOException e) {
             throw AxisFault.makeFault(e);
         }
@@ -70,5 +83,4 @@
             throw new UnsupportedOperationException("FIXME");
         }
     }
-    
 }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/MIMEBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/MIMEBuilder.java?rev=661792&r1=661791&r2=661792&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/MIMEBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/MIMEBuilder.java Fri May 30 10:18:14 2008
@@ -21,12 +21,14 @@
 
 import org.apache.axiom.attachments.Attachments;
 import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.impl.MTOMConstants;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
 import org.apache.axis2.context.MessageContext;
 
-import javax.xml.stream.XMLStreamReader;
+import javax.mail.internet.ContentType;
+import javax.mail.internet.ParseException;
 import java.io.InputStream;
 
 public class MIMEBuilder implements Builder {
@@ -34,7 +36,6 @@
     public OMElement processDocument(InputStream inputStream, String contentType,
                                      MessageContext msgContext)
             throws AxisFault {
-        XMLStreamReader streamReader;
         Attachments attachments =
                 BuilderUtil.createAttachmentsMap(msgContext, inputStream, contentType);
         String charSetEncoding =
@@ -57,11 +58,25 @@
         // by subsequent builders(eg:MTOMBuilder) if needed..
         msgContext.setDoingSwA(true);
         
+        ContentType ct;
+        try {
+            ct = new ContentType(contentType);
+        } catch (ParseException e) {
+            throw new OMException(
+                    "Invalid Content Type Field in the Mime Message"
+                    , e);
+        }
+        
+        String type = ct.getParameter("type");
         Builder builder =
-                BuilderUtil.getBuilderFromSelector(attachments.getAttachmentSpecType(), msgContext);
-        OMElement element = builder.processDocument(attachments.getSOAPPartInputStream(),
-                                                    contentType, msgContext);
-        return element;
+                BuilderUtil.getBuilderFromSelector(type, msgContext);
+        if(MTOMConstants.MTOM_TYPE.equals(type)){
+            String startInfo = ct.getParameter("start-info");
+            if(startInfo != null){
+                type = startInfo;
+            }
+        }
+        return builder.processDocument(attachments.getSOAPPartInputStream(),
+                type, msgContext);
     }
-
 }