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()) {
+