You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ng...@apache.org on 2006/09/25 01:53:53 UTC

svn commit: r449525 [1/2] - in /webservices/axis2/trunk/java/modules/jaxws: ./ src/org/apache/axis2/jaxws/ src/org/apache/axis2/jaxws/binding/ src/org/apache/axis2/jaxws/client/ src/org/apache/axis2/jaxws/core/ src/org/apache/axis2/jaxws/core/controlle...

Author: ngallardo
Date: Sun Sep 24 16:53:51 2006
New Revision: 449525

URL: http://svn.apache.org/viewvc?view=rev&rev=449525
Log:
First pass at providing MTOM support in JAX-WS.  

Added:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/binding/SOAPBinding.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/AttachmentUtils.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentUnmarshaller.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/AttachmentImpl.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/attachments/
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/attachments/MTOMSerializationTests.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/MtomSampleTests.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom/
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom/META-INF/
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom/META-INF/services.xml
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom/MtomSample.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom/MtomSampleProvider.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom/MtomSampleService.java
Modified:
    webservices/axis2/trunk/java/modules/jaxws/maven.xml
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/BindingProvider.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/binding/BindingImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/MessageContext.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/EndpointInterfaceDescription.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Attachment.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Block.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Message.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/XMLPart.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/BlockFactoryImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/BlockImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLPartBase.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLPartImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLSpineImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/JAXWSMessageReceiver.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaBeanDispatcher.java
    webservices/axis2/trunk/java/modules/jaxws/test-resources/xsd/samplemtom.xsd
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addressbook/AddressBook.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addressbook/META-INF/AddressBookService.wsdl

Modified: webservices/axis2/trunk/java/modules/jaxws/maven.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/maven.xml?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/maven.xml (original)
+++ webservices/axis2/trunk/java/modules/jaxws/maven.xml Sun Sep 24 16:53:51 2006
@@ -246,6 +246,15 @@
 		  </ant:fileset>
 		</ant:copy>
 		
