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 sc...@apache.org on 2006/10/27 23:15:20 UTC

svn commit: r468546 - in /webservices/axis2/trunk/java/modules/jaxws: src/javax/xml/ws/spi/ src/org/apache/axis2/jaxws/ src/org/apache/axis2/jaxws/client/ src/org/apache/axis2/jaxws/core/ src/org/apache/axis2/jaxws/core/controller/ src/org/apache/axis2...

Author: scheu
Date: Fri Oct 27 14:15:19 2006
New Revision: 468546

URL: http://svn.apache.org/viewvc?view=rev&rev=468546
Log:
AXIS2-1536
JAX-WS Attachment work
Contributor:Rich Scheuerle

Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/javax/xml/ws/spi/FactoryFinder.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/AxisCallback.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/XMLDispatch.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/core/util/MessageContextUtils.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/EndpointDescription.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/Message.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/impl/AttachmentImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageFactoryImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/MessageUtils.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/JAXWSMessageReceiver.java
    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/provider/SoapMessageProviderTests.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/soapmsg/SoapMessageProvider.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/javax/xml/ws/spi/FactoryFinder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/javax/xml/ws/spi/FactoryFinder.java?view=diff&rev=468546&r1=468545&r2=468546
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/javax/xml/ws/spi/FactoryFinder.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/javax/xml/ws/spi/FactoryFinder.java Fri Oct 27 14:15:19 2006
@@ -24,6 +24,10 @@
 import java.lang.reflect.Method;
 import java.util.Properties;
 
+import org.apache.axis2.jaxws.description.EndpointDescription;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 /**
  * This code is designed to implement the pluggability
  * feature and is designed to both compile and run on JDK version 1.1 and
@@ -38,11 +42,12 @@
     /**
      * Set to true for debugging.
      */
