ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1154682 - in /webservices/commons/trunk/modules/axiom: modules/axiom-api/src/main/java/org/apache/axiom/attachments/ modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/ modules/axiom-api/src/test/java/org/apache/axiom/attach...
Date Sun, 07 Aug 2011 10:27:32 GMT
Author: veithen
Date: Sun Aug  7 10:27:32 2011
New Revision: 1154682

URL: http://svn.apache.org/viewvc?rev=1154682&view=rev
Log:
AXIOM-377 (step 2): Reversed the DataHandler creation logic. In 1.2.12, the DataHandler is
created by PartOnFile/PartOnMemory, i.e. after the MIME part content has been buffered. If
we want to support streaming, then the DataHandler must be created before we decide whether
the content is streamed or buffered and how it is buffered. Note that this implies that we
now always create a DataHandler implementing DataHandlerExt. For memory buffered parts, the
purgeDataSource method will simply release the allocated memory.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartDataHandler.java
  (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartDataSource.java
  (with props)
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Part.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/ContentOnFile.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/ContentOnMemory.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/ContentStore.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/ContentStoreFactory.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/PartOnFileTest.java
    webservices/commons/trunk/modules/axiom/src/docbkx/userguide.xml

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java?rev=1154682&r1=1154681&r2=1154682&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java
Sun Aug  7 10:27:32 2011
@@ -28,7 +28,6 @@ import java.util.Set;
 
 import javax.activation.DataHandler;
 import javax.mail.Header;
-import javax.mail.MessagingException;
 import javax.mail.internet.ContentType;
 import javax.mail.internet.ParseException;
 
@@ -292,59 +291,48 @@ class MIMEMessage extends AttachmentsImp
             return null;
         } else {
             Part nextPart = getPart();
-            try {
-                long size = nextPart.getSize();
-                String partContentID;
-                DataHandler dataHandler;
-                try {
-                    partContentID = nextPart.getContentID();
-
-                    if (partContentID == null & partIndex == 1) {
-                        String id = "firstPart_" + UIDGenerator.generateContentId();
-                        firstPartId = id;
-                        if (size > 0) {
-                            dataHandler = nextPart.getDataHandler();
-                        } else {
-                            // Either the mime part is empty or the stream ended without
having 
-                            // a MIME message terminator
-                            dataHandler = new DataHandler(new ByteArrayDataSource(new byte[]{}));
-                        }
-                        addDataHandler(id, dataHandler);
-                        return dataHandler;
-                    }
-                    if (partContentID == null) {
-                        throw new OMException(
-                                "Part content ID cannot be blank for non root MIME parts");
-                    }
-                    if ((partContentID.indexOf("<") > -1)
-                            & (partContentID.indexOf(">") > -1)) {
-                        partContentID = partContentID.substring(1, (partContentID
-                                .length() - 1));
-
-                    }
-                    if (partIndex == 1) {
-                        firstPartId = partContentID;
-                    }
-                    if (attachmentsMap.containsKey(partContentID)) {
-                        throw new OMException(
-                                "Two MIME parts with the same Content-ID not allowed.");
-                    }
-                    if (size > 0) {
-                        dataHandler = nextPart.getDataHandler();
-                    } else {
-                        // Either the mime part is empty or the stream ended without having

-                        // a MIME message terminator
-                        dataHandler = new DataHandler(new ByteArrayDataSource(new byte[]{}));
-                    }
-                    addDataHandler(partContentID, dataHandler);
-                    return dataHandler;
-                } catch (MessagingException e) {
-                    throw new OMException("Error reading Content-ID from the Part."
-                            + e);
+            long size = nextPart.getSize();
+            String partContentID = nextPart.getContentID();
+            DataHandler dataHandler;
+            if (partContentID == null & partIndex == 1) {
+                String id = "firstPart_" + UIDGenerator.generateContentId();
+                firstPartId = id;
+                if (size > 0) {
+                    dataHandler = nextPart.getDataHandler();
+                } else {
+                    // Either the mime part is empty or the stream ended without having 
+                    // a MIME message terminator
+                    dataHandler = new DataHandler(new ByteArrayDataSource(new byte[]{}));
                 }
-            } catch (MessagingException e) {
-                throw new OMException(e);
+                addDataHandler(id, dataHandler);
+                return dataHandler;
+            }
+            if (partContentID == null) {
+                throw new OMException(
+                        "Part content ID cannot be blank for non root MIME parts");
+            }
+            if ((partContentID.indexOf("<") > -1)
+                    & (partContentID.indexOf(">") > -1)) {
+                partContentID = partContentID.substring(1, (partContentID
+                        .length() - 1));
+
+            }
+            if (partIndex == 1) {
+                firstPartId = partContentID;
+            }
+            if (attachmentsMap.containsKey(partContentID)) {
+                throw new OMException(
+                        "Two MIME parts with the same Content-ID not allowed.");
+            }
+            if (size > 0) {
+                dataHandler = nextPart.getDataHandler();
+            } else {
+                // Either the mime part is empty or the stream ended without having 
+                // a MIME message terminator
+                dataHandler = new DataHandler(new ByteArrayDataSource(new byte[]{}));
             }
+            addDataHandler(partContentID, dataHandler);
+            return dataHandler;
         }
     }
 
@@ -366,11 +354,9 @@ class MIMEMessage extends AttachmentsImp
         try {
             Hashtable headers = readHeaders();
             
-            Header contentTypeHeader = (Header)headers.get("content-type");
             // The PartFactory will determine which Part implementation is most appropriate.
             ContentStore content = ContentStoreFactory.createContentStore(getLifecycleManager(),
parser, 
                                           isSOAPPart, 
-                                          contentTypeHeader == null ? null : contentTypeHeader.getValue(),
                                           threshhold, 
                                           attachmentRepoDir, 
                                           contentLength);  // content-length for the whole
message

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Part.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Part.java?rev=1154682&r1=1154681&r2=1154682&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Part.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Part.java
Sun Aug  7 10:27:32 2011
@@ -36,27 +36,23 @@ public interface Part {
 
     /**
      * @return DataHandler representing this part
-     * @throws MessagingException
      */
-    public DataHandler getDataHandler() throws MessagingException;
+    public DataHandler getDataHandler();
     
     /**
      * @return size
-     * @throws MessagingException
      */
-    public long getSize() throws MessagingException;
+    public long getSize();
 
     /**
      * @return content type of the part
-     * @throws MessagingException
      */
-    public String getContentType() throws MessagingException;
+    public String getContentType();
 
     /**
      * @return content id of the part
-     * @throws MessagingException
      */
-    public String getContentID() throws MessagingException;
+    public String getContentID();
 
     /**
      * Get the value of a specific header

Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartDataHandler.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartDataHandler.java?rev=1154682&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartDataHandler.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartDataHandler.java
Sun Aug  7 10:27:32 2011
@@ -0,0 +1,44 @@
+/*
+ * 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 java.io.IOException;
+
+import javax.activation.DataHandler;
+
+import org.apache.axiom.attachments.lifecycle.DataHandlerExt;
+
+class PartDataHandler extends DataHandler implements DataHandlerExt {
+    private final PartImpl part;
+
+    public PartDataHandler(PartImpl part) {
+        super(new PartDataSource(part));
+        this.part = part;
+    }
+
+    public void purgeDataSource() throws IOException {
+        part.releaseContent();
+    }
+
+    public void deleteWhenReadOnce() throws IOException {
+        // As shown in AXIOM-381, in all released versions of Axiom, deleteWhenReadOnce
+        // always has the same effect as purgeDataSource
+        purgeDataSource();
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartDataHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartDataSource.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartDataSource.java?rev=1154682&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartDataSource.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartDataSource.java
Sun Aug  7 10:27:32 2011
@@ -0,0 +1,50 @@
+/*
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.activation.DataSource;
+
+class PartDataSource implements DataSource {
+    private final PartImpl part;
+
+    public PartDataSource(PartImpl part) {
+        this.part = part;
+    }
+
+    public String getContentType() {
+        String ct = part.getContentType();
+        return ct == null ? "application/octet-stream" : ct;
+    }
+
+    public InputStream getInputStream() throws IOException {
+        return part.getInputStream();
+    }
+
+    public String getName() {
+        return part.getContentID();
+    }
+
+    public OutputStream getOutputStream() throws IOException {
+        throw new UnsupportedOperationException();
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartDataSource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java?rev=1154682&r1=1154681&r2=1154682&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java
Sun Aug  7 10:27:32 2011
@@ -29,6 +29,9 @@ import javax.mail.Header;
 import javax.mail.MessagingException;
 import javax.mail.internet.HeaderTokenizer;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.Hashtable;
 
 /**
@@ -43,6 +46,7 @@ final class PartImpl implements Part {
     private Hashtable headers;
     
     private final ContentStore content;
+    private final DataHandler dataHandler;
     
     /**
      * The actual parts are constructed with the PartFactory.
@@ -55,6 +59,7 @@ final class PartImpl implements Part {
             headers = new Hashtable();
         }
         this.content = content;
+        this.dataHandler = new PartDataHandler(this);
     }
     
     public String getHeader(String name) {
@@ -67,11 +72,11 @@ final class PartImpl implements Part {
         return value;
     }
 
-    public String getContentID() throws MessagingException {
+    public String getContentID() {
         return getHeader("content-id");
     }
 
-    public String getContentType() throws MessagingException {
+    public String getContentType() {
         return getHeader("content-type");
     }
     
@@ -122,12 +127,23 @@ final class PartImpl implements Part {
 
     }
 
-    public DataHandler getDataHandler() throws MessagingException {
-        return content.getDataHandler();
+    public DataHandler getDataHandler() {
+        return dataHandler;
     }
 
-    public long getSize() throws MessagingException {
+    public long getSize() {
         return content.getSize();
     }
 
+    InputStream getInputStream() throws IOException {
+        return content.getInputStream();
+    }
+    
+    void writeTo(OutputStream out) throws IOException {
+        content.writeTo(out);
+    }
+
+    void releaseContent() throws IOException {
+        content.destroy();
+    }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/ContentOnFile.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/ContentOnFile.java?rev=1154682&r1=1154681&r2=1154682&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/ContentOnFile.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/ContentOnFile.java
Sun Aug  7 10:27:32 2011
@@ -22,7 +22,6 @@ package org.apache.axiom.attachments.imp
 import org.apache.axiom.attachments.lifecycle.LifecycleManager;
 import org.apache.axiom.attachments.lifecycle.impl.FileAccessor;
 
-import javax.activation.DataHandler;
 import javax.mail.MessagingException;
 import java.io.IOException;
 import java.io.InputStream;
@@ -44,13 +43,12 @@ public class ContentOnFile extends Conte
     
     /**
      * Create a PartOnFile from the specified InputStream
-     * @param headers Hashtable of javax.mail.Headers
      * @param in1 InputStream containing data
      * @param in2 InputStream containing data
      * @param attachmentDir String 
      */
-    ContentOnFile(LifecycleManager manager, String contentType, InputStream is1, InputStream
is2, String attachmentDir) throws IOException {
-        super(contentType);
+    ContentOnFile(LifecycleManager manager, InputStream is1, InputStream is2, String attachmentDir)
throws IOException {
+        this.manager = manager;
         fileAccessor = manager.create(attachmentDir);
         
         // Now write the data to the backing file
@@ -62,13 +60,27 @@ public class ContentOnFile extends Conte
         
     }
 
-    /* (non-Javadoc)
-     * @see org.apache.axiom.attachments.impl.AbstractPart#getDataHandler()
-     */
-    public DataHandler getDataHandler() throws MessagingException {
-        return fileAccessor.getDataHandler(getContentType());
+    public InputStream getInputStream() throws IOException {
+        try {
+            return fileAccessor.getInputStream();
+        } catch (MessagingException ex) {
+            // The FileAccessor API uses MessagingException, although we no longer use javax.mail.
+            // Convert the exception to an IOException to keep the attachments API clean.
+            IOException ex2 = new IOException(ex.getMessage());
+            ex2.setStackTrace(ex.getStackTrace());
+            throw ex2;
+        }
     }
     
+    public void writeTo(OutputStream out) throws IOException {
+        InputStream in = getInputStream();
+        try {
+            BufferUtils.inputStream2OutputStream(in, out);
+        } finally {
+            in.close();
+        }
+    }
+
     /* (non-Javadoc)
      * @see org.apache.axiom.attachments.impl.AbstractPart#getSize()
      */
@@ -76,4 +88,8 @@ public class ContentOnFile extends Conte
         return fileAccessor.getSize();
     }
 
+    public void destroy() throws IOException {
+        manager.delete(fileAccessor.getFile());
+        // TODO: recover the shutdown hook code from DataHandlerExtImpl
+    }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/ContentOnMemory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/ContentOnMemory.java?rev=1154682&r1=1154681&r2=1154682&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/ContentOnMemory.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/ContentOnMemory.java
Sun Aug  7 10:27:32 2011
@@ -21,10 +21,6 @@ package org.apache.axiom.attachments.imp
 
 import org.apache.axiom.attachments.utils.BAAInputStream;
 
-import javax.activation.DataHandler;
-import javax.activation.DataSource;
-import javax.mail.MessagingException;
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -45,81 +41,27 @@ public class ContentOnMemory extends Con
     
     /**
      * Construct a PartOnMemory
-     * @param headers
      * @param data array list of 4K byte[]
      * @param length (length of data in bytes)
      */
-    ContentOnMemory(String contentType, ArrayList data, int length) {
-        super(contentType);
+    ContentOnMemory(ArrayList data, int length) {
         this.data =  data;
         this.length = length;
     }
 
-    public DataHandler getDataHandler() throws MessagingException {
-        DataSource ds = new MyByteArrayDataSource();
-        return new MyDataHandler(ds);
+    public InputStream getInputStream() {
+        return new BAAInputStream(data, length);
     }
     
-    public long getSize() throws MessagingException {
-        return length;
+    public void writeTo(OutputStream os) throws IOException {
+        new BAAInputStream(data, length).writeTo(os);
     }
     
-    
-    class MyDataHandler extends DataHandler {
-
-        DataSource ds;
-        public MyDataHandler(DataSource ds) {
-            super(ds);
-            this.ds = ds;
-        }
-
-        public void writeTo(OutputStream os) throws IOException {
-            InputStream is = ds.getInputStream();
-            if (is instanceof BAAInputStream) {
-                ((BAAInputStream)is).writeTo(os);
-            } else {
-                BufferUtils.inputStream2OutputStream(is, os);
-            }
-        }
+    public long getSize() {
+        return length;
     }
     
-    /**
-     * A DataSource that is backed by the byte[] and 
-     * headers map.
-     */
-    class MyByteArrayDataSource implements DataSource {
-
-        /* (non-Javadoc)
-         * @see javax.activation.DataSource#getContentType()
-         */
-        public String getContentType() {
-            String ct = ContentOnMemory.this.getContentType();
-            return (ct == null) ?
-                    "application/octet-stream" :
-                    ct;
-        }
-
-        /* (non-Javadoc)
-         * @see javax.activation.DataSource#getInputStream()
-         */
-        public InputStream getInputStream() throws IOException {
-            return new BAAInputStream(data, length);
-        }
-
-        /* (non-Javadoc)
-         * @see javax.activation.DataSource#getName()
-         */
-        public String getName() {
-            return "MyByteArrayDataSource";
-        }
-
-        /* (non-Javadoc)
-         * @see javax.activation.DataSource#getOutputStream()
-         */
-        public OutputStream getOutputStream() throws IOException {
-            throw new IOException("Not Supported");
-        }
-        
+    public void destroy() throws IOException {
+        data.clear();
     }
-
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/ContentStore.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/ContentStore.java?rev=1154682&r1=1154681&r2=1154682&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/ContentStore.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/ContentStore.java
Sun Aug  7 10:27:32 2011
@@ -19,26 +19,19 @@
 
 package org.apache.axiom.attachments.impl;
 
-import javax.activation.DataHandler;
-import javax.mail.MessagingException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 
 /**
  * Stores the content of a MIME part.
  */
 public abstract class ContentStore {
-    private final String contentType;
-    
-    ContentStore(String contentType) {
-        this.contentType = contentType;
-    }
-                                                 
-    public String getContentType() {
-        return contentType;
-    }
-    
-    // The following classes must be implemented by the derived class.
-    public abstract DataHandler getDataHandler() throws MessagingException;
+    public abstract InputStream getInputStream() throws IOException;
 
-    public abstract long getSize() throws MessagingException;
+    public abstract void writeTo(OutputStream out) throws IOException;
 
+    public abstract long getSize();
+
+    public abstract void destroy() throws IOException;
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/ContentStoreFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/ContentStoreFactory.java?rev=1154682&r1=1154681&r2=1154682&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/ContentStoreFactory.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/ContentStoreFactory.java
Sun Aug  7 10:27:32 2011
@@ -76,7 +76,6 @@ public class ContentStoreFactory {
      */
     public static ContentStore createContentStore(LifecycleManager manager, MimeTokenStream
parser,
                     boolean isSOAPPart,
-                    String contentType,
                     int thresholdSize,
                     String attachmentDir,
                     int messageContentLength
@@ -131,7 +130,7 @@ public class ContentStoreFactory {
                     // keeps the data in non-contiguous byte buffers.
                     BAAOutputStream baaos = new BAAOutputStream();
                     BufferUtils.inputStream2OutputStream(parser.getDecodedInputStream(),
baaos);
-                    part = new ContentOnMemory(contentType, baaos.buffers(), baaos.length());
+                    part = new ContentOnMemory(baaos.buffers(), baaos.length());
                 } else {
                     // We need to read the input stream to determine whether
                     // the size is bigger or smaller than the threshold.
@@ -140,13 +139,13 @@ public class ContentStoreFactory {
                     int count = BufferUtils.inputStream2OutputStream(in, baaos, thresholdSize);
 
                     if (count < thresholdSize) {
-                        part = new ContentOnMemory(contentType, baaos.buffers(), baaos.length());
+                        part = new ContentOnMemory(baaos.buffers(), baaos.length());
                     } else {
                         // A BAAInputStream is an input stream over a list of non-contiguous
4K buffers.
                         BAAInputStream baais = 
                             new BAAInputStream(baaos.buffers(), baaos.length());
 
-                        part = new ContentOnFile(manager, contentType, 
+                        part = new ContentOnFile(manager, 
                                               baais,
                                               in, 
                                               attachmentDir);

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/PartOnFileTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/PartOnFileTest.java?rev=1154682&r1=1154681&r2=1154682&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/PartOnFileTest.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/PartOnFileTest.java
Sun Aug  7 10:27:32 2011
@@ -60,9 +60,10 @@ public class PartOnFileTest extends Abst
 
         DataSource ds = dh.getDataSource();
         assertNotNull(ds);
-        if (!(ds instanceof FileDataSource)) {
-            fail("Expected FileDataSource, but got " + ds.getClass().getName());
-        }
+        // TODO: AXIOM-377 implies that we no longer get a FileDataSource; need some other
way to test that the attachment is written to file
+//        if (!(ds instanceof FileDataSource)) {
+//            fail("Expected FileDataSource, but got " + ds.getClass().getName());
+//        }
 
         assertEquals("image/jpeg", dh.getContentType());
     }

Modified: webservices/commons/trunk/modules/axiom/src/docbkx/userguide.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/src/docbkx/userguide.xml?rev=1154682&r1=1154681&r2=1154682&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/docbkx/userguide.xml (original)
+++ webservices/commons/trunk/modules/axiom/src/docbkx/userguide.xml Sun Aug  7 10:27:32 2011
@@ -1361,7 +1361,7 @@ while (iterator.hasNext()) {
                         </listitem>
                         <listitem>
                             <para>
-                                <classname>PartFactory</classname>
+                                <classname>PartFactory</classname> and related
classes
                             </para>
                         </listitem>
                     </itemizedlist>
@@ -1371,6 +1371,33 @@ while (iterator.hasNext()) {
                         to Axiom 1.2.13.
                     </para>
                 </section>
+                <section>
+                    <title>Support for MIME part streaming</title>
+                    <para>
+                        Axiom 1.2.13 has support for MIME part streaming. Pre-existing APIs
continue to work
+                        as documented, but there are some minor changes in behavior that
may be visible to
+                        code that makes assumptions that are not covered by the API contract:
+                    </para>
+                    <itemizedlist>
+                        <listitem>
+                            <para>
+                                The <classname>DataHandler</classname> instances
returned by <classname>Attachments</classname>
+                                for MIME parts read from a stream now always implement <classname>DataHandlerExt</classname>,
while
+                                in 1.2.12 this was only the case for parts buffered using
temporary files. For memory buffered
+                                MIME parts, a call to <methodname>purgeDataSource</methodname>
has the effect of releasing the
+                                allocated memory.
+                            </para>
+                        </listitem>
+                        <listitem>
+                            <para>
+                                The <classname>DataSource</classname> implementation
used for <classname>DataHandler</classname>
+                                instances for MIME parts read from a stream is now always
opaque, i.e. the implementation is
+                                an internal class not visible to application code. This implies
that application code must not
+                                make the assumption that a MIME part buffered on disk uses
a <classname>FileDataSource</classname>.
+                            </para>
+                        </listitem>
+                    </itemizedlist>
+                </section>
             </section>
         </section>
     </chapter>



Mime
View raw message