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 2016/04/28 23:58:59 UTC

svn commit: r1741531 - in /webservices/axiom/trunk/axiom-api: ./ src/main/java/org/apache/axiom/attachments/

Author: veithen
Date: Thu Apr 28 21:58:59 2016
New Revision: 1741531

URL: http://svn.apache.org/viewvc?rev=1741531&view=rev
Log:
AXIOM-350: Expose the getInputStream method through the Part interface and simplify the logic to retrieve the root part of a MIMEMessage.

Modified:
    webservices/axiom/trunk/axiom-api/pom.xml
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessageAdapter.java
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/Part.java
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java

Modified: webservices/axiom/trunk/axiom-api/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/pom.xml?rev=1741531&r1=1741530&r2=1741531&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/pom.xml (original)
+++ webservices/axiom/trunk/axiom-api/pom.xml Thu Apr 28 21:58:59 2016
@@ -272,6 +272,7 @@
                                         org.apache.axiom.attachments.AttachmentSet -> org.apache.axiom.om.OMException,
                                         org.apache.axiom.attachments.IncomingAttachmentStreams -> org.apache.axiom.om.OMException,
                                         org.apache.axiom.attachments.MIMEMessage -> org.apache.axiom.om.OMException,
+                                        org.apache.axiom.attachments.MIMEMessageAdapter -> org.apache.axiom.om.OMException,
                                         org.apache.axiom.attachments.MultipartAttachmentStreams -> org.apache.axiom.om.OMException,
                                         org.apache.axiom.attachments.PartImpl -> org.apache.axiom.om.OMException,
                                         <!-- Bad API design: a public API shouldn't depend on classes in an impl package in its interface -->

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java?rev=1741531&r1=1741530&r2=1741531&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java Thu Apr 28 21:58:59 2016
@@ -30,7 +30,6 @@ import java.util.Set;
 
 import javax.activation.DataHandler;
 
-import org.apache.axiom.attachments.lifecycle.DataHandlerExt;
 import org.apache.axiom.blob.Blobs;
 import org.apache.axiom.blob.WritableBlob;
 import org.apache.axiom.blob.WritableBlobFactory;
@@ -86,6 +85,7 @@ class MIMEMessage {
     private boolean partsRequested;
 
     private PartImpl firstPart;
+    private PartImpl rootPart;
 
     private final WritableBlobFactory attachmentBlobFactory;
     
@@ -142,23 +142,14 @@ class MIMEMessage {
         return null;
     }
 
-    InputStream getRootPartInputStream(boolean preserve) throws OMException {
-        DataHandler dh;
-        try {
-            dh = getDataHandler(getRootPartContentID());
-            if (dh == null) {
-                throw new OMException(
-                        "Mandatory root MIME part is missing");
-            }
-            if (!preserve && dh instanceof DataHandlerExt) {
-                return ((DataHandlerExt)dh).readOnce();
-            } else {
-                return dh.getInputStream();
+    Part getRootPart() {
+        do {
+            if (rootPart != null) {
+                return rootPart;
             }
-        } catch (IOException e) {
-            throw new OMException(
-                    "Problem with DataHandler of the Root Mime Part. ", e);
-        }
+        } while (getNextPart() != null);
+        throw new OMException(
+                "Mandatory root MIME part is missing");
     }
 
     String getRootPartContentID() {
@@ -288,6 +279,9 @@ class MIMEMessage {
                         "Two MIME parts with the same Content-ID not allowed.");
             }
             partMap.put(partContentID, currentPart);
+            if (isRootPart) {
+                rootPart = currentPart;
+            }
             return currentPart;
         }
     }

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessageAdapter.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessageAdapter.java?rev=1741531&r1=1741530&r2=1741531&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessageAdapter.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessageAdapter.java Thu Apr 28 21:58:59 2016
@@ -31,6 +31,7 @@ import javax.activation.DataHandler;
 
 import org.apache.axiom.blob.WritableBlobFactory;
 import org.apache.axiom.mime.ContentType;
+import org.apache.axiom.om.OMException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -92,7 +93,11 @@ final class MIMEMessageAdapter extends A
 
     @Override
     InputStream getRootPartInputStream(boolean preserve) {
-        return message.getRootPartInputStream(preserve);
+        try {
+            return message.getRootPart().getInputStream(preserve);
+        } catch (IOException ex) {
+            throw new OMException("Problem fetching the root part", ex);
+        }
     }
 
     @Override

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/Part.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/Part.java?rev=1741531&r1=1741530&r2=1741531&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/Part.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/Part.java Thu Apr 28 21:58:59 2016
@@ -18,6 +18,9 @@
  */
 package org.apache.axiom.attachments;
 
+import java.io.IOException;
+import java.io.InputStream;
+
 import javax.activation.DataHandler;
 
 /**
@@ -54,4 +57,16 @@ public interface Part {
      * @return value or null
      */
     public String getHeader(String name);
+
+    /**
+     * Get the content of this part.
+     * 
+     * @param preserve
+     *            {@code true} if the content should be preserved so that it can be read multiple
+     *            times, {@code false} to discard the content when it is read
+     * @return the content of the part
+     * @throws IOException
+     *             if the content couldn't be read
+     */
+    public InputStream getInputStream(boolean preserve) throws IOException;
 }

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java?rev=1741531&r1=1741530&r2=1741531&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java Thu Apr 28 21:58:59 2016
@@ -233,7 +233,7 @@ final class PartImpl implements Part {
         parser = null;
     }
     
-    InputStream getInputStream(boolean preserve) throws IOException {
+    public InputStream getInputStream(boolean preserve) throws IOException {
         if (!preserve && state == STATE_UNREAD) {
             checkParserState(parser.getState(), EntityState.T_BODY);
             state = STATE_STREAMING;