+    private static final Log log = LogFactory.getLog(FactoryFinder.class);
     private static final boolean debug = false;
 
     private static void debugPrintln(String msg) {
-        if (debug) {
-            System.err.println("JAXWS: " + msg);
+        if (debug && log.isDebugEnabled()) {
+            log.debug("Factory Finder:" + msg);
         }
     }
 

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/AxisCallback.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/AxisCallback.java?view=diff&rev=468546&r1=468545&r2=468546
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/AxisCallback.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/AxisCallback.java Fri Oct 27 14:15:19 2006
@@ -18,7 +18,6 @@
 package org.apache.axis2.jaxws;
 
 import org.apache.axiom.om.OMElement;
-import org.apache.axis2.AxisFault;
 import org.apache.axis2.client.async.AsyncResult;
 import org.apache.axis2.client.async.Callback;
 import org.apache.axis2.jaxws.core.MessageContext;
@@ -27,6 +26,8 @@
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
 import org.apache.axis2.jaxws.util.Constants;
 import org.apache.axis2.util.ThreadContextMigratorUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * The AxisCallback is the touch point for asynchronous invocations 
@@ -40,6 +41,8 @@
  */
 public class AxisCallback extends Callback {
 
+    private static final Log log = LogFactory.getLog(AxisCallback.class);
+    
     private MessageContext responseMsgCtx;
     private Exception e = null;
     
@@ -48,20 +51,20 @@
      * ready to send the async response back to the client.
      */
     public void onComplete(AsyncResult result) {
-        org.apache.axis2.context.MessageContext axisMsgCtx = 
-            result.getResponseMessageContext();
-        responseMsgCtx = new MessageContext(axisMsgCtx);
-        
         try {
+            org.apache.axis2.context.MessageContext axisMsgCtx = 
+                result.getResponseMessageContext();
+            responseMsgCtx = new MessageContext(axisMsgCtx);
             //REVIEW: Are we on the final thread of execution here or does this get handed off to the executor?
             // TODO: Remove workaround for WS-Addressing running in thin client (non-server) environment
             try {
                 ThreadContextMigratorUtil.performMigrationToThread(Constants.THREAD_CONTEXT_MIGRATOR_LIST_ID, axisMsgCtx);
             }
             catch (Throwable t) {
-                // TODO: Remove writes to stdout
-                System.out.println("JAX-WS AxisCallback caught throwable from ThreadContextMigratorUtil " + t);
-                System.out.println("...caused by " + t.getCause());
+                if (log.isDebugEnabled()) {
+                    log.debug("JAX-WS AxisCallback caught throwable from ThreadContextMigratorUtil " + t);
+                    log.debug("...caused by " + t.getCause());
+                }
                 t.printStackTrace();
             }
           

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/XMLDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/XMLDispatch.java?view=diff&rev=468546&r1=468545&r2=468546
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/XMLDispatch.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/XMLDispatch.java Fri Oct 27 14:15:19 2006
@@ -172,23 +172,32 @@
     
     private Class getBlockFactory(Object o) {
         if (o instanceof String) {
-            System.out.println(">> returning XMLStringBlockFactory");
+            if (log.isDebugEnabled()) {
+                log.debug(">> returning XMLStringBlockFactory");
+            }
             return XMLStringBlockFactory.class;
         }
         else if (Source.class.isAssignableFrom(o.getClass())) {
-            System.out.println(">> returning SourceBlockFactory");
+            if (log.isDebugEnabled()) {
+                log.debug(">> returning SourceBlockFactory");
+            }
             return SourceBlockFactory.class;
         }
         else if (SOAPMessage.class.isAssignableFrom(o.getClass())) {
-            System.out.println(">> returning SOAPMessageFactory");
+            if (log.isDebugEnabled()) {
+                log.debug(">> returning SOAPMessageFactory");
+            }
             return SOAPEnvelopeBlockFactory.class;
         } 
         else if (SOAPEnvelope.class.isAssignableFrom(o.getClass())) {
-            System.out.println(">> returning SOAPEnvelope");
+            if (log.isDebugEnabled()) {
+                log.debug(">> returning SOAPEnvelope");
+            }
             return SOAPEnvelopeBlockFactory.class;
         }
-        
-        System.out.println(">> ERROR: Factory not found");
+        if (log.isDebugEnabled()) {
+            log.debug(">> ERROR: Factory not found");
+        }
         return null;
     }
 }

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=468546&r1=468545&r2=468546
==============================================================================
--- 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 Fri Oct 27 14:15:19 2006
@@ -22,14 +22,12 @@
 import javax.xml.namespace.QName;
 import javax.xml.ws.Service.Mode;
 
-import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axis2.description.AxisService;
-import org.apache.axis2.jaxws.ExceptionFactory;
 import org.apache.axis2.jaxws.description.OperationDescription;
 import org.apache.axis2.jaxws.description.ServiceDescription;
 import org.apache.axis2.jaxws.message.Message;
-import org.apache.axis2.jaxws.message.factory.MessageFactory;
-import org.apache.axis2.jaxws.registry.FactoryRegistry;
+import org.apache.axis2.jaxws.message.MessageException;
+import org.apache.axis2.jaxws.message.util.MessageUtils;
 
 /**
  * The <code>org.apache.axis2.jaxws.core.MessageContext</code> is
@@ -59,25 +57,11 @@
         properties = new HashMap<String, Object>();
     }
     
-    public MessageContext(org.apache.axis2.context.MessageContext mc) {
+    public MessageContext(org.apache.axis2.context.MessageContext mc) throws MessageException {
         axisMsgCtx = mc;
         properties = new HashMap<String, Object>();
         
-        //If the Axis2 MessageContext that was passed in already had a SOAPEnvelope
-        //set on it, grab that and create a JAX-WS Message out of it.
-        SOAPEnvelope soapEnv = mc.getEnvelope();
-        if (soapEnv != null) {
-            MessageFactory msgFactory = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
-            Message newMessage = null;
-            try {
-                newMessage = msgFactory.createFrom(soapEnv);
-            } catch (Exception e) {
-                throw ExceptionFactory.makeWebServiceException("Could not create new Message");
-            }
-            
-            message = newMessage;
-        }
-
+        message = MessageUtils.getMessageFromMessageContext(mc);
     }
     
     public InvocationContext getInvocationContext() {

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=468546&r1=468545&r2=468546
==============================================================================
--- 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 Fri Oct 27 14:15:19 2006
@@ -33,11 +33,9 @@
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.impl.MTOMConstants;
-import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
 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;
 import org.apache.axis2.client.Options;
@@ -61,7 +59,7 @@
 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.message.util.MessageUtils;
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
 import org.apache.axis2.jaxws.util.Constants;
 import org.apache.axis2.transport.http.HTTPConstants;
@@ -139,7 +137,7 @@
          
             // This assumes that we are on the ultimate execution thread
             ThreadContextMigratorUtil.performMigrationToThread(Constants.THREAD_CONTEXT_MIGRATOR_LIST_ID, axisResponseMsgCtx);
-        } catch (AxisFault e) {
+        } catch (Exception e) {
             throw ExceptionFactory.makeWebServiceException(e);
         }
         
@@ -324,15 +322,16 @@
                 //throw an exception
             }
 
+            org.apache.axis2.context.MessageContext axisRequestMsgCtx = 
+                requestMsgCtx.getAxisMessageContext();
+            
             // The MessageContext will contain a Message object with the
             // contents that need to be sent.  We need to get those contents
             // in a form that Axis2 can consume them, an AXIOM SOAPEnvelope.
-            Message requestMsg = requestMsgCtx.getMessage();
-            SOAPEnvelope requestOM = (SOAPEnvelope) requestMsg.getAsOMElement();
-            
-            org.apache.axis2.context.MessageContext axisRequestMsgCtx = 
-                requestMsgCtx.getAxisMessageContext();
-            axisRequestMsgCtx.setEnvelope(requestOM);
+            MessageUtils.putMessageOnMessageContext(
+                    requestMsgCtx.getMessage(),  // JAX-WS Message
+                    axisRequestMsgCtx // Axis 2 MessageContext
+                    );
             
             // For now, just take all of the properties that were in the 
             // JAX-WS MessageContext, and set them on the Axis2 MessageContext.
@@ -357,33 +356,7 @@
      * @see org.apache.axis2.jaxws.core.controller.InvocationController#prepareResponse(org.apache.axis2.jaxws.core.MessageContext)
      */
     protected void prepareResponse(MessageContext responseMsgCtx) {
-        org.apache.axis2.context.MessageContext axisResponseMsgCtx = responseMsgCtx.getAxisMessageContext();
         
-        //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);
-                }
-            }
-        }
     }
     
     private void initOperationClient(OperationClient opClient, MessageContext requestMsgCtx) {

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/util/MessageContextUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/util/MessageContextUtils.java?view=diff&rev=468546&r1=468545&r2=468546
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/util/MessageContextUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/util/MessageContextUtils.java Fri Oct 27 14:15:19 2006
@@ -19,6 +19,7 @@
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.jaxws.ExceptionFactory;
 import org.apache.axis2.jaxws.core.MessageContext;
+import org.apache.axis2.jaxws.message.MessageException;
 import org.apache.axis2.util.Utils;
 
 /**
@@ -50,6 +51,8 @@
             
             return newMC;
         } catch (AxisFault e) {
+            throw ExceptionFactory.makeWebServiceException(e);
+        } catch (MessageException e) {
             throw ExceptionFactory.makeWebServiceException(e);
         }
     }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/EndpointDescription.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/EndpointDescription.java?view=diff&rev=468546&r1=468545&r2=468546
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/EndpointDescription.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/EndpointDescription.java Fri Oct 27 14:15:19 2006
@@ -48,6 +48,7 @@
 import org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite;
 import org.apache.axis2.jaxws.description.builder.MDQConstants;
 import org.apache.axis2.jaxws.i18n.Messages;
+import org.apache.axis2.jaxws.message.databinding.impl.JAXBBlockImpl;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -90,6 +91,7 @@
  * somehow from an AxisService/AxisPort combination, and not directly from the WSDL.
  */
 public class EndpointDescription {
+    
     private ServiceDescription parentServiceDescription;
     private AxisService axisService;
 
@@ -193,16 +195,18 @@
         } catch (DeploymentException e) {
             // TODO RAS
             // TODO NLS
-            // TODO: Remove this println
-            System.out.println("Caught exception in ServiceDescription.ServiceDescription: " + e);
-            e.printStackTrace();
+            if (log.isDebugEnabled()) {
+                log.debug("Caught exception in ServiceDescription.ServiceDescription: " + e);
+                log.debug("Exception:", e);
+            }
 //            throw ExceptionFactory.makeWebServiceException("ServiceDescription caught " + e);
         } catch (Exception e) {
             // TODO RAS
             // TODO NLS
-            // TODO: Remove this println
-            System.out.println("Caught exception in ServiceDescription.ServiceDescription: " + e);
-            e.printStackTrace();
+            if (log.isDebugEnabled()) {
+                log.debug("Caught exception in ServiceDescription.ServiceDescription: " + e);
+                log.debug("Exception:", e);
+            }
 //            throw ExceptionFactory.makeWebServiceException("ServiceDescription caught " + e);
         }
     }

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=468546&r1=468545&r2=468546
==============================================================================
--- 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 Fri Oct 27 14:15:19 2006
@@ -17,32 +17,71 @@
 package org.apache.axis2.jaxws.message;
 
 import javax.activation.DataHandler;
