Author: dims
Date: Sun Jun 21 12:05:56 2009
New Revision: 787001
URL: http://svn.apache.org/viewvc?rev=787001&view=rev
Log:
Added back the change for WSCOMMONS-477 which was originally added in r785554
and reverted by Andreas in r786897.
When removeDataHandler is called, the specific cid was not being removed from
cids array list. Added a new test case as well.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/DeleteAttachmentTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/soap/soap11/SWAAttachmentStream.txt
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
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/attachments/Attachments.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java?rev=787001&r1=787000&r2=787001&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
Sun Jun 21 12:05:56 2009
@@ -389,7 +389,7 @@
}
}
}
- if (!cids.contains(blobContentID)) {
+ if (cids.contains(blobContentID)) {
cids.remove(blobContentID);
}
}
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=787001&r1=787000&r2=787001&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
Sun Jun 21 12:05:56 2009
@@ -72,6 +72,18 @@
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.
+ public static final String RESPECT_SWA_ATTACHMENT_ORDER =
+ "org.apache.axiom.om.OMFormat.respectSWAAttachmentOrder";
+
+ public static final Boolean RESPECT_SWA_ATTACHMENT_ORDER_DEFAULT =
+ Boolean.TRUE;
+
+
HashMap map = null; // Map of generic properties
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=787001&r1=787000&r2=787001&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
Sun Jun 21 12:05:56 2009
@@ -22,6 +22,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringWriter;
+import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
@@ -260,14 +261,40 @@
javax.activation.DataHandler dh = new javax.activation.DataHandler(
writer.toString(), "text/xml; charset="
+ format.getCharSetEncoding());
- writeDataHandlerWithAttachmentsMessage(dh, contentType, outputStream,
attachments.getMap(), format);
+
+ // 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();
+ }
+ writeDataHandlerWithAttachmentsMessage(dh, contentType, outputStream,
+ attachments.getMap(), format, ids);
}
public static void writeDataHandlerWithAttachmentsMessage(DataHandler
rootDataHandler,
+ String contentType,
+ OutputStream outputStream,
+ Map attachments,
+ OMOutputFormat format) {
+ writeDataHandlerWithAttachmentsMessage(rootDataHandler,
+ contentType,
+ outputStream,
+ attachments,
+ format,
+ null);
+
+ }
+ public static void writeDataHandlerWithAttachmentsMessage(DataHandler
rootDataHandler,
String contentType,
OutputStream
outputStream,
Map attachments,
- OMOutputFormat format) {
+ OMOutputFormat format,
+ Collection ids) {
try {
startWritingMime(outputStream, format.getMimeBoundary());
@@ -282,9 +309,20 @@
writeBodyPart(outputStream, rootMimeBodyPart, format
.getMimeBoundary());
- Iterator iterator = attachments.keySet().iterator();
- while (iterator.hasNext()) {
- String key = (String) iterator.next();
+ Iterator idIterator = null;
+ if (ids == null) {
+ // If ids are not provided, use the attachment map
+ // to get the keys
+ idIterator = attachments.keySet().iterator();
+ } else {
+ // if ids are provided (normal case), iterate
+ // over the ids so that the attachments are
+ // written in the same order as the id keys.
+ idIterator = ids.iterator();
+ }
+
+ while (idIterator.hasNext()) {
+ String key = (String) idIterator.next();
MimeBodyPart part = createMimeBodyPart(key,
(DataHandler) attachments.get(key), format);
writeBodyPart(outputStream, part,
@@ -357,7 +395,15 @@
outputStream.write(CRLF);
outputStream.write(CRLF);
startWritingMime(outputStream, innerBoundary);
- Iterator attachmentIDIterator =
attachments.getContentIDSet().iterator();
+ Iterator attachmentIDIterator = null;
+ if (respectSWAAttachmentOrder(format)) {
+ // ContentIDList is the order of the incoming/added
attachments
+ attachmentIDIterator =
attachments.getContentIDList().iterator();
+ } else {
+ // ContentIDSet is an undefined order (the
implemenentation currently
+ // orders the attachments using the natural order of the
content ids)
+ attachmentIDIterator =
attachments.getContentIDSet().iterator();
+ }
while (attachmentIDIterator.hasNext()) {
String contentID = (String) attachmentIDIterator.next();
DataHandler dataHandler =
attachments.getDataHandler(contentID);
@@ -376,4 +422,16 @@
throw new OMException("Problem writing Mime Parts.", 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();
+ }
}
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/DeleteAttachmentTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/DeleteAttachmentTest.java?rev=787001&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/DeleteAttachmentTest.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/DeleteAttachmentTest.java
Sun Jun 21 12:05:56 2009
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.attachments;
+
+import org.apache.axiom.om.AbstractTestCase;
+import org.apache.axiom.om.TestConstants;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.List;
+
+
+public class DeleteAttachmentTest extends AbstractTestCase {
+ File temp;
+
+ public void testIncomingAttachmentInputStreamFunctions() throws Exception {
+ InputStream inStream = getTestResource(TestConstants.MTOM_MESSAGE);
+ Attachments attachments = new Attachments(inStream,
TestConstants.MTOM_MESSAGE_CONTENT_TYPE);
+
+ Collection list = attachments.getContentIDSet();
+ assertEquals(3, list.size());
+
+
assertTrue(list.contains("1.urn:uuid:[email protected]"));
+
assertTrue(list.contains("2.urn:uuid:[email protected]"));
+
+
attachments.removeDataHandler("1.urn:uuid:[email protected]");
+
+ List list2 = attachments.getContentIDList();
+ assertEquals(2, list2.size());
+ assertEquals(2, attachments.getMap().size());
+
+
assertFalse(list2.contains("1.urn:uuid:[email protected]"));
+
assertTrue(list2.contains("2.urn:uuid:[email protected]"));
+ }
+}
\ No newline at end of file