Author: scheu
Date: Mon Sep 27 15:43:20 2010
New Revision: 1001786

URL: http://svn.apache.org/viewvc?rev=1001786&view=rev
Log:
AXIS2-4831
Contributor: Rich Scheuerle
Summary:
SWA attachment may not  be added if the MTOMXMLStreamWriter is not used

Modified:
    
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBAttachmentMarshaller.java
    
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java

Modified: 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBAttachmentMarshaller.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBAttachmentMarshaller.java?rev=1001786&r1=1001785&r2=1001786&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBAttachmentMarshaller.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBAttachmentMarshaller.java
 Mon Sep 27 15:43:20 2010
@@ -145,7 +145,7 @@ public class JAXBAttachmentMarshaller ex
 
             if(optimizedThreshold==0 || dataLength > optimizedThreshold){
                 DataHandler dataHandler = new DataHandler(mpds);
-                cid = addDataHandler(dataHandler);
+                cid = addDataHandler(dataHandler, false);
             }
 
             // Add the content id to the mime body part
@@ -166,7 +166,7 @@ public class JAXBAttachmentMarshaller ex
             log.debug("Adding MTOM/XOP datahandler attachment for element: " + 
                       "{" + namespace + "}" + localPart);
         }
-        String cid = addDataHandler(data);
+        String cid = addDataHandler(data, false);
         return cid == null ? null : "cid:" + cid;
     }
     
@@ -179,7 +179,7 @@ public class JAXBAttachmentMarshaller ex
             log.debug("Adding SWAREF attachment");
         }
         
-        String cid = addDataHandler(data);
+        String cid = addDataHandler(data, true);
         setDoingSWA();
         return "cid:" + cid;
     }
@@ -189,21 +189,45 @@ public class JAXBAttachmentMarshaller ex
      * @param dh
      * @return
      */
-    private String addDataHandler(DataHandler dh) {
+    private String addDataHandler(DataHandler dh, boolean isSWA) {
         String cid = null;
         OMText textNode = null;
         
         // If this is an MTOMXMLStreamWriter then inform the writer 
-        // that it must write out this attchment (I guess we should do this
+        // that it must write out this attachment (I guess we should do this
         // even if the attachment is SWAREF ?)
-        if (writer instanceof MTOMXMLStreamWriter) {
+        if (isSWA) {
+            if (log.isDebugEnabled()){ 
+                log.debug("adding DataHandler for SWA");
+            }
             textNode = new OMTextImpl(dh, null);
-               if(((MTOMXMLStreamWriter) 
writer).isOptimizedThreshold(textNode)){
-                       cid = textNode.getContentID();
-                       ((MTOMXMLStreamWriter) writer).writeOptimized(textNode);
-                       // Remember the attachment on the message.
-                       addDataHandler(dh, cid);
-               }               
+            // If old SWA attachments, get the ID and add the attachment to 
message
+            cid = textNode.getContentID();
+            addDataHandler(dh, cid);   
+        } else {
+            if (log.isDebugEnabled()){ 
+                log.debug("adding DataHandler for MTOM");
+            }
+            if (writer instanceof MTOMXMLStreamWriter) {
+                textNode = new OMTextImpl(dh, null);
+                if(((MTOMXMLStreamWriter) 
writer).isOptimizedThreshold(textNode)){
+                    if (log.isDebugEnabled()){ 
+                        log.debug("The MTOM attachment is written as an 
attachment part.");
+                    }
+                    cid = textNode.getContentID();
+                    ((MTOMXMLStreamWriter) writer).writeOptimized(textNode);
+                    // Remember the attachment on the message.
+                    addDataHandler(dh, cid);
+                } else {
+                    if (log.isDebugEnabled()){ 
+                        log.debug("The MTOM attachment is inlined.");
+                    }
+                }
+            } else {
+                if (log.isDebugEnabled()){ 
+                    log.debug("writer is not MTOM capable.  The attachment 
will be inlined.");
+                }
+            }
         }
         
         if (log.isDebugEnabled()){ 
@@ -243,6 +267,12 @@ public class JAXBAttachmentMarshaller ex
     public void addDataHandler(DataHandler dh, String cid) {
         if (msgContext != null) {
             msgContext.addAttachment(cid, dh);
+        } else {
+            if (log.isDebugEnabled()) {
+                log.debug("The msgContext is null.  The attachment is not 
stored");
+                log.debug("   content id=" + cid);
+                log.debug("   dataHandler  =" + dh);
+            }
         }
     }
 }

Modified: 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java?rev=1001786&r1=1001785&r2=1001786&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java
 Mon Sep 27 15:43:20 2010
@@ -21,6 +21,8 @@ package org.apache.axis2.jaxws.message.a
 
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.jaxws.message.Message;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import javax.activation.DataHandler;
 import javax.xml.stream.XMLStreamWriter;
@@ -30,6 +32,8 @@ import javax.xml.stream.XMLStreamWriter;
  * and create populate the appropriate constructs within the JAX-WS Message 
Model.
  */
 public class JAXBAttachmentMarshaller extends 
org.apache.axis2.datasource.jaxb.JAXBAttachmentMarshaller {
+    
+    private static final Log log = 
LogFactory.getLog(JAXBAttachmentMarshaller.class);
     private Message message;
     
     public JAXBAttachmentMarshaller(Message message, XMLStreamWriter writer) {
@@ -79,6 +83,12 @@ public class JAXBAttachmentMarshaller ex
     public void addDataHandler(DataHandler dh, String cid) {
         if (message != null) {
             message.addDataHandler(dh, cid);
+        } else {
+            if (log.isDebugEnabled()) {
+                log.debug("The msgContext is null.  The attachment is not 
stored");
+                log.debug("   content id=" + cid);
+                log.debug("   dataHandler  =" + dh);
+            }
         }
     }
 }


Reply via email to