+import javax.xml.soap.MimeHeaders;
 
 /**
  * Attachment
  * 
- * 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>.
+ * This class is very similar to the SAAJ concept of Attachment.
+ * An Attachment has a content and mimeheaders.
+ * 
+ * The most important mimeheaders are the ContentType and ContentId.
+ * The content is stored with a DataHandler
+ * 
+ * @see javax.xml.soap.AttachmentPart
  */
 public interface Attachment {
     
     /**
-     * Gets the MIME type for the content of the attachment.
+     * Gets the MIME content type of the attachment.
      * @return contentType
      */
     public String getContentType();
     
     /**
-     * Gets the contendID that identifies this attachment.
+     * Set the MIME content type of the attachment
+     * @param contentType
+     */
+    public void setContentType(String contentType);
+    
+    /**
+     * Gets the MIME content id that identifies this attachment.
      * @return contentID
      */
     public String getContentID();
     
     /**
-     * Gets the actual content of the attachment in a DataHandler form.
-     * @return content
+     * Set the MIME content id that identifies this attachment
+     * @param contentID
+     */
+    public void setContentID(String contentID);
+    
+    /**
+     * Gets the DataHandler of the attachment in a DataHandler form.
+     * @return DataHandler
      */
     public DataHandler getDataHandler();
     
+    /**
+     * Sets the DataHandler of the attachment
+     * @param DataHandler
+     */
+    public void setDataHandler(DataHandler dh);
+    
+    /**
+     * @return get the MimeHeaders
+     */
+    public MimeHeaders getMimeHeaders();
+    
+    /**
+     * Set the MimeHeaders
+     * @param mh MimeHeaders
+     */
+    public void setMimeHeaders(MimeHeaders mhs);
+    
+    // Common Header keys
+    public final static String CONTENT_ID         = "Content-Id";
+    public final static String CONTENT_TYPE       = "Content-Type";
+    public final static String CONTENT_LOCATION   = "Content-Location";
+    public final static String CONTENT_LENGTH     = "Content-Length";
 }

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=468546&r1=468545&r2=468546
==============================================================================
--- 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 Fri Oct 27 14:15:19 2006
@@ -18,6 +18,7 @@
 
 import java.util.List;
 
+import javax.activation.DataHandler;
 import javax.xml.soap.SOAPMessage;
 
 /**
@@ -52,6 +53,16 @@
      * @param Attachment - the content to add
      */
 	public void addAttachment(Attachment a);
+    
+    /**
+     * Create an Attachment.
+     * After the Attachment is created, it must be added with addAttachment()
+     * @param dh DataHandler (type of Attachment is inferred from dh.getContentType)
+     * @param id String which is the Attachment id
+     * @return Attachment
+     * @see addAttachment(Attachment)
+     */
+    public Attachment createAttachment(DataHandler dh, String id);
     
     /**
 	 * Get the list of attachments for the message

Modified: 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=diff&rev=468546&r1=468545&r2=468546
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java Fri Oct 27 14:15:19 2006
@@ -21,7 +21,6 @@
 
 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;
@@ -66,7 +65,7 @@
             log.debug("Adding MTOM/XOP attachment for element: " + localPart + "{" + namespace + "}");
         
         String cid = UUIDGenerator.getUUID();
-        Attachment a = new AttachmentImpl(data, cid);
+        Attachment a = message.createAttachment(data, cid);
         message.addAttachment(a);
         return cid;
     }

Modified: 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=diff&rev=468546&r1=468545&r2=468546
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/AttachmentImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/AttachmentImpl.java Fri Oct 27 14:15:19 2006
@@ -17,20 +17,21 @@
 package org.apache.axis2.jaxws.message.impl;
 
 import javax.activation.DataHandler;
+import javax.xml.soap.MimeHeaders;
 
 import org.apache.axis2.jaxws.message.Attachment;
 
 /**
- * 
+ * Implementation of the Attachment interface
+ * @see 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;
+    private DataHandler dh;
+    private MimeHeaders mimeHeaders = new MimeHeaders(); 
+    
+    AttachmentImpl(DataHandler dh, String id) {
+        setDataHandler(dh);
+        setContentID(id);
     }
     
     /*
@@ -38,18 +39,30 @@
      * @see org.apache.axis2.jaxws.message.Attachment#getContentType()
      */
     public String getContentType() {
-        if (contentType == null)
-            contentType = data.getContentType();
-        
-        return contentType;
+        return getHeaderValue(CONTENT_TYPE);
     }
     