+		<ant:copy toDir="target/test-classes/services/MtomSampleService/">
+		  <ant:fileset dir="target/test-classes">
+		    <ant:include name="org/apache/axis2/jaxws/sample/mtom/**"/>
+		  </ant:fileset>
+		  <ant:fileset dir="test/org/apache/axis2/jaxws/sample/mtom">
+			<ant:include name="META-INF/**"/>
+          </ant:fileset>
+        </ant:copy>
+		
 		<ant:copy toDir="target/test-classes/services/DocLitNonWrapService/">
 		  <ant:fileset dir="target/test-classes">
 		    <ant:include name="org/apache/axis2/jaxws/sample/nonwrap/**"/>

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/BindingProvider.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/BindingProvider.java?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/BindingProvider.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/BindingProvider.java Sun Sep 24 16:53:51 2006
@@ -1,4 +1,3 @@
-
 /*
  * Copyright 2004,2005 The Apache Software Foundation.
  * Copyright 2006 International Business Machines Corp.
@@ -23,11 +22,13 @@
 
 import javax.xml.ws.Binding;
 
+import org.apache.axis2.jaxws.binding.SOAPBinding;
 
 public class BindingProvider implements javax.xml.ws.BindingProvider {
 
 	protected Map<String, Object> requestContext;
     protected Map<String, Object> responseContext;
+    protected Binding binding;
     
     public BindingProvider() {
         requestContext = new Hashtable<String,Object>();
@@ -37,11 +38,13 @@
         requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, new Boolean(false));
         requestContext.put(BindingProvider.SOAPACTION_USE_PROPERTY, new Boolean(false));
         requestContext.put(BindingProvider.SOAPACTION_URI_PROPERTY, "");
+        
+        //The default Binding is the SOAPBinding
+        binding = new SOAPBinding();
     }
     
     public Binding getBinding() {
-        // TODO 
-        return null;
+        return binding;
     }
 
     public Map<String, Object> getRequestContext() {

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/binding/BindingImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/binding/BindingImpl.java?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/binding/BindingImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/binding/BindingImpl.java Sun Sep 24 16:53:51 2006
@@ -44,6 +44,5 @@
 			handlers = new ArrayList<Handler>();
 		this.handlers = list;
 	}
-
 	
 }

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/binding/SOAPBinding.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/binding/SOAPBinding.java?view=auto&rev=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/binding/SOAPBinding.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/binding/SOAPBinding.java Sun Sep 24 16:53:51 2006
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed 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.binding;
+
+import java.net.URI;
+import java.util.Set;
+
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPFactory;
+
+/**
+ * An implementation of the <link>javax.xml.ws.soap.SOAPBinding</link>
+ * interface.  This is the default binding for JAX-WS, and will exist
+ * for all Dispatch and Dynamic Proxy instances unless the XML/HTTP
+ * Binding is explicitly specificied.
+ */
+public class SOAPBinding extends BindingImpl 
+    implements javax.xml.ws.soap.SOAPBinding {
+
+    private boolean mtomEnabled = false;
+    
+    /*
+     * (non-Javadoc)
+     * @see javax.xml.ws.soap.SOAPBinding#getMessageFactory()
+     */
+    public MessageFactory getMessageFactory() {
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see javax.xml.ws.soap.SOAPBinding#getRoles()
+     */
+    public Set<URI> getRoles() {
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see javax.xml.ws.soap.SOAPBinding#getSOAPFactory()
+     */
+    public SOAPFactory getSOAPFactory() {
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see javax.xml.ws.soap.SOAPBinding#isMTOMEnabled()
+     */
+    public boolean isMTOMEnabled() {
+        return mtomEnabled;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see javax.xml.ws.soap.SOAPBinding#setMTOMEnabled(boolean)
+     */
+    public void setMTOMEnabled(boolean flag) {
+        mtomEnabled = flag;        
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see javax.xml.ws.soap.SOAPBinding#setRoles(java.util.Set)
+     */
+    public void setRoles(Set<URI> set) {
+        
+    }
+
+}

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java Sun Sep 24 16:53:51 2006
@@ -19,11 +19,11 @@
 import java.util.concurrent.Executor;
 import java.util.concurrent.Future;
 
-import javax.xml.namespace.QName;
 import javax.xml.ws.AsyncHandler;
 import javax.xml.ws.Response;
 import javax.xml.ws.WebServiceException;
 import javax.xml.ws.Service.Mode;
+import javax.xml.ws.soap.SOAPBinding;
 
 import org.apache.axis2.client.ServiceClient;
 import org.apache.axis2.jaxws.AxisController;
@@ -114,6 +114,7 @@
         invocationContext.setRequestMessageContext(requestMsgCtx);
         
         Message requestMsg = createMessageFromValue(obj);
+        setupMessageProperties(requestMsg);
         requestMsgCtx.setMessage(requestMsg);
         
         // Copy the properties from the request context into the MessageContext
@@ -150,6 +151,7 @@
         invocationContext.setRequestMessageContext(requestMsgCtx);
        
         Message requestMsg = createMessageFromValue(obj);
+        setupMessageProperties(requestMsg);
         requestMsgCtx.setMessage(requestMsg);
        
         // Copy the properties from the request context into the MessageContext
@@ -180,6 +182,7 @@
         invocationContext.setRequestMessageContext(requestMsgCtx);
         
         Message requestMsg = createMessageFromValue(obj);
+        setupMessageProperties(requestMsg);
         requestMsgCtx.setMessage(requestMsg);
         
         // Copy the properties from the request context into the MessageContext
@@ -258,6 +261,19 @@
 
     public PortData getPort() {
         return port;
+    }
+    
+    /*
+     * Configure any properties that will be needed on the Message
+     */
+    private void setupMessageProperties(Message msg) {
+        // If the user has enabled MTOM on the SOAPBinding, we need
+        // to make sure that gets pushed to the Message object.
+        if (binding != null && binding instanceof SOAPBinding) {
+            SOAPBinding soapBinding = (SOAPBinding) binding;
+            if (soapBinding.isMTOMEnabled())
+                msg.setMTOMEnabled(true);
+        }
     }
 
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/MessageContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/MessageContext.java?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/MessageContext.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/MessageContext.java Sun Sep 24 16:53:51 2006
@@ -76,6 +76,7 @@
             
             message = newMessage;
         }
+
     }
     
     public Map<String, Object> getProperties() {   

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java Sun Sep 24 16:53:51 2006
@@ -16,19 +16,24 @@
  */
 package org.apache.axis2.jaxws.core.controller;
 
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
 
+import javax.activation.DataHandler;
 import javax.xml.namespace.QName;
 import javax.xml.ws.AsyncHandler;
 import javax.xml.ws.Response;
 
 import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.impl.MTOMConstants;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants.Configuration;
 import org.apache.axis2.addressing.AddressingConstants;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.client.OperationClient;
@@ -46,9 +51,12 @@
 import org.apache.axis2.jaxws.i18n.Messages;
 import org.apache.axis2.jaxws.impl.AsyncListener;
 import org.apache.axis2.jaxws.impl.AsyncListenerWrapper;
+import org.apache.axis2.jaxws.message.Attachment;
 import org.apache.axis2.jaxws.message.Message;
 import org.apache.axis2.jaxws.message.MessageException;
+import org.apache.axis2.jaxws.message.attachments.AttachmentUtils;
 import org.apache.axis2.jaxws.message.factory.MessageFactory;
+import org.apache.axis2.jaxws.message.impl.AttachmentImpl;
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
 import org.apache.axis2.jaxws.util.Constants;
 import org.apache.axis2.util.CallbackReceiver;
@@ -114,7 +122,7 @@
         ServiceClient svcClient = ic.getServiceClient();
         OperationClient opClient = createOperationClient(svcClient, operationName);
         
-        setupProperties(requestMsgCtx.getProperties(), opClient.getOptions());
+        setupProperties(requestMsgCtx, opClient.getOptions());
         
         if (opClient != null) {
             // Get the target endpoint address and setup the TO endpoint 
@@ -145,7 +153,10 @@
                 // JAX-WS MessageContext, and set them on the Axis2 MessageContext.
                 axisRequestMsgCtx.setProperty(AbstractContext.COPY_PROPERTIES,
                     Boolean.TRUE);
-                axisRequestMsgCtx.setProperties(requestMsgCtx.getProperties());
+                Map props = axisRequestMsgCtx.getOptions().getProperties();
+                props.putAll(requestMsgCtx.getProperties());
+                
+                axisRequestMsgCtx.getOptions().setProperties(props);
                 if (log.isDebugEnabled()) {
                     log.debug("Properties: " + axisRequestMsgCtx.getProperties().toString());
                 }
@@ -179,6 +190,32 @@
                 // Setup the response MessageContext
                 responseMsgCtx = new MessageContext(axisResponseMsgCtx);
                 responseMsgCtx.setMessage(responseMsg);
+                
+                //FIXME: This should be revisited when we re-work the MTOM support.
+                //This destroys performance by forcing a double pass through the message.
+                //If attachments are found, we must find all of the OMText nodes and 
+                //replace them with <xop:include> elements so they can be processed
+                //correctly by JAXB.
+                if (axisResponseMsgCtx.getProperty(MTOMConstants.ATTACHMENTS) != null) { 
+                    Message response = responseMsgCtx.getMessage();
+                    response.setMTOMEnabled(true);
+                    
+                    ArrayList<OMText> binaryNodes = AttachmentUtils.findBinaryNodes(
+                            axisResponseMsgCtx.getEnvelope());
+                    if (binaryNodes != null) {
+                        Iterator<OMText> itr = binaryNodes.iterator();
+                        while (itr.hasNext()) {
+                            OMText node = itr.next();
+                            OMElement xop = AttachmentUtils.makeXopElement(node);
+                            node.getParent().addChild(xop);
+                            node.detach();
+                            
+                            Attachment a = new AttachmentImpl((DataHandler) node.getDataHandler(), 
+                                    node.getContentID());
+                            response.addAttachment(a);
+                        }
+                    }
+                }
             } catch (AxisFault e) {
                 throw ExceptionFactory.makeWebServiceException(e);
             } catch (MessageException e) { 
@@ -240,7 +277,7 @@
 
         OperationClient opClient = createOperationClient(svcClient, operationName);
         
-        setupProperties(requestMsgCtx.getProperties(), opClient.getOptions());
+        setupProperties(requestMsgCtx, opClient.getOptions());
         
         if (opClient != null) {
             // Get the target endpoint address and setup the TO endpoint 
@@ -269,7 +306,9 @@
                 // JAX-WS MessageContext, and set them on the Axis2 MessageContext.
                 axisRequestMsgCtx.setProperty(AbstractContext.COPY_PROPERTIES,
                     Boolean.TRUE);
-                axisRequestMsgCtx.setProperties(requestMsgCtx.getProperties());
+                Map props = axisRequestMsgCtx.getOptions().getProperties();
+                props.putAll(requestMsgCtx.getProperties());
+                axisRequestMsgCtx.getOptions().setProperties(props);
                 if (log.isDebugEnabled()) {
                     log.debug("Properties: " + axisRequestMsgCtx.getProperties().toString());
                 }
@@ -336,7 +375,7 @@
 
         OperationClient opClient = createOperationClient(svcClient, operationName);
         
-        setupProperties(requestMsgCtx.getProperties(), opClient.getOptions());
+        setupProperties(requestMsgCtx, opClient.getOptions());
         
         if (opClient != null) {
             // Get the target endpoint address and setup the TO endpoint 
@@ -407,7 +446,9 @@
                 // JAX-WS MessageContext, and set them on the Axis2 MessageContext.
                 axisRequestMsgCtx.setProperty(AbstractContext.COPY_PROPERTIES,
                     Boolean.TRUE);
-                axisRequestMsgCtx.setProperties(requestMsgCtx.getProperties());
+                Map props = axisRequestMsgCtx.getOptions().getProperties();
+                props.putAll(requestMsgCtx.getProperties());
+                axisRequestMsgCtx.getOptions().setProperties(props);
                 if (log.isDebugEnabled()) {
                     log.debug("Properties: " + axisRequestMsgCtx.getProperties().toString());
                 }
@@ -537,7 +578,8 @@
      * moved over to when the property is set.  This should not be in the path
      * of performance.
      */
-    private void setupProperties(Map<String, Object> properties, Options ops) {
+    private void setupProperties(MessageContext mc, Options ops) {
+        Map<String, Object> properties = mc.getProperties();
         for (Iterator<String> it = properties.keySet().iterator(); it.hasNext(); ) {
             String key = it.next();
             Object value = properties.get(key);
@@ -553,6 +595,12 @@
             }
             
             ops.setProperty(key, value);
+        }
+        
+        // Enable MTOM
+        Message msg = mc.getMessage();
+        if (msg.isMTOMEnabled()) {
+            ops.setProperty(Configuration.ENABLE_MTOM, "true");
         }
     }
     

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/EndpointInterfaceDescription.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/EndpointInterfaceDescription.java?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/EndpointInterfaceDescription.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/EndpointInterfaceDescription.java Sun Sep 24 16:53:51 2006
@@ -85,7 +85,7 @@
     
     EndpointInterfaceDescription(Class sei, EndpointDescription parent) {
         seiClass = sei;
-
+        
         // Per JSR-181 all methods on the SEI are mapped to operations regardless
         // of whether they include an @WebMethod annotation.  That annotation may
         // be present to customize the mapping, but is not required (p14)
@@ -94,6 +94,8 @@
             OperationDescription operation = new OperationDescription(method, this);
             addOperation(operation);
         }
+        
+        parentEndpointDescription = parent;
     }
     
     private static Method[] getSEIMethods(Class sei) {
@@ -233,6 +235,10 @@
     
     public OperationDescription[] getOperations() {
         return operationDescriptions.toArray(new OperationDescription[0]);
+    }
+    
+    public EndpointDescription getEndpointDescription() {
+        return parentEndpointDescription;
     }
     
     /**

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Attachment.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Attachment.java?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Attachment.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Attachment.java Sun Sep 24 16:53:51 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 The Apache Software Foundation.
  * Copyright 2006 International Business Machines Corp.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,10 +16,33 @@
  */
 package org.apache.axis2.jaxws.message;
 
+import javax.activation.DataHandler;
+
 /**
  * Attachment
- * non-xml portions of the message
+ * 
+ * Used for attaching documents to a Message.  Each Attachment must have a 
+ * uniquie identifier or "contentID".  The actual content of the attachment
+ * is stored in a <link>javax.activation.DataHandler</link>.
  */
 public interface Attachment {
- // PlaceHolder
+    
+    /**
+     * Gets the MIME type for the content of the attachment.
+     * @return contentType
+     */
+    public String getContentType();
+    
+    /**
+     * Gets the contendID that identifies this attachment.
+     * @return contentID
+     */
+    public String getContentID();
+    
+    /**
+     * Gets the actual content of the attachment in a DataHandler form.
+     * @return content
+     */
+    public DataHandler getDataHandler();
+    
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Block.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Block.java?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Block.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Block.java Sun Sep 24 16:53:51 2006
@@ -127,5 +127,16 @@
 	 * @return BlockFactory that created the Block
 	 */
 	public BlockFactory getBlockFactory();
+    
+    /**
+     * Get the XMLPart that contains this Block, if it is attached to one at all.
+     * @return XMLPart that the Block is attached to
+     */
+    public XMLPart getParent();
+    
+    /**
+     * Set the XMLPart that will contain this Block.
+     */
+    public void setParent(XMLPart p);
 	
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Message.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Message.java?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Message.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/Message.java Sun Sep 24 16:53:51 2006
@@ -47,10 +47,27 @@
 	 */
 	public SOAPMessage getAsSOAPMessage() throws MessageException;
 	
-	/**
+    /**
+     * Adds an attachment part to the message
+     * @param Attachment - the content to add
+     */
+	public void addAttachment(Attachment a);
+    
+    /**
 	 * Get the list of attachments for the message
 	 * @return List<Attachments>
 	 */
 	public List<Attachment> getAttachments();
+    
+    /**
+     * Get the attachment identified by the contentID 
+     * @param cid
+     * @return
+     */
+    public Attachment getAttachment(String cid);
+    
+    public boolean isMTOMEnabled();
+    
+    public void setMTOMEnabled(boolean b);
 	
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/XMLPart.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/XMLPart.java?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/XMLPart.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/XMLPart.java Sun Sep 24 16:53:51 2006
@@ -77,7 +77,22 @@
 	 * @return true if the block is consumed (a method was called with consume=true)
 	 */
 	public boolean isConsumed();
-	
+    
+    /**
+     * getParent
+     * Get the Message object that this XMLPart is attached to, if it is 
+     * attached to one at all.
+     * @return
+     */
+    public Message getParent();
+    
+    /**
+     * setParent
+     * Set the Message object that will hold this XMLPart
+     * @param m
+     */
+    public void setParent(Message m);
+    
 	/**
 	 * getAsEnvelope
 	 * Get the xml part as a read/write SOAPEnvelope
@@ -206,5 +221,5 @@
 	 * @return String containing trace information
 	 */
 	public String traceString(String indent);
-	
+    
 }

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/AttachmentUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/AttachmentUtils.java?view=auto&rev=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/AttachmentUtils.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/AttachmentUtils.java Sun Sep 24 16:53:51 2006
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed 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.attachments;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axis2.jaxws.message.Attachment;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * A suite of utilities used for handling MTOM attachment data. 
+ */
+public class AttachmentUtils {
+    
+    private static final Log log = LogFactory.getLog(AttachmentUtils.class);
+    private static final QName XOP_INCLUDE = 
+        new QName("http://www.w3.org/2004/08/xop/include", "Include");
+    
+    /**
+     * Can be used to find all instances of the <pre><xop:include></pre> element 
+     * within a given OM SOAPEnvelope.
+     * @param env
+     * @return
+     */
+    public static ArrayList<OMElement> findXopElements(SOAPEnvelope env) {
+        ArrayList<OMElement> xops = new ArrayList<OMElement>();
+        findXopElements(env, xops);
+        return xops;
+    }
+    
+    /*
+     * A recursive search for all of the <xop:include> elements in the tree.
+     */
+    private static void findXopElements(OMElement root, ArrayList<OMElement> xops) {
+        Iterator itr = root.getChildElements();
+        if (log.isDebugEnabled())
+            log.debug("[subtree] " + root.getLocalName());
+        
+        // If it has no children, then it's a leaf and we need
+        // to check if it's an <xop:include> element.  If not, then
+        // we need to grab each of the children and continue traversing
+        // down the tree.
+        if (itr == null || !itr.hasNext()) {
+            if (log.isDebugEnabled())
+                log.debug("[leaf] " + root.getLocalName());
+            
+            if (root.getQName().equals(XOP_INCLUDE)) {
+                xops.add(root);
+            }
+        }
+        else if (itr != null && itr.hasNext()) {
+            while (itr.hasNext()) {
+                OMElement next = (OMElement) itr.next();
+                findXopElements(next, xops);
+            }
+        }
+    }
+    
+    /**
+     * Can be used to find all of the nodes in a tree that contain binary
+     * content that is targetted for optimization via MTOM.
+     * @param env
+     * @return
+     */
+    public static ArrayList<OMText> findBinaryNodes(SOAPEnvelope env) {
+        ArrayList<OMText> nodes = new ArrayList<OMText>();
+        findBinaryElements(env, nodes);
+        return nodes;
+    }
+    
+    /*
+     * A recursive search for all of the binary, optimized nodes in a tree.
+     */
+    private static void findBinaryElements(OMNode node, ArrayList<OMText> attachments) {
+        // If it's an OMText, then it's essentially a leaf and won't
+        // have any children.  If not, then check to see if it's an OMElement
+        // and continue traversing down.
+        if (node instanceof OMText) {
+            if (log.isDebugEnabled())
+                log.debug("text node found");
+            
+            OMText textNode = (OMText) node;
+            if (textNode.isOptimized()) {
+                if (log.isDebugEnabled())
+                    log.debug("optimized text node found");
+                
+                attachments.add(textNode);
+            }
+        }
+        else if (node instanceof OMElement){
+            OMElement element = (OMElement) node;
+            Iterator itr = element.getChildren();
+            while (itr.hasNext()) {
+                OMNode next = (OMNode) itr.next();
+                findBinaryElements(next, attachments);
+            }
+        }
+    }
+    
+    /**
+     * Given an <pre><xop:include></pre> element, create an OMText element
+     * with the appropriate attachment data.
+     * @param xop
+     * @param data
+     * @return
+     */
+    public static OMText makeBinaryOMNode(OMElement xop, Attachment data) {
+        OMFactory factory = xop.getOMFactory();
+        OMText binaryNode = factory.createOMText(data.getDataHandler(), true);
+        return binaryNode;
+    }
+    
+    /**
+     * Given an OMText node, create it's corresponding <pre><xop:include></pre>
+     * element.
+     */
+    public static OMElement makeXopElement(OMText data) {
+        OMFactory factory = data.getOMFactory();
+        OMElement xop = factory.createOMElement(XOP_INCLUDE, null);
+        xop.addAttribute("href", data.getContentID(), null);
+        return xop;
+    }
+   
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java?view=auto&rev=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java Sun Sep 24 16:53:51 2006
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed 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.attachments;
+
+import javax.activation.DataHandler;
+import javax.xml.bind.attachment.AttachmentMarshaller;
+
+import org.apache.axis2.jaxws.message.Attachment;
+import org.apache.axis2.jaxws.message.Message;
+import org.apache.axis2.jaxws.message.impl.AttachmentImpl;
+import org.apache.axis2.util.UUIDGenerator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * An implementation of the JAXB AttachmentMarshaller that is used to 
+ * handle binary data from JAXB and create populate the appropriate
+ * constructs within the JAX-WS Message Model.
+ */
+public class JAXBAttachmentMarshaller extends AttachmentMarshaller {
+
+    private static final Log log = LogFactory.getLog(JAXBAttachmentMarshaller.class);
+    
+    private Message message;
+    
+    public JAXBAttachmentMarshaller() {
+        super();
+    }
+
+    public void setMessage(Message msg) {
+        message = msg;
+    }
+    
+    @Override
+    public boolean isXOPPackage() {
+        //This should really be set based on whether or not we
+        //the SOAP 1.1 or SOAP 1.2 MTOM binding is set.
+        return true;
+    }
+
+    @Override
+    public String addMtomAttachment(byte[] data, int offset, int length, 
+            String mimeType, String namespace, String localPart) {
+        if (log.isDebugEnabled()) 
+            log.debug("Adding MTOM/XOP attachment for element: " + localPart + "{" + namespace + "}");
+        return UUIDGenerator.getUUID();
+    }
+
+    @Override
+    public String addMtomAttachment(DataHandler data, String namespace, String localPart) {
+        if (log.isDebugEnabled()) 
+            log.debug("Adding MTOM/XOP attachment for element: " + localPart + "{" + namespace + "}");
+        
+        String cid = UUIDGenerator.getUUID();
+        Attachment a = new AttachmentImpl(data, cid);
+        message.addAttachment(a);
+        return cid;
+    }
+
+    @Override
+    public String addSwaRefAttachment(DataHandler arg0) {
+        throw new UnsupportedOperationException("SwaRef attachments are not supported.");
+    }
+    
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentUnmarshaller.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentUnmarshaller.java?view=auto&rev=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentUnmarshaller.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentUnmarshaller.java Sun Sep 24 16:53:51 2006
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed 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.attachments;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.activation.DataHandler;
+import javax.xml.bind.attachment.AttachmentUnmarshaller;
+
+import org.apache.axis2.jaxws.message.Attachment;
+import org.apache.axis2.jaxws.message.Message;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * JAXBAttachmentUnmarshaller
+ * 
+ * An implementation of the <link>javax.xml.bind.attachment.AttachmentUnmarshaller</link>
+ * that is used for deserializing XOP elements into their corresponding
+ * binary data packages.
+ */
+public class JAXBAttachmentUnmarshaller extends AttachmentUnmarshaller {
+
+    private static final Log log = LogFactory.getLog(JAXBAttachmentUnmarshaller.class);
+    
+    private Message message;
+    
+    @Override
+    public boolean isXOPPackage() {
+        //FIXME: This should really be set based on whether or not we
+        //the SOAP 1.1 or SOAP 1.2 MTOM binding is set.
+        return true;
+    }
+    
+    @Override
+    public byte[] getAttachmentAsByteArray(String cid) {
+        if (log.isDebugEnabled())
+            log.debug("Attempting to retreive attachment [" + cid + "] as a byte[]");
+        return null;
+    }
+
+    @Override
+    public DataHandler getAttachmentAsDataHandler(String cid) {
+        if (log.isDebugEnabled())
+            log.debug("Attempting to retreive attachment [" + cid + "] as a DataHandler");
+        
+        List<Attachment> attachments = message.getAttachments();
+        Iterator<Attachment> itr = attachments.iterator();
+        while (itr.hasNext()) {
+            Attachment a = itr.next();
+            if (a.getContentID().equals(cid)) {
+                return a.getDataHandler();
+            }
+        }
+        
+        return null;
+    }
+    
+    /**
+     * Set the message that holds the attachment data.
+     * @param msg
+     */
+    public void setMessage(Message msg) {
+        message = msg;
+    }
+
+}

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java Sun Sep 24 16:53:51 2006
@@ -33,10 +33,16 @@
 
 import org.apache.axiom.om.OMElement;
 import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.message.Message;
 import org.apache.axis2.jaxws.message.MessageException;
+import org.apache.axis2.jaxws.message.XMLPart;
+import org.apache.axis2.jaxws.message.attachments.JAXBAttachmentMarshaller;
+import org.apache.axis2.jaxws.message.attachments.JAXBAttachmentUnmarshaller;
 import org.apache.axis2.jaxws.message.databinding.JAXBBlock;
 import org.apache.axis2.jaxws.message.factory.BlockFactory;
 import org.apache.axis2.jaxws.message.impl.BlockImpl;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * JAXBBlockImpl
@@ -45,6 +51,8 @@
  */
 public class JAXBBlockImpl extends BlockImpl implements JAXBBlock {
 
+    private static final Log log = LogFactory.getLog(JAXBBlockImpl.class);
+    
 	protected static XMLInputFactory inputFactory = XMLInputFactory.newInstance();
 	protected static XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
 	/**
@@ -60,8 +68,6 @@
 				(qName==null) ? getQName(busObject, (JAXBContext) busContext): qName , 
 				factory);
 	}
-	
-	
 
 	/**
 	 * Called by JAXBBlockFactory
@@ -78,9 +84,23 @@
 	protected Object _getBOFromReader(XMLStreamReader reader, Object busContext) throws XMLStreamException, MessageException {
 		try {
 			// Very easy, use the Context to get the Unmarshaller.
-			// Use the marshaller to get the jaxb object
+			// Use the Unmarshaller to get the jaxb object.
 			JAXBContext jc = (JAXBContext) busContext;
-			Unmarshaller u = jc.createUnmarshaller();
+            Unmarshaller u = jc.createUnmarshaller();
+            
+            // If MTOM is enabled, add in the AttachmentUnmarshaller
+            if (isMTOMEnabled()) {
+                if (log.isDebugEnabled()) 
+                    log.debug("Adding JAXBAttachmentUnmarshaller to Unmarshaller");
+                
+                XMLPart xp = getParent();
+                Message msg = xp.getParent();
+                
+                JAXBAttachmentUnmarshaller aum = new JAXBAttachmentUnmarshaller();
+                aum.setMessage(msg);
+                u.setAttachmentUnmarshaller(aum);
+            }
+			
 			Object jaxb = u.unmarshal(reader);
 			setQName(getQName(jaxb, jc));
 			return jaxb;
@@ -119,7 +139,21 @@
 			// Use the marshaller to write the object.  
 			JAXBContext jc = (JAXBContext) busContext;
 			Marshaller m = jc.createMarshaller();
-			m.marshal(busObject, writer);
+            
+			// If MTOM is enabled, add in the AttachmentMarshaller.
+            if (isMTOMEnabled()) {
+                if (log.isDebugEnabled())
+                    log.debug("Adding JAXBAttachmentMarshaller to Marshaller");
+                
+                XMLPart xp = getParent();
+                Message msg = xp.getParent();
+                
+                JAXBAttachmentMarshaller am = new JAXBAttachmentMarshaller();
+                am.setMessage(msg);
+                m.setAttachmentMarshaller(am);
+            }
+                        
+            m.marshal(busObject, writer);
 		} catch(JAXBException je) {
 			// TODO NLS
 			throw ExceptionFactory.makeMessageException(je);
@@ -136,4 +170,15 @@
 		JAXBIntrospector jbi = jbc.createJAXBIntrospector();
 		return jbi.getElementName(jaxb);
 	}
+    
+    private boolean isMTOMEnabled() {
+        XMLPart xp = getParent();
+        if (xp != null) {
+            Message msg = xp.getParent();
+            if (msg != null && msg.isMTOMEnabled())
+                return true;
+        }
+        
+        return false;
+    }
 }

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/AttachmentImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/AttachmentImpl.java?view=auto&rev=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/AttachmentImpl.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/AttachmentImpl.java Sun Sep 24 16:53:51 2006
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed 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.impl;
+
+import javax.activation.DataHandler;
+
+import org.apache.axis2.jaxws.message.Attachment;
+
+/**
+ * 
+ */
+public class AttachmentImpl implements Attachment {
+    private DataHandler data;
+    private String contentType;
+    private String cid;
+    
+    public AttachmentImpl(DataHandler dh, String id) {
+        data = dh;
+        cid = id;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.axis2.jaxws.message.Attachment#getContentType()
+     */
+    public String getContentType() {
+        if (contentType == null)
+            contentType = data.getContentType();
+        
+        return contentType;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.axis2.jaxws.message.Attachment#getContentID()
+     */
+    public String getContentID() {
+        return cid;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.axis2.jaxws.message.Attachment#getDataHandler()
+     */
+    public DataHandler getDataHandler() {
+        return data;
+    }
+}

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/BlockFactoryImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/BlockFactoryImpl.java?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/BlockFactoryImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/BlockFactoryImpl.java Sun Sep 24 16:53:51 2006
@@ -56,7 +56,9 @@
 		if (other.isQNameAvailable()) {
 			qName = other.getQName();
 		}
-		return createFrom(other.getXMLStreamReader(true), context, qName);
+		Block newBlock = createFrom(other.getXMLStreamReader(true), context, qName);
+        newBlock.setParent(other.getParent());
+        return newBlock;
 	}
 
 	public Block createFrom(XMLStreamReader reader, Object context, QName qName) throws XMLStreamException {

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/BlockImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/BlockImpl.java?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/BlockImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/BlockImpl.java Sun Sep 24 16:53:51 2006
@@ -27,6 +27,7 @@
 import org.apache.axis2.jaxws.i18n.Messages;
 import org.apache.axis2.jaxws.message.Block;
 import org.apache.axis2.jaxws.message.MessageException;
+import org.apache.axis2.jaxws.message.XMLPart;
 import org.apache.axis2.jaxws.message.factory.BlockFactory;
 import org.apache.axis2.jaxws.message.util.Reader2Writer;
 
@@ -57,6 +58,7 @@
 	private QName qName;
 	private BlockFactory factory;
 	private boolean consumed = false;
+    private XMLPart parent;
 	
 	/**
 	 * A Block has the following components
@@ -99,7 +101,15 @@
 	public Object getBusinessContext() {
 		return busContext;
 	}
-
+    
+    public XMLPart getParent() {
+        return parent;
+    }
+    
+    public void setParent(XMLPart p) {
+        parent = p;
+    }
+     
 	/* (non-Javadoc)
 	 * @see org.apache.axis2.jaxws.message.Block#getBusinessObject(boolean)
 	 */

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageImpl.java?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageImpl.java Sun Sep 24 16:53:51 2006
@@ -18,6 +18,7 @@
 
 import java.io.ByteArrayInputStream;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
 import javax.xml.soap.MessageFactory;
@@ -53,6 +54,7 @@
 	Protocol protocol = Protocol.unknown; // the protocol, defaults to unknown
 	XMLPart xmlPart = null; // the representation of the xmlpart
 	List<Attachment> attachments = new ArrayList<Attachment>(); // non-xml parts
+    boolean mtomEnabled;
 	
 	/**
 	 * MessageImpl should be constructed via the MessageFactory.
@@ -70,6 +72,7 @@
 		}
 		XMLPartFactory factory = (XMLPartFactory) FactoryRegistry.getFactory(XMLPartFactory.class);
 		xmlPart = factory.create(protocol);
+        xmlPart.setParent(this);
 	}
 	
 	/**
@@ -81,6 +84,7 @@
 		XMLPartFactory factory = (XMLPartFactory) FactoryRegistry.getFactory(XMLPartFactory.class);
 		xmlPart = factory.createFrom(root);
 		protocol = xmlPart.getProtocol();
+        xmlPart.setParent(this);
 	}
 	
 	/**
@@ -92,6 +96,7 @@
 		XMLPartFactory factory = (XMLPartFactory) FactoryRegistry.getFactory(XMLPartFactory.class);
 		xmlPart = factory.createFrom(root);
 		protocol = xmlPart.getProtocol();
+        xmlPart.setParent(this);
 	}
 
 	/* (non-Javadoc)
@@ -149,6 +154,23 @@
 	public List<Attachment> getAttachments() {
 		return attachments;
 	}
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.axis2.jaxws.message.Message#getAttachment(java.lang.String)
+     */
+    public Attachment getAttachment(String cid) {
+        if (attachments != null) {
+           Iterator<Attachment> itr = attachments.iterator();
+           while (itr.hasNext()) {
+               Attachment a = itr.next();
+               if (a.getContentID().equals(cid))
+                   return a;
+           }
+       }
+        
+       return null;
+    }
 
 	/* (non-Javadoc)
 	 * @see org.apache.axis2.jaxws.message.XMLPart#getProtocol()
@@ -202,7 +224,7 @@
 	}
 
 	public void setBodyBlock(int index, Block block) throws MessageException {
-		xmlPart.setBodyBlock(index, block);
+        xmlPart.setBodyBlock(index, block);
 	}
 
 	public void setHeaderBlock(String namespace, String localPart, Block block) throws MessageException {
@@ -212,4 +234,28 @@
 	public String traceString(String indent) {
 		return xmlPart.traceString(indent);
 	}
+    
+    public void addAttachment(Attachment data) {
+        attachments.add(data);
+    }
+    
+    //FIXME: This doesn't make much sense, but has to be here because Message extends
+    //XMLPart.  
+    public Message getParent() {
+        throw new UnsupportedOperationException();
+    }
+    
+    //FIXME: This doesn't make much sense, but has to be here because Message extends
+    //XMLPart.  
+    public void setParent(Message msg) { 
+        throw new UnsupportedOperationException();
+    }
+    
+    public boolean isMTOMEnabled() {
+        return mtomEnabled;
+    }
+    
+    public void setMTOMEnabled(boolean b) {
+        mtomEnabled = b;
+    }
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLPartBase.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLPartBase.java?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLPartBase.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLPartBase.java Sun Sep 24 16:53:51 2006
@@ -29,6 +29,7 @@
 import org.apache.axis2.jaxws.ExceptionFactory;
 import org.apache.axis2.jaxws.i18n.Messages;
 import org.apache.axis2.jaxws.message.Block;
+import org.apache.axis2.jaxws.message.Message;
 import org.apache.axis2.jaxws.message.MessageException;
 import org.apache.axis2.jaxws.message.MessageInternalException;
 import org.apache.axis2.jaxws.message.Protocol;
@@ -88,6 +89,8 @@
 	static final int SOAPENVELOPE = 2;
 	static final int SPINE = 3;
 	boolean consumed = false;
+    
+    Message parent;
 	
 	
 	/**
@@ -204,7 +207,8 @@
 		default:
 			throw ExceptionFactory.makeMessageInternalException(Messages.getMessage("XMLPartImplErr2"), null);
 		}
-		setContent(spine, SPINE);
+		spine.setParent(parent);
+        setContent(spine, SPINE);
 		return spine;
 	}
 	
@@ -317,7 +321,22 @@
 	public void setHeaderBlock(String namespace, String localPart, Block block) throws MessageException {
 		getContentAsXMLSpine().setHeaderBlock(namespace, localPart, block);
 	}
-
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.axis2.jaxws.message.XMLPart#getParent()
+     */
+    public Message getParent() {
+        return parent;
+    }
+
+    /*
+     * Set the backpointer to this XMLPart's parent Message
+     */
+    public void setParent(Message p) {
+        parent = p;
+    }
+    
 	/**
 	 * Convert SOAPEnvelope into an OM tree
 	 * @param se SOAPEnvelope

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLPartImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLPartImpl.java?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLPartImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLPartImpl.java Sun Sep 24 16:53:51 2006
@@ -16,13 +16,24 @@
  */
 package org.apache.axis2.jaxws.message.impl;
 
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
 import javax.xml.soap.SOAPEnvelope;
 import javax.xml.stream.XMLStreamReader;
 
+import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMText;
 import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
+import org.apache.axis2.jaxws.message.Attachment;
+import org.apache.axis2.jaxws.message.Message;
 import org.apache.axis2.jaxws.message.MessageException;
 import org.apache.axis2.jaxws.message.Protocol;
+import org.apache.axis2.jaxws.message.attachments.AttachmentUtils;
 import org.apache.axis2.jaxws.message.factory.SAAJConverterFactory;
 import org.apache.axis2.jaxws.message.util.SAAJConverter;
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
@@ -82,6 +93,33 @@
 		StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(reader, null);  
 		// Create and return the OM Envelope
 		org.apache.axiom.soap.SOAPEnvelope omEnvelope = builder.getSOAPEnvelope();
+        
+        // If we have MTOM attachments, we need to replace the <xop:include>
+        // elements with OMText binary nodes.
+        Message msg = getParent();
+        if (msg.isMTOMEnabled()) {
+            // First find all of the <xop:include> elements
+            ArrayList<OMElement> xops = AttachmentUtils.findXopElements(omEnvelope);
+            
+            if (xops != null) {
+                QName href = new QName("","href");
+                Iterator<OMElement> itr = xops.iterator();
+                while (itr.hasNext()) {
+                    OMElement xop = itr.next();
+                    String cid = xop.getAttributeValue(href);
+                    
+                    // Then find their corresponding Attachment object
+                    Attachment a = msg.getAttachment(cid);
+                    
+                    // Convert the <xop:include> OMElement into an OMText
+                    // binary node and replace it in the tree.                    
+                    OMText binaryNode = AttachmentUtils.makeBinaryOMNode(xop, a);
+                    xop.insertSiblingAfter(binaryNode);
+                    xop.detach();
+                }
+            }
+        }
+        
 		return omEnvelope;
 	}
 

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLSpineImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLSpineImpl.java?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLSpineImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLSpineImpl.java Sun Sep 24 16:53:51 2006
@@ -38,6 +38,7 @@
 import org.apache.axis2.jaxws.ExceptionFactory;
 import org.apache.axis2.jaxws.i18n.Messages;
 import org.apache.axis2.jaxws.message.Block;
+import org.apache.axis2.jaxws.message.Message;
 import org.apache.axis2.jaxws.message.MessageException;
 import org.apache.axis2.jaxws.message.MessageInternalException;
 import org.apache.axis2.jaxws.message.Protocol;
@@ -70,6 +71,7 @@
 	private List<Block> detailBlocks = new ArrayList<Block>();
 	private boolean consumed = false;
 	private Iterator bodyIterator = null;
+    private Message parent;
 
 	/**
 	 * Create a lightweight representation of this protocol
@@ -163,8 +165,9 @@
 					throw ExceptionFactory.makeMessageException(xse);
 				}
 				blocks.add(block);
+                block.setParent(this);
 			} else {
-				// Non-elements are ignored
+				System.out.println("NON-ELEMENT FOUND: " +  node.getClass().getName());
 			}
 		}
 	}
@@ -196,6 +199,21 @@
 	public Protocol getProtocol() {
 		return protocol;
 	}
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.axis2.jaxws.message.XMLPart#getParent()
+     */
+    public Message getParent() {
+        return parent;
+    }
+    
+    /*
+     * Set the backpointer to this XMLPart's parent Message
+     */
+    public void setParent(Message p) {
+        parent = p;
+    }
 
 	/* (non-Javadoc)
 	 * @see org.apache.axis2.jaxws.message.XMLPart#outputTo(javax.xml.stream.XMLStreamWriter, boolean)
@@ -261,6 +279,7 @@
 			advanceIterator(bodyIterator, bodyBlocks, true);
 		}
 		bodyBlocks.add(index, block);
+        block.setParent(this);
 	}
 
 	public void removeBodyBlock(int index) throws MessageException {
@@ -293,6 +312,7 @@
 	public void setHeaderBlock(String namespace, String localPart, Block block) throws MessageException {
 		int index = getHeaderBlockIndex(namespace, localPart);
 		headerBlocks.set(index, block);
+        block.setParent(this);
 	}
 
 	/**

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/JAXWSMessageReceiver.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/JAXWSMessageReceiver.java?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/JAXWSMessageReceiver.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/JAXWSMessageReceiver.java Sun Sep 24 16:53:51 2006
@@ -17,8 +17,21 @@
 
 package org.apache.axis2.jaxws.server;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Hashtable;
+import java.util.Iterator;
+
+import javax.activation.DataHandler;
+
+import org.apache.axiom.attachments.Attachments;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.impl.MTOMConstants;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants.Configuration;
+import org.apache.axis2.client.Options;
 import org.apache.axis2.context.OperationContext;
 import org.apache.axis2.description.AxisOperation;
 import org.apache.axis2.description.AxisService;
@@ -28,9 +41,11 @@
 import org.apache.axis2.jaxws.core.InvocationContext;
 import org.apache.axis2.jaxws.core.InvocationContextImpl;
 import org.apache.axis2.jaxws.core.MessageContext;
-import org.apache.axis2.jaxws.description.ServiceDescription;
 import org.apache.axis2.jaxws.i18n.Messages;
+import org.apache.axis2.jaxws.message.Attachment;
 import org.apache.axis2.jaxws.message.Message;
+import org.apache.axis2.jaxws.message.attachments.AttachmentUtils;
+import org.apache.axis2.jaxws.message.impl.AttachmentImpl;
 import org.apache.axis2.jaxws.util.Constants;
 import org.apache.axis2.util.ThreadContextMigratorUtil;
 import org.apache.axis2.wsdl.WSDLConstants.WSDL20_2004Constants;
@@ -84,8 +99,41 @@
             //TODO: More work needed to determine the lifecycle of this thing
         	EndpointController endpointCtlr = new EndpointController();
           	
-            InvocationContext ic = new InvocationContextImpl();
             MessageContext requestMsgCtx = new MessageContext(axisRequestMsgCtx);
+            
+            //FIXME: This should be revisited when we re-work the MTOM support.
+            //This destroys performance by forcing a double pass through the message.
+            //If attachments are found on the MessageContext, then that means
+            //the inbound message has more than just the normal XML payload
+            Attachments as = (Attachments) axisRequestMsgCtx.getProperty(MTOMConstants.ATTACHMENTS); 
+            if (as != null) { 
+                Message request = requestMsgCtx.getMessage();
+                request.setMTOMEnabled(true);
+                
+                //Walk the tree and find all of the optimized binary nodes.
+                ArrayList<OMText> binaryNodes = AttachmentUtils.findBinaryNodes(
+                        axisRequestMsgCtx.getEnvelope());
+                if (binaryNodes != null) {
+                    //Replace each of the nodes with it's corresponding <xop:include>
+                    //element, so JAXB can process it correctly.
+                    Iterator<OMText> itr = binaryNodes.iterator();
+                    while (itr.hasNext()) {
+                        OMText node = itr.next();
+                        OMElement xop = AttachmentUtils.makeXopElement(node);
+                        node.getParent().addChild(xop);
+                        node.detach();
+                        
+                        //We have to add the individual attachments in their raw
+                        //binary form, so we can access them later.
+                        Attachment a = new AttachmentImpl((DataHandler) node.getDataHandler(), 
+                                node.getContentID());
+                        request.addAttachment(a);
+                    }
+                }
+            }
+            
+
+            InvocationContext ic = new InvocationContextImpl();            
             ic.setRequestMessageContext(requestMsgCtx);
             
             //TODO:Once we the JAX-WS MessageContext one of the next things that
@@ -109,6 +157,11 @@
                 Message responseMsg = responseMsgCtx.getMessage();
                 SOAPEnvelope responseEnv = (SOAPEnvelope) responseMsg.getAsOMElement();
                 axisResponseMsgCtx.setEnvelope(responseEnv);
+                
+                if (responseMsg.isMTOMEnabled()) {
+                    Options opts = axisResponseMsgCtx.getOptions();
+                    opts.setProperty(Configuration.ENABLE_MTOM, "true");                    
+                }
                 
                 OperationContext opCtx = axisResponseMsgCtx.getOperationContext();
                 opCtx.addMessageContext(axisResponseMsgCtx);

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaBeanDispatcher.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaBeanDispatcher.java?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaBeanDispatcher.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaBeanDispatcher.java Sun Sep 24 16:53:51 2006
@@ -17,37 +17,19 @@
 package org.apache.axis2.jaxws.server.dispatcher;
 
 import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.jws.WebParam;
-import javax.jws.WebResult;
-import javax.jws.soap.SOAPBinding;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.namespace.QName;
-import javax.xml.ws.RequestWrapper;
-
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.description.Parameter;
-import org.apache.axis2.jaxws.ExceptionFactory;
+
+import javax.xml.ws.soap.SOAPBinding;
+
 import org.apache.axis2.jaxws.core.MessageContext;
 import org.apache.axis2.jaxws.core.util.MessageContextUtils;
-import org.apache.axis2.jaxws.description.DescriptionFactory;
 import org.apache.axis2.jaxws.description.EndpointDescription;
 import org.apache.axis2.jaxws.description.EndpointInterfaceDescription;
 import org.apache.axis2.jaxws.description.OperationDescription;
 import org.apache.axis2.jaxws.description.ServiceDescription;
 import org.apache.axis2.jaxws.message.Block;
 import org.apache.axis2.jaxws.message.Message;
-import org.apache.axis2.jaxws.message.factory.BlockFactory;
-import org.apache.axis2.jaxws.message.factory.JAXBBlockFactory;
 import org.apache.axis2.jaxws.message.factory.MessageFactory;
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
-import org.apache.axis2.jaxws.wrapper.JAXBWrapperTool;
-import org.apache.axis2.jaxws.wrapper.impl.JAXBWrapperToolImpl;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -105,10 +87,22 @@
                 MessageFactory.class);
         Message message = factory.create(mc.getMessage().getProtocol());
         message.setBodyBlock(0, responseBlock);
-
+        
         MessageContext responseMsgCtx = MessageContextUtils.createMessageMessageContext(mc);
         responseMsgCtx.setMessage(message);
         
+        //Enable MTOM if necessary
+        EndpointInterfaceDescription epInterfaceDesc = opDesc.getEndpointInterfaceDescription();
+        EndpointDescription epDesc = epInterfaceDesc.getEndpointDescription();
+        
+        String bindingType = epDesc.getBindingTypeValue();
+        if (bindingType != null) {
+            if (bindingType.equals(SOAPBinding.SOAP11HTTP_MTOM_BINDING) ||
+                bindingType.equals(SOAPBinding.SOAP12HTTP_MTOM_BINDING)) {
+                message.setMTOMEnabled(true);
+            }
+        }
+         
         return responseMsgCtx;
     }
     

Modified: webservices/axis2/trunk/java/modules/jaxws/test-resources/xsd/samplemtom.xsd
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test-resources/xsd/samplemtom.xsd?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test-resources/xsd/samplemtom.xsd (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test-resources/xsd/samplemtom.xsd Sun Sep 24 16:53:51 2006
@@ -30,5 +30,22 @@
           </xs:sequence>
        </xs:complexType>
     </xs:element>
+    
+    <xs:element name="sendText">
+       <xs:complexType>
+          <xs:sequence>
+             <xs:element nillable="false" name="input" 
+                type="xs:base64Binary" xmime:expectedContentType="text/xml"/>
+          </xs:sequence>
+       </xs:complexType>
+    </xs:element>
+    
+    <xs:element name="sendTextResponse">
+       <xs:complexType>
+          <xs:sequence>
+             <xs:element minOccurs="0" maxOccurs="1" name="output" type="tns:ImageDepot"/>
+          </xs:sequence>
+       </xs:complexType>
+    </xs:element>
 
 </xs:schema>

Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/attachments/MTOMSerializationTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/attachments/MTOMSerializationTests.java?view=auto&rev=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/attachments/MTOMSerializationTests.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/attachments/MTOMSerializationTests.java Sun Sep 24 16:53:51 2006
@@ -0,0 +1,169 @@
+package org.apache.axis2.jaxws.attachments;
+
+import java.awt.Image;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.imageio.ImageIO;
+import javax.imageio.stream.FileImageInputStream;
+import javax.imageio.stream.ImageInputStream;
+import javax.xml.bind.JAXBContext;
+
+import junit.framework.TestCase;
+
+import org.apache.axiom.om.OMAbstractFactory;
+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.OMText;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
+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.JAXBBlockFactory;
+import org.apache.axis2.jaxws.message.factory.MessageFactory;
+import org.apache.axis2.jaxws.provider.DataSourceImpl;
+import org.apache.axis2.jaxws.registry.FactoryRegistry;
+import org.test.mtom.ImageDepot;
+import org.test.mtom.ObjectFactory;
+import org.test.mtom.SendImage;
+
+public class MTOMSerializationTests extends TestCase {
+
+    private DataSource imageDS;
+    
+    public void setUp() throws Exception {
+        String imageResourceDir = "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);
+    }
+    
+    public MTOMSerializationTests(String name) {
+        super(name);
+    }
+    
+    /*
+     * Simulate building up an OM that is sourced from JAXB and contains
+     * binary data that should be optimized when serialized.  
+     */
+    public void testPlainOMSerialization() throws Exception {
+        System.out.println("---------------------------------------");
+        System.out.println("test: " + getName());
+        
+        OMElement payload = createPayload();
+        
+        OMOutputFormat format = new OMOutputFormat();
+        format.setDoOptimize(true);
+        format.setSOAP11(true);
+               
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        payload.serializeAndConsume(baos, format);
+        
+        System.out.println("==================================");
+        System.out.println(baos.toString());
+        System.out.println("==================================");
+    }
+    
+    /*
+     * Simulate building up an OM SOAPEnvelope that has the contents of
+     * the body sourced from JAXB and contains binary data that should be 
+     * optimized when serialized.  
+     */
+    public void testSoapOMSerialization() throws Exception {
+        System.out.println("---------------------------------------");
+        System.out.println("test: " + getName());
+        
+        OMElement payload = createPayload();
+        
+        SOAPFactory factory = new SOAP11Factory();
+        SOAPEnvelope env = factory.createSOAPEnvelope();
+        SOAPBody body = factory.createSOAPBody(env);
+        
+        body.addChild(payload);
+        
+        OMOutputFormat format = new OMOutputFormat();
+        format.setDoOptimize(true);
+        format.setSOAP11(true);
+               
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        env.serializeAndConsume(baos, format);
+        
+        System.out.println("==================================");
+        System.out.println(baos.toString());
+        System.out.println("==================================");
+    }
+    
+    public void testMTOMAttachmentWriter() throws Exception {
+        System.out.println("---------------------------------------");
+        System.out.println("test: " + getName());
+        
+        //Create a DataHandler with the String DataSource object
+        DataHandler dataHandler = new DataHandler(imageDS);
+                        
+        //Store the data handler in ImageDepot bean
+        ImageDepot imageDepot = new ObjectFactory().createImageDepot();
+        imageDepot.setImageData(dataHandler);
+        
+        JAXBContext jbc = JAXBContext.newInstance("org.test.mtom");
+        
+        //Create a request bean with imagedepot bean as value
+        ObjectFactory factory = new ObjectFactory();
+        SendImage request = factory.createSendImage();
+        request.setInput(imageDepot);
+        
+        BlockFactory blkFactory = (JAXBBlockFactory) FactoryRegistry.getFactory(JAXBBlockFactory.class);
+        Block block = blkFactory.createFrom(request, jbc, null);
+        
+        MessageFactory msgFactory = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
+        Message msg = msgFactory.create(Protocol.soap11);
+        
+        msg.setBodyBlock(0, block);
+        
+        msg.setMTOMEnabled(true);
+        
+        SOAPEnvelope soapOM = (SOAPEnvelope) msg.getAsOMElement();
+        
+        OMOutputFormat format = new OMOutputFormat();
+        format.setDoOptimize(true);
+        format.setSOAP11(true);
+               
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        soapOM.serializeAndConsume(baos, format);
+        
+        System.out.println("==================================");
+        System.out.println(baos.toString());
+        System.out.println("==================================");
+    }
+    
+    private OMElement createPayload() {
+        //Create a DataHandler with the String DataSource object
+        DataHandler dataHandler = new DataHandler(imageDS);
+                        
+        OMFactory fac = OMAbstractFactory.getOMFactory();
+        OMNamespace omNs = fac.createOMNamespace("urn://mtom.test.org", "mtom");
+        
+        OMElement sendImage = fac.createOMElement("sendImage", omNs);
+        
+        OMElement input = fac.createOMElement("input", omNs);
+        sendImage.addChild(input);
+        
+        OMElement imageData = fac.createOMElement("imageData", omNs);
+        input.addChild(imageData);
+        
+        OMText binaryData = fac.createOMText(dataHandler, true);
+        imageData.addChild(binaryData);
+        
+        return sendImage;
+    }
+}

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java Sun Sep 24 16:53:51 2006
@@ -22,6 +22,7 @@
 import junit.framework.TestSuite;
 
 import org.apache.axis2.jaxws.DispatchTestSuite;
+import org.apache.axis2.jaxws.attachments.MTOMSerializationTests;
 import org.apache.axis2.jaxws.description.AnnotationDescriptionTests;
 import org.apache.axis2.jaxws.description.AnnotationProviderImplDescriptionTests;
 import org.apache.axis2.jaxws.description.AnnotationServiceImplDescriptionTests;
@@ -40,6 +41,7 @@
 import org.apache.axis2.jaxws.provider.*;
 import org.apache.axis2.jaxws.sample.AddNumbersTests;
 import org.apache.axis2.jaxws.sample.AddressBookTests;
+import org.apache.axis2.jaxws.sample.MtomSampleTests;
 import org.apache.axis2.jaxws.sample.NonWrapTests;
 import org.apache.axis2.jaxws.sample.WrapTests;
 import org.apache.axis2.proxy.ProxyNonWrappedTests;
@@ -62,6 +64,7 @@
         suite.addTestSuite(SAAJConverterTests.class);
         suite.addTestSuite(XMLStreamReaderSplitterTests.class);
         suite.addTestSuite(SOAP12Tests.class);
+        suite.addTestSuite(MTOMSerializationTests.class);
         
         suite.addTestSuite(WSDLTests.class);
         suite.addTestSuite(ServiceDescriptionTests.class);
@@ -84,6 +87,7 @@
         suite.addTestSuite(ExceptionFactoryTests.class);
 
         suite.addTestSuite(AddressBookTests.class);
+        suite.addTestSuite(MtomSampleTests.class);
         suite.addTestSuite(NonWrapTests.class);
         suite.addTestSuite(WrapTests.class);
         suite.addTestSuite(AddNumbersTests.class);

Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/MtomSampleTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/MtomSampleTests.java?view=auto&rev=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/MtomSampleTests.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/MtomSampleTests.java Sun Sep 24 16:53:51 2006
@@ -0,0 +1,72 @@
+package org.apache.axis2.jaxws.sample;
+
+import java.awt.Image;
+import java.io.File;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.imageio.ImageIO;
+import javax.imageio.stream.FileImageInputStream;
+import javax.imageio.stream.ImageInputStream;
+import javax.xml.bind.JAXBContext;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+import javax.xml.ws.Service.Mode;
+import javax.xml.ws.soap.SOAPBinding;
+
+import junit.framework.TestCase;
+
+import org.apache.axis2.jaxws.provider.DataSourceImpl;
+import org.test.mtom.ImageDepot;
+import org.test.mtom.ObjectFactory;
+import org.test.mtom.SendImage;
+import org.test.mtom.SendImageResponse;
+
+public class MtomSampleTests extends TestCase {
+
+    private static final QName QNAME_SERVICE = new QName("urn://mtom.test.org", "MtomSampleService");
+    private static final QName QNAME_PORT    = new QName("urn://mtom.test.org", "MtomSample");
+    private static final String URL_ENDPOINT = "http://localhost:8080/axis2/services/MtomSampleService";
+    
+    public void testSendImageAttachment() throws Exception {
+        System.out.println("----------------------------------");
+        System.out.println("test: " + getName());
+        
+        String imageResourceDir = "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);
+        DataSource imageDS = new DataSourceImpl("image/jpeg","test.jpg",image);
+        
+        //Create a DataHandler with the String DataSource object
+        DataHandler dataHandler = new DataHandler(imageDS);
+        
+        //Store the data handler in ImageDepot bean
+        ImageDepot imageDepot = new ObjectFactory().createImageDepot();
+        imageDepot.setImageData(dataHandler);
+        
+        SendImage request = new ObjectFactory().createSendImage();
+        request.setInput(imageDepot);
+        
+        //Create the necessary JAXBContext
+        JAXBContext jbc = JAXBContext.newInstance("org.test.mtom");
+        
+        // Create the JAX-WS client needed to send the request
+        Service service = Service.create(QNAME_SERVICE);
+        service.addPort(QNAME_PORT, SOAPBinding.SOAP11HTTP_BINDING, URL_ENDPOINT);
+        Dispatch<Object> dispatch = service.createDispatch(
+                QNAME_PORT, jbc, Mode.PAYLOAD);
+        
+        SOAPBinding binding = (SOAPBinding) dispatch.getBinding();
+        binding.setMTOMEnabled(true);
+        
+        SendImageResponse response = (SendImageResponse) dispatch.invoke(request);
+        
+        assertNotNull(response);
+        assertNotNull(response.getOutput().getImageData());
+    }
+    
+}

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addressbook/AddressBook.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addressbook/AddressBook.java?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addressbook/AddressBook.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addressbook/AddressBook.java Sun Sep 24 16:53:51 2006
@@ -23,7 +23,9 @@
 import javax.xml.ws.RequestWrapper;
 import javax.xml.ws.ResponseWrapper;
 
-@WebService(name = "AddressBook", targetNamespace = "http://org/apache/axis2/jaxws/sample/addressbook", wsdlLocation = "\\work\\apps\\eclipse\\workspace\\axis2\\modules\\jaxws\\test\\org\\apache\\axis2\\jaxws\\sample\\addressbook\\META-INF\\AddressBookService.wsdl")
+@WebService(name = "AddressBook", 
+            targetNamespace = "http://org/apache/axis2/jaxws/sample/addressbook", 
+            wsdlLocation = "\\work\\apps\\eclipse\\workspace\\axis2\\modules\\jaxws\\test\\org\\apache\\axis2\\jaxws\\sample\\addressbook\\META-INF\\AddressBookService.wsdl")
 public interface AddressBook {
 
 

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addressbook/META-INF/AddressBookService.wsdl
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addressbook/META-INF/AddressBookService.wsdl?view=diff&rev=449525&r1=449524&r2=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addressbook/META-INF/AddressBookService.wsdl (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addressbook/META-INF/AddressBookService.wsdl Sun Sep 24 16:53:51 2006
@@ -60,7 +60,7 @@
      </schema>
    </wsdl:types>
  
- <wsdl:message name="addEntryRequest">
+  <wsdl:message name="addEntryRequest">
     <wsdl:part element="impl:addEntry" name="parameters"/>
   </wsdl:message>
  

Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom/META-INF/services.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom/META-INF/services.xml?view=auto&rev=449525
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom/META-INF/services.xml (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom/META-INF/services.xml Sun Sep 24 16:53:51 2006
@@ -0,0 +1,11 @@
+<serviceGroup>
+ <service name="MtomSampleService">
+  <messageReceivers>
+   <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.jaxws.server.JAXWSMessageReceiver"/>
+  </messageReceivers>
+  <parameter locked="false" name="ServiceClass">org.apache.axis2.jaxws.sample.mtom.MtomSampleService</parameter>
+  <operation name="sendImage" mep="http://www.w3.org/2004/08/wsdl/in-out">
+    <actionMapping/>
+  </operation>
+ </service>
+</serviceGroup>



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org