Author: veithen
Date: Fri Nov 12 17:20:18 2010
New Revision: 1034477

URL: http://svn.apache.org/viewvc?rev=1034477&view=rev
Log:
AXIOM-274: Refactored and deprecated the 
MIMEOutputUtils#writeSOAPWithAttachmentsMessage method.

Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MIMEOutputUtils.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MIMEOutputUtils.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MIMEOutputUtils.java?rev=1034477&r1=1034476&r2=1034477&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MIMEOutputUtils.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MIMEOutputUtils.java
 Fri Nov 12 17:20:18 2010
@@ -21,7 +21,10 @@ package org.apache.axiom.om.impl;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.OutputStreamWriter;
 import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -231,33 +234,40 @@ public class MIMEOutputUtils {
         outStream.write(new byte[] { 45, 45 });
     }
 
+    /**
+     * @deprecated use {...@link OMMultipartWriter} instead
+     */
     public static void writeSOAPWithAttachmentsMessage(StringWriter writer,
                                                        OutputStream 
outputStream,
                                                        Attachments attachments,
                                                        OMOutputFormat format) {
-        String SOAPContentType;
-        if (format.isSOAP11()) {
-            SOAPContentType = SOAP11Constants.SOAP_11_CONTENT_TYPE;
-        } else {
-            SOAPContentType = SOAP12Constants.SOAP_12_CONTENT_TYPE;
-        }
-        String contentType = SOAPContentType + "; charset=" + 
format.getCharSetEncoding();
-        javax.activation.DataHandler dh = new javax.activation.DataHandler(
-                writer.toString(), "text/xml; charset="
-                + format.getCharSetEncoding());
-        
-        // Get the collection of ids associated with the attachments
-        Collection ids = null;         
-        if (respectSWAAttachmentOrder(format)) {
-            // ContentIDList is the order of the incoming/added attachments
-            ids = attachments.getContentIDList();
-        } else {
-            // ContentIDSet is an undefined order (the implemenentation 
currently
-            // orders the attachments using the natural order of the content 
ids)
-            ids = attachments.getContentIDSet();
+        try {
+            OMMultipartWriter mpw = new OMMultipartWriter(outputStream, 
format);
+            
+            Writer rootPartWriter = new 
OutputStreamWriter(mpw.writeRootPart(), format.getCharSetEncoding());
+            rootPartWriter.write(writer.toString());
+            rootPartWriter.close();
+            
+            // Get the collection of ids associated with the attachments
+            Collection ids;         
+            if (respectSWAAttachmentOrder(format)) {
+                // ContentIDList is the order of the incoming/added attachments
+                ids = Arrays.asList(attachments.getAllContentIDs());
+            } else {
+                // ContentIDSet is an undefined order (the implementation 
currently
+                // orders the attachments using the natural order of the 
content ids)
+                ids = attachments.getContentIDSet();
+            }
+            
+            for (Iterator it = ids.iterator(); it.hasNext(); ) {
+                String id = (String)it.next();
+                mpw.writePart(attachments.getDataHandler(id), id);
+            }
+            
+            mpw.complete();
+        } catch (IOException ex) {
+            throw new OMException("Error writing SwA message", ex);
         }
-        writeDataHandlerWithAttachmentsMessage(dh, contentType, outputStream, 
-                    attachments.getMap(), format, ids);
     }
 
     public static void writeDataHandlerWithAttachmentsMessage(DataHandler 
rootDataHandler,

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java?rev=1034477&r1=1034476&r2=1034477&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java
 Fri Nov 12 17:20:18 2010
@@ -53,18 +53,17 @@ public class OMMultipartWriter {
         useCTEBase64 = format != null && Boolean.TRUE.equals(
                 
format.getProperty(OMOutputFormat.USE_CTE_BASE64_FOR_NON_TEXTUAL_ATTACHMENTS));
         
+        String soapContentType;
+        if (format.isSOAP11()) {
+            soapContentType = SOAP11Constants.SOAP_11_CONTENT_TYPE;
+        } else {
+            soapContentType = SOAP12Constants.SOAP_12_CONTENT_TYPE;
+        }
         if (format.isOptimized()) {
-            String soapContentType;
-            if (format.isSOAP11()) {
-                soapContentType = SOAP11Constants.SOAP_11_CONTENT_TYPE;
-            } else {
-                soapContentType = SOAP12Constants.SOAP_12_CONTENT_TYPE;
-            }
             rootPartContentType = "application/xop+xml; charset=" + 
format.getCharSetEncoding()
                     + "; type=\"" + soapContentType + "\"";            
         } else {
-            // TODO: need to support SwA here
-            throw new IllegalArgumentException();
+            rootPartContentType = soapContentType + "; charset=" + 
format.getCharSetEncoding();
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to