+  
+    /* (non-Javadoc)
+     * @see org.apache.axis2.jaxws.message.Attachment#setContentType(java.lang.String)
+     */
+    public void setContentType(String contentType) {
+        mimeHeaders.setHeader(CONTENT_TYPE, contentType);
+    }
+
     /*
      * (non-Javadoc)
      * @see org.apache.axis2.jaxws.message.Attachment#getContentID()
      */
     public String getContentID() {
-        return cid;
+        return getHeaderValue(CONTENT_ID);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.axis2.jaxws.message.Attachment#setContentID(java.lang.String)
+     */
+    public void setContentID(String contentID) {
+        mimeHeaders.setHeader(CONTENT_ID, contentID);
     }
     
     /*
@@ -57,6 +70,43 @@
      * @see org.apache.axis2.jaxws.message.Attachment#getDataHandler()
      */
     public DataHandler getDataHandler() {
-        return data;
+        return dh;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.axis2.jaxws.message.Attachment#setDataHandler(javax.activation.DataHandler)
+     */
+    public void setDataHandler(DataHandler dh) {
+        this.dh = dh;
+        if (dh.getContentType() != null) {
+            setContentType(dh.getContentType());
+        }
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.axis2.jaxws.message.Attachment#getMimeHeaders()
+     */
+    public MimeHeaders getMimeHeaders() {
+       return mimeHeaders;
+    }
+
+    
+
+    /* (non-Javadoc)
+     * @see org.apache.axis2.jaxws.message.Attachment#setMimeHeaders(javax.xml.soap.MimeHeaders)
+     */
+    public void setMimeHeaders(MimeHeaders mhs) {
+        mimeHeaders = mhs;
+        if (mimeHeaders == null) {
+            mimeHeaders = new MimeHeaders();
+        }
+    }
+
+    private String getHeaderValue(String header) {
+        String[] values = mimeHeaders.getHeader(header);
+        if (values != null && values.length > 0) {
+            return values[0];
+        }
+        return null;
     }
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageFactoryImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageFactoryImpl.java?view=diff&rev=468546&r1=468545&r2=468546
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageFactoryImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageFactoryImpl.java Fri Oct 27 14:15:19 2006
@@ -16,6 +16,9 @@
  */
 package org.apache.axis2.jaxws.message.impl;
 
+import java.util.Iterator;
+
+import javax.xml.soap.AttachmentPart;
 import javax.xml.soap.SOAPMessage;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
@@ -25,12 +28,14 @@
 import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
 import org.apache.axis2.jaxws.ExceptionFactory;
 import org.apache.axis2.jaxws.i18n.Messages;
+import org.apache.axis2.jaxws.message.Attachment;
 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.Protocol;
 import org.apache.axis2.jaxws.message.databinding.SOAPEnvelopeBlock;
 import org.apache.axis2.jaxws.message.factory.MessageFactory;
+import org.apache.axis2.jaxws.message.util.MessageUtils;
 
 /**
  * MessageFactoryImpl
@@ -73,10 +78,16 @@
 	 */
 	public Message createFrom(SOAPMessage message) throws XMLStreamException, MessageException {
 		try {
+            // Create a Message with an XMLPart from the SOAPEnvelope
 			Message m = new MessageImpl(message.getSOAPPart().getEnvelope());
 			if (message.countAttachments() > 0) {
-				throw ExceptionFactory.makeMessageException(Messages.getMessage("AttachmentsNotSupported"));
-			}
+                Iterator it = message.getAttachments();
+                while (it.hasNext()) {
+                    AttachmentPart ap = (AttachmentPart) it.next();
+                    Attachment a = MessageUtils.createAttachment(ap, m);
+                    m.addAttachment(a);
+                }
+            }
 			return m;
 		} catch (Exception e) {
 			throw ExceptionFactory.makeMessageException(e);

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=468546&r1=468545&r2=468546
==============================================================================
--- 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 Fri Oct 27 14:15:19 2006
@@ -22,6 +22,7 @@
 import java.util.Iterator;
 import java.util.List;
 
+import javax.activation.DataHandler;
 import javax.xml.soap.MessageFactory;
 import javax.xml.soap.MimeHeaders;
 import javax.xml.soap.SOAPEnvelope;
@@ -52,6 +53,10 @@
  * A Message is an XML part + Attachments.
  * Most of the implementation delegates to the XMLPart implementation.
  */
+/**
+ * @author scheu
+ *
+ */
 public class MessageImpl implements Message {
 
 	Protocol protocol = Protocol.unknown; // the protocol, defaults to unknown
@@ -307,15 +312,21 @@
         attachments.add(data);
     }
     
-    //FIXME: This doesn't make much sense, but has to be here because Message extends
-    //XMLPart.  
+    
+    
+    /* (non-Javadoc)
+     * @see org.apache.axis2.jaxws.message.Message#createAttachment(javax.activation.DataHandler, java.lang.String)
+     */
+    public Attachment createAttachment(DataHandler dh, String id) {
+        return new AttachmentImpl(dh, id);
+    }
+
     public Message getParent() {
-        throw new UnsupportedOperationException();
+        return null;
     }
 
-    //FIXME: This doesn't make much sense, but has to be here because Message extends
-    //XMLPart.  
     public void setParent(Message msg) { 
+        // A Message does not have a parent
         throw new UnsupportedOperationException();
     }
 

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/MessageUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/MessageUtils.java?view=diff&rev=468546&r1=468545&r2=468546
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/MessageUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/MessageUtils.java Fri Oct 27 14:15:19 2006
@@ -16,15 +16,43 @@
  */
 package org.apache.axis2.jaxws.message.util;
 
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.activation.DataHandler;
+import javax.xml.soap.AttachmentPart;
+import javax.xml.soap.MimeHeader;
+import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
+
+import org.apache.axiom.attachments.Attachments;
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMDocument;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.MTOMConstants;
 import org.apache.axiom.om.impl.builder.StAXBuilder;
 import org.apache.axiom.soap.SOAP11Constants;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants.Configuration;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.description.EndpointDescription;
+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.registry.FactoryRegistry;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 
 /**
@@ -33,6 +61,7 @@
  */
 public class MessageUtils {
     
+    private static final Log log = LogFactory.getLog(MessageUtils.class);
     /**
      * Get an axiom SOAPFactory for the specified element
      * @param e OMElement
@@ -69,5 +98,145 @@
             }
         }
         return null;
+    }
+    
+    /**
+     * Create a JAXWS Message Attachment object from an SAAJ AttachmentPart
+     * @param ap AttachmentPart
+     * @param message Message
+     * @return Attachment
+     * @throws SOAPException
+     */
+    public static Attachment createAttachment(AttachmentPart ap, Message message) throws SOAPException {
+        // Create the attachment
+        Attachment a = message.createAttachment(ap.getDataHandler(), ap.getContentId());
+        
+        // Copy over all of the headers
+        MimeHeaders mhs = new MimeHeaders();
+        Iterator it =ap.getAllMimeHeaders();
+        while (it.hasNext()) {
+            MimeHeader mh = (MimeHeader) it.next();
+            mhs.addHeader(mh.getName(), mh.getValue());
+        }
+        a.setMimeHeaders(mhs);
+        return a;
+    }
+    
+    /**
+     * Create an SAAJ AttachmentPart from a JAXWS Attachment
+     * @param a Attachment
+     * @param message SOAPMessage
+     * @return AttachmentPart
+     */
+    public static AttachmentPart createAttachmentPart(Attachment a, SOAPMessage message) {
+        // Create the Attachment Part
+        AttachmentPart ap = message.createAttachmentPart(a.getDataHandler());
+        
+        // Copy over all of the Headers
+        Iterator it = a.getMimeHeaders().getAllHeaders();
+        while (it.hasNext()) {
+            MimeHeader mh = (MimeHeader) it.next();
+            ap.addMimeHeader(mh.getName(), mh.getValue());
+        }
+        return ap;
+    }
+    
+    /**
+     * Create a JAX-WS Message from the
+     * information on an Axis 2 Message Context
+     * @param msgContext
+     * @return Message
+     */
+    public static Message getMessageFromMessageContext(MessageContext msgContext) throws MessageException {
+        Message message = null;
+        // If the Axis2 MessageContext that was passed in has a SOAPEnvelope
+        // set on it, grab that and create a JAX-WS Message out of it.
+        SOAPEnvelope soapEnv = msgContext.getEnvelope();
+        if (soapEnv != null) {
+            MessageFactory msgFactory = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
+            try {
+                message = msgFactory.createFrom(soapEnv);
+            } catch (Exception e) {
+                throw ExceptionFactory.makeWebServiceException("Could not create new Message");
+            }
+            
+            // 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) msgContext.getProperty(MTOMConstants.ATTACHMENTS); 
+            if (as != null) { 
+                message.setMTOMEnabled(true);
+                
+                //Walk the tree and find all of the optimized binary nodes.
+                ArrayList<OMText> binaryNodes = AttachmentUtils.findBinaryNodes((SOAPEnvelope) message.getAsOMElement());
+                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 = message.createAttachment(
+                                (DataHandler) node.getDataHandler(), 
+                                node.getContentID());
+                        message.addAttachment(a);
+                    }
+                }
+            } else {
+                // Add non-mtom attachments
+                Attachments attachments = msgContext.getAttachmentMap();
+                if (attachments != null) {
+                    String[] ids = attachments.getAllContentIDs();
+                    if (ids != null) {
+                        for (int i = 0; i<ids.length; i++) {
+                            DataHandler dh = attachments.getDataHandler(ids[i]);
+                            Attachment a = message.createAttachment(dh, ids[i]);
+                            message.addAttachment(a);
+                            if (log.isDebugEnabled()) {
+                                log.debug("Create Attachment for:" + a.getContentID() + " " + a.getContentType());
+                            }
+                        }
+                    }
+                }
+            }
+            
+        }
+        return message;
+    }
+    
+    /**
+     * Put the JAX-WS Message onto the Axis2 MessageContext
+     * @param message JAX-WS Message
+     * @param msgContext Axis2MessageContext
+     */
+    public static void putMessageOnMessageContext(Message message, MessageContext msgContext) throws AxisFault, MessageException {
+        // Put the XML message on the Axis 2 Message Context
+        SOAPEnvelope envelope = (SOAPEnvelope) message.getAsOMElement();
+        msgContext.setEnvelope(envelope);
+        
+        // Enable MTOM Attachments 
+        if (message.isMTOMEnabled()) {
+            Options opts = msgContext.getOptions();
+            opts.setProperty(Configuration.ENABLE_MTOM, "true");                    
+        }
+        
+        // Add the attachments
+        List attachments = message.getAttachments();
+        if (attachments != null && attachments.size() > 0) {
+            for (int i=0; i<attachments.size(); i++) {
+                Attachment a = (Attachment) attachments.get(i);
+                msgContext.addAttachment(a.getContentID(), a.getDataHandler());
+                if (log.isDebugEnabled()) {
+                    log.debug("Attachment for:" + a.getContentID() + " " + a.getContentType());
+                }
+            }
+        }
+       
     }
 }

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=468546&r1=468545&r2=468546
==============================================================================
--- 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 Fri Oct 27 14:15:19 2006
@@ -17,17 +17,6 @@
 
 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;
@@ -42,10 +31,8 @@
 import org.apache.axis2.jaxws.core.InvocationContextImpl;
 import org.apache.axis2.jaxws.core.MessageContext;
 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.message.util.MessageUtils;
 import org.apache.axis2.jaxws.util.Constants;
 import org.apache.axis2.util.ThreadContextMigratorUtil;
 import org.apache.axis2.wsdl.WSDLConstants.WSDL20_2004Constants;
@@ -101,38 +88,6 @@
           	
             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);
             
@@ -152,16 +107,9 @@
                 // MessageContext.
                 MessageContext responseMsgCtx = ic.getResponseMessageContext();
                 org.apache.axis2.context.MessageContext axisResponseMsgCtx = 
-                    responseMsgCtx.getAxisMessageContext();                
-                
-                Message responseMsg = responseMsgCtx.getMessage();
-                SOAPEnvelope responseEnv = (SOAPEnvelope) responseMsg.getAsOMElement();
-                axisResponseMsgCtx.setEnvelope(responseEnv);
+                    responseMsgCtx.getAxisMessageContext(); 
                 
-                if (responseMsg.isMTOMEnabled()) {
-                    Options opts = axisResponseMsgCtx.getOptions();
-                    opts.setProperty(Configuration.ENABLE_MTOM, "true");                    
-                }
+                MessageUtils.putMessageOnMessageContext(responseMsgCtx.getMessage(), axisResponseMsgCtx);
                 
                 OperationContext opCtx = axisResponseMsgCtx.getOperationContext();
                 opCtx.addMessageContext(axisResponseMsgCtx);

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=468546&r1=468545&r2=468546
==============================================================================
--- 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 Fri Oct 27 14:15:19 2006
@@ -58,8 +58,15 @@
 import org.apache.axis2.jaxws.security.BasicAuthSecurityTests;
 import org.apache.axis2.proxy.ProxyNonWrappedTests;
 import org.apache.axis2.proxy.ProxyTests;
+import org.apache.log4j.BasicConfigurator;
 
 public class JAXWSTest extends TestCase {
+    
+    static {
+        // Enable debug
+        //BasicConfigurator.configure();
+    }
+    
     /**
      * suite
      * @return

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SoapMessageProviderTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SoapMessageProviderTests.java?view=diff&rev=468546&r1=468545&r2=468546
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SoapMessageProviderTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SoapMessageProviderTests.java Fri Oct 27 14:15:19 2006
@@ -18,27 +18,36 @@
 
 
 import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.util.Map;
+import java.util.Iterator;
+
 import javax.xml.namespace.QName;
-import javax.xml.ws.BindingProvider;
-import javax.xml.ws.Dispatch;
-import javax.xml.ws.Service;
+import javax.xml.soap.AttachmentPart;
 import javax.xml.soap.MessageFactory;
+import javax.xml.soap.Node;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
 import javax.xml.soap.SOAPMessage;
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+
+import org.apache.axis2.jaxws.provider.soapmsg.SoapMessageProvider;
 
+/**
+ * Tests Dispatch<SOAPMessage> client and a Provider<SOAPMessage> service.
+ * The client and service interaction tests various xml and attachment scenarios
+ *
+ */
 public class SoapMessageProviderTests extends ProviderTestCase {
 
     private String endpointUrl = "http://localhost:8080/axis2/services/SoapMessageProviderService";
     private QName serviceName = new QName("http://ws.apache.org/axis2", "SoapMessageProviderService");
-    private String xmlDir = "xml";
-    private String reqMsg = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><ns2:invoke xmlns:ns2=\"http://org.test.soapmessage\"><invoke_str>some request</invoke_str></ns2:invoke></soap:Body></soap:Envelope>";
-
-
+    
+    private String reqMsgStart = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+    "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>" +
+    "<ns2:invoke xmlns:ns2=\"http://org.test.soapmessage\"><invoke_str>";
+    
+    private String reqMsgEnd = "</invoke_str></ns2:invoke></soap:Body></soap:Envelope>";
+   
     protected void setUp() throws Exception {
             super.setUp();
     }
@@ -51,24 +60,31 @@
         super(name);
     }
     
-    public void testProviderSource(){
-        try{
-//        	String resourceDir = new File(providerResourceDir, xmlDir).getAbsolutePath();
-//        	String fileName = resourceDir+File.separator+"web.xml";
-//        	
-//        	File file = new File(fileName);
-//        	InputStream inputStream = new FileInputStream(file);
-//        	StreamSource xmlStreamSource = new StreamSource(inputStream);
-//        	
-        	Service svc = Service.create(serviceName);
-        	svc.addPort(portName,null, endpointUrl);
-        	Dispatch<SOAPMessage> dispatch = svc.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
-        	System.out.println(">> Invoking SourceMessageProviderDispatch");
+    /**
+     * Sends an SOAPMessage containing only xml data to the web service.  
+     * Receives a response containing just xml data.
+     */
+    public void testProviderSource1(){
+        try{       
+            // Create the dispatch
+            Dispatch<SOAPMessage> dispatch = createDispatch();
+            
+            // Create the SOAPMessage
+            String msg = reqMsgStart + SoapMessageProvider.XML_REQUEST + reqMsgEnd;
             MessageFactory factory = MessageFactory.newInstance();
-            SOAPMessage outboundMessage = factory.createMessage(null, 
-                    new ByteArrayInputStream(reqMsg.getBytes()));
-        	SOAPMessage response = dispatch.invoke(outboundMessage);
+            SOAPMessage request = factory.createMessage(null, 
+                    new ByteArrayInputStream(msg.getBytes()));
+            
+            // Dispatch
+        	System.out.println(">> Invoking SourceMessageProviderDispatch");
+        	SOAPMessage response = dispatch.invoke(request);
 
+            // Check assertions and get the data element
+            SOAPElement dataElement = assertResponseXML(response, SoapMessageProvider.XML_RESPONSE);
+            
+            assertTrue(countAttachments(response) == 0);
+            
+            // Print out the response
         	System.out.println(">> Response [" + response.toString() + "]");
             response.writeTo(System.out);
         	
@@ -77,5 +93,111 @@
             fail("Caught exception " + e);
         }
         
+    }
+    
+    /**
+     * Sends an SOAPMessage containing xml data and raw attachments to the web service.  
+     * Receives a response containing xml data and the same raw attachments.
+     */
+    /** TODO Disable while I implement the code
+    public void testProviderSource2(){
+        try{       
+            // Create the dispatch
+            Dispatch<SOAPMessage> dispatch = createDispatch();
+            
+            // Create the SOAPMessage
+            String msg = reqMsgStart + SoapMessageProvider.XML_ATTACHMENT_REQUEST + reqMsgEnd;
+            MessageFactory factory = MessageFactory.newInstance();
+            SOAPMessage request = factory.createMessage(null, 
+                    new ByteArrayInputStream(msg.getBytes()));
+            
+            // Add the Attachment
+            AttachmentPart ap = request.createAttachmentPart(SoapMessageProvider.TEXT_XML_ATTACHMENT, "text/xml");
+            ap.setContentId(SoapMessageProvider.ID);
+            request.addAttachmentPart(ap);
+            
+            System.out.println("Request Message:");
+            request.writeTo(System.out);
+            
+            // Dispatch
+            System.out.println(">> Invoking SourceMessageProviderDispatch");
+            SOAPMessage response = dispatch.invoke(request);
+
+            // Check assertions and get the data element
+            SOAPElement dataElement = assertResponseXML(response, SoapMessageProvider.XML_ATTACHMENT_RESPONSE);
+            assertTrue(countAttachments(response) == 1);
+            
+            // Get the Attachment
+            AttachmentPart attachmentPart = (AttachmentPart) response.getAttachments().next();
+            
+            // Check the attachment
+            String content = (String) attachmentPart.getContent();
+            assertTrue(content != null);
+            assertTrue(SoapMessageProvider.TEXT_XML_ATTACHMENT.equals(content));
+            
+            // Print out the response
+            System.out.println(">> Response [" + response.toString() + "]");
+            response.writeTo(System.out);
+            
+        }catch(Exception e){
+            e.printStackTrace();
+            fail("Caught exception " + e);
+        }
+        
+    }
+    */
+    
+    /**
+     * @return
+     * @throws Exception
+     */
+    private Dispatch<SOAPMessage> createDispatch() throws Exception {
+        Service svc = Service.create(serviceName);
+        svc.addPort(portName,null, endpointUrl);
+        Dispatch<SOAPMessage> dispatch = svc.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
+        return dispatch;
+    }
+    
+    /**
+     * Common assertion checking of the response
+     * @param msg
+     * @param expectedText
+     * @return SOAPElement representing the data element
+     */
+    private SOAPElement assertResponseXML(SOAPMessage msg, String expectedText) throws Exception {
+        assertTrue(msg != null);
+        SOAPBody body = msg.getSOAPBody();
+        assertTrue(body != null);
+        
+        Node invokeElement = (Node) body.getFirstChild();
+        assert(invokeElement instanceof SOAPElement);
+        assert(SoapMessageProvider.RESPONSE_NAME.equals(invokeElement.getLocalName()));
+        
+        Node dataElement = (Node) invokeElement.getFirstChild();
+        assert(dataElement instanceof SOAPElement);
+        assert(SoapMessageProvider.RESPONSE_DATA_NAME.equals(dataElement.getLocalName()));
+        
+        // TODO AXIS2 SAAJ should (but does not) support the getTextContent();
+        // String text = dataElement.getTextContent();
+        String text = dataElement.getValue();
+        assertEquals("Found ("+ text + ") but expected (" + expectedText + ")", expectedText, text);
+        
+        return (SOAPElement) dataElement;
+    }
+    
+    /**
+     * Count Attachments
+     * @param msg
+     * @return
+     */
+    private int countAttachments(SOAPMessage msg) {
+        Iterator it = msg.getAttachments();
+        int count = 0;
+        assert(it != null);
+        while (it.hasNext()) {
+            it.next();
+            count++;
+        }
+        return count;
     }
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/soapmsg/SoapMessageProvider.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/soapmsg/SoapMessageProvider.java?view=diff&rev=468546&r1=468545&r2=468546
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/soapmsg/SoapMessageProvider.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/soapmsg/SoapMessageProvider.java Fri Oct 27 14:15:19 2006
@@ -17,18 +17,41 @@
 package org.apache.axis2.jaxws.provider.soapmsg;
 
 import java.io.ByteArrayInputStream;
+import java.util.Iterator;
 
 import javax.xml.ws.Provider;
 import javax.xml.ws.Service;
 import javax.xml.ws.ServiceMode;
 import javax.xml.ws.WebServiceProvider;
+import javax.xml.soap.AttachmentPart;
 import javax.xml.soap.MessageFactory;
+import javax.xml.soap.Node;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
 import javax.xml.soap.SOAPMessage;
 
 @WebServiceProvider()
 @ServiceMode(value=Service.Mode.MESSAGE)
 public class SoapMessageProvider implements Provider<SOAPMessage> {
-    String responseAsString = new String("<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header/><soapenv:Body><ns2:ReturnType xmlns:ns2=\"http://test\"><return_str>some response</return_str></ns2:ReturnType></soapenv:Body></soapenv:Envelope>");
+      
+    String responseMsgStart = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header/><soapenv:Body><ns2:ReturnType xmlns:ns2=\"http://test\"><return_str>";
+    String responseMsgEnd = "</return_str></ns2:ReturnType></soapenv:Body></soapenv:Envelope>";
+
+    // Requests and Response values of invoke_str and return_str
+    // These constants are referenced by the SoapMessageProviderTest and SoapMessageProvider
+    public static String RESPONSE_NAME = "ReturnType";
+    public static String RESPONSE_DATA_NAME = "return_str";
+    public static String REQUEST_NAME = "invoke";
+    public static String REQUEST_DATA_NAME = "invoke_str";
+    
+    public static String XML_REQUEST              = "xml request";
+    public static String XML_RESPONSE             = "xml response";
+    public static String XML_ATTACHMENT_REQUEST   = "xml and attachment request";
+    public static String XML_ATTACHMENT_RESPONSE  = "xml and attachment response";
+    
+    public static String TEXT_XML_ATTACHMENT = "<myAttachment>Hello World</myAttachment>";
+    public static String ID = "cid123";
+    
     public SOAPMessage invoke(SOAPMessage soapMessage) {
     	System.out.println(">> SoapMessageProvider: Request received.");
     	
@@ -38,19 +61,121 @@
             soapMessage.writeTo(System.out);
             System.out.println("\n");
             
-            // Build the outgoing response message
-            SOAPMessage message = null;
-            MessageFactory factory = MessageFactory.newInstance();
-            message = factory.createMessage(null, new ByteArrayInputStream(responseAsString.getBytes()));
-
+            // Get the data element.  This performs basic assertions on the received message
+            SOAPElement dataElement = assertRequestXML(soapMessage);
+            
+            // Use the data element text to determine the type of response to send
+            SOAPMessage response = null;
+            // TODO AXIS2 SAAJ should (but does not) support the getTextContent();
+            // String text = dataElement.getTextContent();
+            String text = dataElement.getValue();
+            if (XML_REQUEST.equals(text)) {
+                response = getXMLResponse(soapMessage, dataElement);
+            } else if (XML_ATTACHMENT_REQUEST.equals(text)) {
+                response = getXMLAttachmentResponse(soapMessage, dataElement);
+            } else {
+                // We should not get here
+                assert(false);
+            }
+            
+            // Write out the Message
             System.out.println(">> Response being sent by Server:");
-            message.writeTo(System.out);
+            response.writeTo(System.out);
             System.out.println("\n");
-            return message;
+            return response;
     	}catch(Exception e){
             System.out.println("***ERROR: In SoapMessageProvider.invoke: Caught exception " + e);
     		e.printStackTrace();
     	}
     	return null;
+    }
+    
+    /**
+     * Common assertion checking of the request
+     * @param msg
+     * @return SOAPElement representing the data element
+     */
+    private SOAPElement assertRequestXML(SOAPMessage msg) throws Exception {
+        assert(msg != null);
+        SOAPBody body = msg.getSOAPBody();
+        assert(body != null);
+        
+        Node invokeElement = (Node) body.getFirstChild();
+        assert(invokeElement instanceof SOAPElement);
+        assert(SoapMessageProvider.RESPONSE_NAME.equals(invokeElement.getLocalName()));
+        
+        Node dataElement = (Node) invokeElement.getFirstChild();
+        assert(dataElement instanceof SOAPElement);
+        assert(SoapMessageProvider.RESPONSE_DATA_NAME.equals(dataElement.getLocalName()));
+        
+        String text = dataElement.getValue();
+        assert(text != null);
+        assert(text.length() > 0);
+        
+        return (SOAPElement) dataElement;
+    }
+    
+    /**
+     * Get the response for an XML only request
+     * @param request
+     * @param dataElement
+     * @return SOAPMessage
+     */
+    private SOAPMessage getXMLResponse(SOAPMessage request, SOAPElement dataElement) throws Exception {
+        SOAPMessage response;
+        
+        // Additional assertion checks
+        assert(countAttachments(request) == 0);
+        
+        // Build the Response
+        MessageFactory factory = MessageFactory.newInstance();
+        String responseXML = responseMsgStart + XML_RESPONSE + responseMsgEnd;
+        response = factory.createMessage(null, new ByteArrayInputStream(responseXML.getBytes()));
+        
+        return response;
+    }
+    
+    /**
+     * Get the response for an XML and an Attachment request
+     * @param request
+     * @param dataElement
+     * @return SOAPMessage
+     */
+    private SOAPMessage getXMLAttachmentResponse(SOAPMessage request, SOAPElement dataElement) throws Exception {
+        SOAPMessage response;
+        
+        // Additional assertion checks
+        assert(countAttachments(request) == 1);
+        AttachmentPart requestAP = (AttachmentPart) request.getAttachments().next();
+        String content = (String) requestAP.getContent();
+        assert(SoapMessageProvider.TEXT_XML_ATTACHMENT.equals(content));
+        
+        // Build the Response
+        MessageFactory factory = MessageFactory.newInstance();
+        String responseXML = responseMsgStart + XML_ATTACHMENT_RESPONSE + responseMsgEnd;
+        response = factory.createMessage(null, new ByteArrayInputStream(responseXML.getBytes()));
+        
+        // Create and attach the attachment
+        AttachmentPart ap = response.createAttachmentPart(SoapMessageProvider.TEXT_XML_ATTACHMENT, "text/xml");
+        ap.setContentId(ID);
+        response.addAttachmentPart(ap);
+        
+        return response;
+    }
+    
+    /**
+     * Count Attachments
+     * @param msg
+     * @return
+     */
+    private int countAttachments(SOAPMessage msg) {
+        Iterator it = msg.getAttachments();
+        int count = 0;
+        assert(it != null);
+        while (it.hasNext()) {
+            it.next();
+            count++;
+        }
+        return count;
     }
 }



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