ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1205235 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/attachments/ axiom-api/src/test/java/org/apache/axiom/attachments/ axiom-api/src/test/java/org/apache/axiom/om/ axiom-tests/src/test/ja...
Date Tue, 22 Nov 2011 23:33:31 GMT
Author: veithen
Date: Tue Nov 22 23:33:30 2011
New Revision: 1205235

URL: http://svn.apache.org/viewvc?rev=1205235&view=rev
Log:
AXIOM-378: Clarified the Attachments#getAttachmentSpecType() API.

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/test/java/org/apache/axiom/attachments/AttachmentsTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/TestConstants.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=1205235&r1=1205234&r2=1205235&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
Tue Nov 22 23:33:30 2011
@@ -25,6 +25,8 @@ import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.impl.MTOMConstants;
 
 import javax.activation.DataHandler;
+import javax.mail.internet.ContentType;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
@@ -143,17 +145,23 @@ public class Attachments implements OMAt
     }
 
     /**
-     * Identify the type of message (MTOM or SOAP with attachments) represented by this
-     * object.
+     * Identify the type of message (MTOM or SOAP with attachments) represented by this object.
Note
+     * that this method is only meaningful if the instance was created from a stream.
      * 
-     * @return One of the {@link MTOMConstants#MTOM_TYPE}, {@link MTOMConstants#SWA_TYPE}
-     *         or {@link MTOMConstants#SWA_TYPE_12} constants.
-     * @throws OMException if the message doesn't have one of the supported types, i.e. is
-     *         neither MTOM nor SOAP with attachments
+     * @return One of the {@link MTOMConstants#MTOM_TYPE}, {@link MTOMConstants#SWA_TYPE}
or
+     *         {@link MTOMConstants#SWA_TYPE_12} constants.
+     * @throws OMException
+     *             if the message doesn't have one of the supported types (i.e. is neither
MTOM nor
+     *             SOAP with attachments) or if the instance was not created from a stream
      */
     public String getAttachmentSpecType() {
         if (this.applicationType == null) {
-            applicationType = impl.getContentType().getParameter("type");
+            ContentType contentType = impl.getContentType();
+            if (contentType == null) {
+                throw new OMException("Unable to determine the attachment spec type because
the " +
+                		"Attachments object doesn't have a known content type");
+            }
+            applicationType = contentType.getParameter("type");
             if ((MTOMConstants.MTOM_TYPE).equalsIgnoreCase(applicationType)) {
                 this.applicationType = MTOMConstants.MTOM_TYPE;
             } else if ((MTOMConstants.SWA_TYPE).equalsIgnoreCase(applicationType)) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java?rev=1205235&r1=1205234&r2=1205235&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
Tue Nov 22 23:33:30 2011
@@ -44,8 +44,10 @@ import javax.mail.util.ByteArrayDataSour
 
 import org.apache.axiom.attachments.lifecycle.DataHandlerExt;
 import org.apache.axiom.om.AbstractTestCase;
+import org.apache.axiom.om.MIMEResource;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.TestConstants;
+import org.apache.axiom.om.impl.MTOMConstants;
 import org.apache.axiom.testutils.activation.RandomDataSource;
 import org.apache.axiom.testutils.io.IOTestUtils;
 import org.apache.axiom.util.UIDGenerator;
@@ -660,4 +662,31 @@ public class AttachmentsTest extends Abs
     public void testTurkishLocale2() throws Exception {
         testTurkishLocale("content-id");
     }
+    
+    private void testGetAttachmentSpecType(MIMEResource resource, String expectedResult)
throws Exception {
+        InputStream in = getTestResource(resource.getName());
+        try {
+            Attachments attachments = new Attachments(in, resource.getContentType());
+            assertEquals(expectedResult, attachments.getAttachmentSpecType());
+        } finally {
+            in.close();
+        }
+    }
+    
+    public void testGetAttachmentSpecTypeMTOM() throws Exception {
+        testGetAttachmentSpecType(TestConstants.MTOM_MESSAGE, MTOMConstants.MTOM_TYPE);
+    }
+    
+    public void testGetAttachmentSpecTypeSWA() throws Exception {
+        testGetAttachmentSpecType(TestConstants.SWA_MESSAGE, MTOMConstants.SWA_TYPE);
+    }
+    
+    public void testGetAttachmentSpecTypeWithoutStream() {
+        try {
+            new Attachments().getAttachmentSpecType();
+            fail("Expected OMException");
+        } catch (OMException ex) {
+            // Expected
+        }
+    }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/TestConstants.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/TestConstants.java?rev=1205235&r1=1205234&r2=1205235&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/TestConstants.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/TestConstants.java
Tue Nov 22 23:33:30 2011
@@ -47,6 +47,13 @@ public class TestConstants {
             "multipart/Related; charset=\"UTF-8\"; type=\"application/xop+xml\"; " +
             "boundary=\"----=_AxIs2_Def_boundary_=42214532\"; start=\"SOAPPart\"");
     
+    public static final MIMEResource SWA_MESSAGE = new MIMEResource(
+            "soap/soap11/SWAAttachmentStream.txt",
+            "multipart/related; " +
+            "boundary=\"MIMEBoundaryurn:uuid:A3ADBAEE51A1A87B2A11443668160701\"; " +
+            "type=\"text/xml\"; " +
+            "start=\"<0.urn:uuid:A3ADBAEE51A1A87B2A11443668160702@apache.org>\"");
+    
     private TestConstants() {
     }
 

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=1205235&r1=1205234&r2=1205235&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
Tue Nov 22 23:33:30 2011
@@ -42,11 +42,6 @@ public class AttachmentsTest extends Abs
         super(testName);
     }
 
-    String inSWAFileName = "soap/soap11/SWAAttachmentStream.txt";
-    
-    String contentTypeString =
-        "multipart/related; boundary=\"MIMEBoundaryurn:uuid:A3ADBAEE51A1A87B2A11443668160701\";
type=\"application/xop+xml\"; start=\"<0.urn:uuid:A3ADBAEE51A1A87B2A11443668160702@apache.org>\";
start-info=\"application/soap+xml\"; charset=UTF-8;action=\"mtomSample\"";
-
     public void testWritingBinaryAttachments() throws Exception {
         MIMEResource testMessage = TestConstants.MTOM_MESSAGE;
 
@@ -135,8 +130,8 @@ public class AttachmentsTest extends Abs
     public void testSWAWriteWithIncomingOrder() throws Exception {
 
         // Read the stream that has soap xml followed by BAttachment then AAttachment
-        InputStream inStream = getTestResource(inSWAFileName);
-        Attachments attachments = new Attachments(inStream, contentTypeString);
+        InputStream inStream = getTestResource(TestConstants.SWA_MESSAGE.getName());
+        Attachments attachments = new Attachments(inStream, TestConstants.SWA_MESSAGE.getContentType());
 
         // Get the contentIDs to force the reading
         String[] contentIDs = attachments.getAllContentIDs();



Mime
View raw message