You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2011/07/30 16:29:52 UTC

svn commit: r1152474 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/ axiom-api/src/main/java/org/apache/axiom/om/impl/ axiom-tests/src/test/java/org/apache/axiom/attachments/

Author: veithen
Date: Sat Jul 30 14:29:51 2011
New Revision: 1152474

URL: http://svn.apache.org/viewvc?rev=1152474&view=rev
Log:
AXIOM-119: Always preserve the order of attachments (which was already the default behavior since r785554). There is no use case where the pre-r785554 behavior (i.e. sorting attachments by content ID) would be mandatory [1], and removing support for this frees us from the constraint of maintaining two collections with different orders in the Attachments class.

[1] XOP explicitly specifies that the order of MIME parts is irrelevant. The same should be true for SwA messages using swaRef. Finally, for services described using the WSDL MIME binding, preserving the order of attachments is mandatory.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
    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-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java?rev=1152474&r1=1152473&r2=1152474&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java Sat Jul 30 14:29:51 2011
@@ -90,14 +90,15 @@ public class OMOutputFormat {
     public static final String USE_CTE_BASE64_FOR_NON_TEXTUAL_ATTACHMENTS = 
         "org.apache.axiom.om.OMFormat.use.cteBase64.forNonTextualAttachments";
     
-    // The old default behavior for the swa output attachment order was the 
-    // natural order of the content ids.
-    //
-    // There are some customers who want the output order to match the 
-    // input order for swa attachments.
+    /**
+     * @deprecated As of version 1.2.13, Axiom always respects the order of attachments.
+     */
     public static final String RESPECT_SWA_ATTACHMENT_ORDER =
         "org.apache.axiom.om.OMFormat.respectSWAAttachmentOrder";
     
+    /**
+     * @deprecated As of version 1.2.13, Axiom always respects the order of attachments.
+     */
     public static final Boolean RESPECT_SWA_ATTACHMENT_ORDER_DEFAULT =
         Boolean.TRUE;
     

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=1152474&r1=1152473&r2=1152474&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 Sat Jul 30 14:29:51 2011
@@ -254,15 +254,7 @@ public class MIMEOutputUtils {
             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();
-            }
+            Collection ids = Arrays.asList(attachments.getAllContentIDs());
             
             for (Iterator it = ids.iterator(); it.hasNext(); ) {
                 String id = (String)it.next();
@@ -358,15 +350,7 @@ public class MIMEOutputUtils {
                 innerFormat.setMimeBoundary(innerBoundary);
                 OutputStream innerOutputStream = mpw.writePart("multipart/related; boundary=\"" + innerBoundary + "\"", innerPartCID);
                 OMMultipartWriter innerMpw = new OMMultipartWriter(innerOutputStream, innerFormat);
-                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();
-                }
+                Collection ids = Arrays.asList(attachments.getAllContentIDs());
                 for (Iterator it = ids.iterator(); it.hasNext(); ) {
                     String id = (String)it.next();
                     innerMpw.writePart(attachments.getDataHandler(id), id);
@@ -380,16 +364,4 @@ public class MIMEOutputUtils {
             throw new OMException("Error while writing to the OutputStream.", e);
         }
     }
-    
-    /**
-     * @param format
-     * @return true if the incoming attachment order should be respected
-     */
-    private static boolean respectSWAAttachmentOrder(OMOutputFormat format) {
-        Boolean value = (Boolean) format.getProperty(OMOutputFormat.RESPECT_SWA_ATTACHMENT_ORDER);
-        if (value == null) {
-            value = OMOutputFormat.RESPECT_SWA_ATTACHMENT_ORDER_DEFAULT;
-        }
-        return value.booleanValue();
-    }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java?rev=1152474&r1=1152473&r2=1152474&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java Sat Jul 30 14:29:51 2011
@@ -139,41 +139,6 @@ public class AttachmentsTest extends Abs
         assertTrue(outBase64ToBase64.indexOf("GBgcGBQgHBwcJCQgKDBQNDAsL") != -1);
     }
     
-    public void testSWAWriteWithContentIDOrder() throws Exception {
-
-        // Read the stream that has soap xml followed by BAttachment then AAttachment
-        InputStream inStream = getTestResource(inSWAFileName);
-        Attachments attachments = new Attachments(inStream, contentTypeString);
-
-        // Get the contentIDs to force the reading
-        String[] contentIDs = attachments.getAllContentIDs();
-        
-        // Get the root
-        XMLStreamReader reader =
-                StAXUtils.createXMLStreamReader(new BufferedReader(new InputStreamReader(attachments.getSOAPPartInputStream())));
-        MTOMStAXSOAPModelBuilder builder = 
-            new MTOMStAXSOAPModelBuilder(reader, attachments, null);
-        OMElement root = builder.getDocumentElement();
-        StringWriter xmlWriter = new StringWriter();
-        root.serialize(xmlWriter);
-        
-        // Serialize the message using the legacy behavior (order by content id)
-        OMOutputFormat format = new OMOutputFormat();
-        format.setCharSetEncoding("utf-8");
-        format.setDoingSWA(true);
-        format.setProperty(OMOutputFormat.RESPECT_SWA_ATTACHMENT_ORDER, Boolean.FALSE);
-        
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        
-        MIMEOutputUtils.writeSOAPWithAttachmentsMessage(xmlWriter, baos, attachments, format);
-        
-        String text = baos.toString();
-        // Assert that AAttachment occurs before BAttachment since
-        // that is the natural ordering of the content ids.
-        assertTrue(text.indexOf("AAttachment") < text.indexOf("BAttachment"));
-        
-    }
-    
     public void testSWAWriteWithIncomingOrder() throws Exception {
 
         // Read the stream that has soap xml followed by BAttachment then AAttachment
@@ -196,7 +161,6 @@ public class AttachmentsTest extends Abs
         OMOutputFormat format = new OMOutputFormat();
         format.setCharSetEncoding("utf-8");
         format.setDoingSWA(true);
-        format.setProperty(OMOutputFormat.RESPECT_SWA_ATTACHMENT_ORDER, Boolean.TRUE);
         
         ByteArrayOutputStream baos = new ByteArrayOutputStream();