You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by th...@apache.org on 2006/09/11 11:18:42 UTC

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

Author: thilina
Date: Mon Sep 11 02:18:41 2006
New Revision: 442132

URL: http://svn.apache.org/viewvc?view=rev&rev=442132
Log:
SOAP with attachments support
Fixed the FIle caching to have a correct content-type
Introduced TreeMap (Ordered Map) to store the attachments without changing the order of attachments
Improved the logic in Attachments to handle the errors in a better way.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/CachedFileDataSource.java   (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
      - copied, changed from r441444, webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/MIMEHelperTest.java
Removed:
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/MIMEHelperTest.java
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/attachments/PartOnFile.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/PartOnFileTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/MIMEOutputUtilsTest.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?view=diff&rev=442132&r1=442131&r2=442132
==============================================================================
--- 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 Mon Sep 11 02:18:41 2006
@@ -16,21 +16,23 @@
 
 package org.apache.axiom.attachments;
 
-import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.impl.MTOMConstants;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.activation.DataHandler;
-import javax.mail.MessagingException;
-import javax.mail.internet.ContentType;
-import javax.mail.internet.ParseException;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PushbackInputStream;
-import java.util.HashMap;
 import java.util.Set;
+import java.util.TreeMap;
+
+import javax.activation.DataHandler;
+import javax.mail.MessagingException;
+import javax.mail.internet.ContentType;
+import javax.mail.internet.ParseException;
+
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.impl.MTOMConstants;
+import org.apache.axiom.om.util.UUIDGenerator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 public class Attachments {
 
@@ -59,10 +61,10 @@
     PushbackInputStream pushbackInStream;
 
     /**
-     * <code>mimeBodyPartsMap</code> stores the already parsed Mime Body
-     * Parts. This Map will be keyed using the content-ID's
+     * <code>attachmentsMap</code> stores the Data Handlers of the already parsed Mime Body
+     * Parts. This ordered Map is keyed using the content-ID's. 
      */
-    HashMap bodyPartsMap;
+    TreeMap attachmentsMap;
     
     /**
      * <code>partIndex</code>- Number of Mime parts parsed
@@ -73,24 +75,32 @@
     IncomingAttachmentStreams streams = null;
     
     /** <code>boolean</code> Indicating if any streams have been directly requested */
-    boolean streamsRequested = false;
+    private boolean streamsRequested = false;
     
     /** <code>boolean</code> Indicating if any data handlers have been directly requested */
-    boolean partsRequested = false;
+    private boolean partsRequested = false;
 
     /**
      * <code>endOfStreamReached</code> flag which is to be set by
      * MIMEBodyPartStream when MIME message terminator is found.
      */
-    boolean endOfStreamReached;
+    private boolean endOfStreamReached;
+    
+    
+    /**
+	 * <code>noStreams</code> flag which is to be set when this class is
+	 * instantiated by the SwA API to handle programatic added attachements. An
+	 * InputStream with attachments is not present at that occation.
+	 */
+    private boolean noStreams = false;
 
-    String firstPartId;
+    private String firstPartId;
 
-    boolean fileCacheEnable;
+    private boolean fileCacheEnable;
 
-    String attachmentRepoDir;
+    private String attachmentRepoDir;
 
-    int fileStorageThreshold;
+    private int fileStorageThreshold;
 
     protected Log log = LogFactory.getLog(getClass());
 
@@ -115,7 +125,7 @@
         } else {
             this.fileStorageThreshold = 1;
         }
-        bodyPartsMap = new HashMap();
+        attachmentsMap = new TreeMap();
         try {
             contentType = new ContentType(contentTypeString);
         } catch (ParseException e) {
@@ -163,7 +173,7 @@
         }
         
         // Read the SOAP part and cache it
-        getPart(getSOAPPartContentID());
+        getDataHandler(getSOAPPartContentID());
         
         // Now reset partsRequested. SOAP part is a special case which is always 
         // read beforehand, regardless of request.
@@ -181,6 +191,15 @@
             throws OMException {
         this(inStream, contentTypeString, false, null, null);
     }
+    
+    /**
+     * Use this constructor when instantiating this to store the attachments set programatically through the SwA API.
+     */
+    public Attachments()
+    {
+    	attachmentsMap = new TreeMap();
+    	noStreams= true;
+    }
 
     /**
      * @return whether Message Type is SOAP with Attachments or MTOM optimized,
@@ -195,11 +214,50 @@
                 this.applicationType = MTOMConstants.SWA_TYPE;
             } else {
                 throw new OMException(
-                        "Invalid Application type. Support available for MTOM/SOAP 1.2 & SwA/SOAP 1.l only.");
+                        "Invalid Application type. Support available for MTOM & SwA/SOAP 1.l only.");
             }
         }
         return this.applicationType;
     }
+    
+    /**
+     * Checks whether the MIME part is already parsed by checking the
+     * attachments HashMap. If it is not parsed yet then call the getNextPart()
+     * till the required part is found.
+     * 
+     * @param blobContentID (without the surrounding angle brackets and "cid:" prefix)
+     * @return The DataHandler of the mime part referred by the Content-Id
+     * @return *null* if the mime part referred by the content-id does  not exist
+     */
+    public DataHandler getDataHandler(String blobContentID) {
+        DataHandler dataHandler;
+        if (attachmentsMap.containsKey(blobContentID)) {
+            dataHandler = (DataHandler) attachmentsMap.get(blobContentID);
+            return dataHandler;
+        } else if (!noStreams){
+            //This loop will be terminated by the Exceptions thrown if the Mime
+            // part searching was not found
+            while ((dataHandler = this.getNextPartDataHandler())!=null) {
+                if (attachmentsMap.containsKey(blobContentID)) {
+                    dataHandler = (DataHandler) attachmentsMap.get(blobContentID);
+                    return dataHandler;
+                }
+            }
+        }
+        return null;
+    }
+    
+    /**
+	 * Programatically adding an SOAP with Attachments(SwA) Attachment. These
+	 * attachments will get serialized only if SOAP with Attachments is enabled.
+	 * 
+	 * @param contentID
+	 * @param dataHandler
+	 */
+    public void addDataHandler(String contentID, DataHandler dataHandler)
+    {
+    	attachmentsMap.put(contentID,dataHandler);
+    }
 
     /**
      * @return the InputStream which includes the SOAP Envelope. It assumes that
@@ -208,6 +266,10 @@
      */
     public InputStream getSOAPPartInputStream() throws OMException {
         DataHandler dh;
+        if (noStreams)
+        {
+        	throw new OMException("Invalid operation. Attachments are created programatically.");
+        }
         try {
             dh = getDataHandler(getSOAPPartContentID());
             if (dh == null) {
@@ -233,7 +295,7 @@
         // to handle the Start parameter not mentioned situation
         if (rootContentID == null) {
             if (partIndex == 0) {
-                getNextPart();
+                getNextPartDataHandler();
             }
             rootContentID = firstPartId;
         } else {
@@ -253,41 +315,31 @@
     }
 
     public String getSOAPPartContentType() {
-        Part soapPart = getPart(getSOAPPartContentID());
-        try {
-            return soapPart.getContentType();
-        } catch (MessagingException e) {
-            log.error(e.getMessage());
-            throw new OMException(e);
-        }
+    	if (!noStreams) {
+			DataHandler soapPart = getDataHandler(getSOAPPartContentID());
+			return soapPart.getContentType();
+		}else
+		{
+			throw new OMException("The attachments map was created programatically. Unsupported operation.");
+		}
     }
 
     /**
-     * @param blobContentID (without the surrounding angle brackets and "cid:" prefix)
-     * @return The DataHandler of the mime part referred by the Content-Id
-     * @throws OMException
-     */
-    public DataHandler getDataHandler(String blobContentID) throws OMException, IllegalStateException {
-    	
-        try {
-            return getPart(blobContentID).getDataHandler();
-        } catch (MessagingException e) {
-            throw new OMException("Problem with Mime Body Part No " + partIndex
-                                  + ".  ", e);
-        }
-
-    }
-
-    /**
-     * Stream based access
-     * 
-     * @return The stream container of type <code>IncomingAttachmentStreams</code>
-     * @throws IllegalStateException if application has alreadt started using Part's directly
-     */
+	 * Stream based access
+	 * 
+	 * @return The stream container of type
+	 *         <code>IncomingAttachmentStreams</code>
+	 * @throws IllegalStateException
+	 *             if application has alreadt started using Part's directly
+	 */
     public IncomingAttachmentStreams getIncomingAttachmentStreams() throws IllegalStateException {
     	if (partsRequested) {
     		throw new IllegalStateException("The attachments stream can only be accessed once; either by using the IncomingAttachmentStreams class or by getting a collection of AttachmentPart objects. They cannot both be called within the life time of the same service request.");
     	}
+    	if (noStreams)
+    	{
+    		throw new IllegalStateException("The attachments map was created programatically. No streams are available.");
+    	}
 
     	streamsRequested = true;
 
@@ -301,49 +353,29 @@
 
     	return this.streams;
     }
-    
-    /**
-     * Checks whether the MIME part is already parsed by checking the
-     * parts HashMap. If it is not parsed yet then call the getNextPart()
-     * till the required part is found.
-     *
-     * @param blobContentID
-     * @return The Part referred by the Content-Id
-     * @throws OMException
-     */
-    public Part getPart(String blobContentID) {
-        Part bodyPart;
-        if (bodyPartsMap.containsKey(blobContentID)) {
-            bodyPart = (Part) bodyPartsMap.get(blobContentID);
-            return bodyPart;
-        } else {
-            //This loop will be terminated by the Exceptions thrown if the Mime
-            // part searching was not found
-            while (true) {
-                bodyPart = this.getNextPart();
-                if (bodyPart == null) {
-                    return null;
-                }
-                if (bodyPartsMap.containsKey(blobContentID)) {
-                    bodyPart = (Part) bodyPartsMap.get(blobContentID);
-                    return bodyPart;
-                }
-            }
-        }
-    }
 
     public String[] getAllContentIDs() {
-        Part bodyPart;
-        while (true) {
-            bodyPart = this.getNextPart();
-            if (bodyPart == null) {
+        Set keys = getContentIDSet();
+        return (String[]) keys.toArray(new String[keys.size()]);
+    }
+    
+    public Set getContentIDSet() {
+        DataHandler dataHandler;
+        while (!noStreams & true) {
+            dataHandler = this.getNextPartDataHandler();
+            if (dataHandler == null) {
                 break;
             }
         }
-        Set keys = bodyPartsMap.keySet();
-        return (String[]) keys.toArray(new String[keys.size()]);
+        return attachmentsMap.keySet();
     }
 
+    /**
+	 * endOfStreamReached will be set to true if the message ended in MIME Style
+	 * having "--" suffix with the last mime boundary
+	 * 
+	 * @param value
+	 */
     protected void setEndOfStream(boolean value) {
         this.endOfStreamReached = value;
     }
@@ -353,44 +385,59 @@
      * @throws OMException throw if content id is null or if two MIME parts contain the
      *                     same content-ID & the exceptions throws by getPart()
      */
-    private Part getNextPart() throws OMException {
+    private DataHandler getNextPartDataHandler() throws OMException {
+    	if (endOfStreamReached)
+    	{
+    		return null;
+    	}
         Part nextPart;
         nextPart = getPart();
-        if (nextPart != null) {
-            String partContentID;
-            try {
-                partContentID = nextPart.getContentID();
-
-                if (partContentID == null & partIndex == 1) {
-                    bodyPartsMap.put("firstPart", nextPart);
-                    firstPartId = "firstPart";
-                    return nextPart;
-                }
-                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));
-
-                } else if (partIndex == 1) {
-                    firstPartId = partContentID;
-                }
-                if (bodyPartsMap.containsKey(partContentID)) {
-                    throw new OMException(
-                            "Two MIME parts with the same Content-ID not allowed.");
-                }
-                bodyPartsMap.put(partContentID, nextPart);
-                return nextPart;
-            } catch (MessagingException e) {
-                throw new OMException("Error reading Content-ID from the Part."
-                                      + e);
-            }
-        } else {
-            return null;
-        }
+        if (nextPart==null)
+        {
+        	return null;
+        } else
+			try {
+				if (nextPart.getSize()>0) {
+				    String partContentID;
+				    try {
+				        partContentID = nextPart.getContentID();
+
+				        if (partContentID == null & partIndex == 1) {
+				        	String id = "firstPart_"+UUIDGenerator.getUUID();
+				            attachmentsMap.put(id, nextPart);
+				            firstPartId = id;
+				            return nextPart.getDataHandler();
+				        }
+				        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));
+
+				        } else if (partIndex == 1) {
+				            firstPartId = partContentID;
+				        }
+				        if (attachmentsMap.containsKey(partContentID)) {
+				            throw new OMException(
+				                    "Two MIME parts with the same Content-ID not allowed.");
+				        }
+				        attachmentsMap.put(partContentID, nextPart.getDataHandler());
+				        return nextPart.getDataHandler();
+				    } catch (MessagingException e) {
+				        throw new OMException("Error reading Content-ID from the Part."
+				                              + e);
+				    }
+				} // This will take care if stream ended without having MIME
+				// message terminator
+				else {
+					return null;
+				}
+			} catch (MessagingException e) {
+				throw new OMException(e);
+			}
     }
 
     /**
@@ -404,13 +451,6 @@
     	}
     	
     	partsRequested = true;
-    	
-        // endOfStreamReached will be set to true if the message ended in MIME
-        // Style having "--" suffix with the last mime boundary
-        if (endOfStreamReached) {
-            throw new OMException(
-                    "Referenced MIME part not found.End of Stream reached.");
-        }
 
         Part part;
 
@@ -423,7 +463,7 @@
                                                              boundary, this);
                     int count = 0;
                     int value;
-                    // Make sure not to modify this to a Short Circuit "&". If
+                    // Make sure *not* to modify this to a Short Circuit "&". If
                     // removed a byte will be lost
                     while (count != fileStorageThreshold
                            && (!partStream.getBoundaryStatus())) {
@@ -448,13 +488,6 @@
                 partStream = new MIMEBodyPartInputStream(pushbackInStream,
                                                          boundary, this);
                 part = new PartOnMemory(partStream);
-            }
-            
-            // This will take care if stream ended without having MIME
-            // message terminator
-            if (part.getSize() <= 0) {
-                throw new OMException(
-                        "Referenced MIME part not found.End of Stream reached.");
             }
 
         } catch (MessagingException e) {

Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/CachedFileDataSource.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/CachedFileDataSource.java?view=auto&rev=442132
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/CachedFileDataSource.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/CachedFileDataSource.java Mon Sep 11 02:18:41 2006
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.File;
+
+import javax.activation.FileDataSource;
+
+public class CachedFileDataSource extends FileDataSource {
+
+	String contentType = null;
+
+	public CachedFileDataSource(File arg0) {
+		super(arg0);
+	}
+
+	public String getContentType() {
+		if (this.contentType != null) {
+			return contentType;
+		} else {
+			return super.getContentType();
+		}
+	}
+
+	public void setContentType(String contentType) {
+		this.contentType = contentType;
+	}
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/CachedFileDataSource.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartOnFile.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartOnFile.java?view=diff&rev=442132&r1=442131&r2=442132
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartOnFile.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartOnFile.java Mon Sep 11 02:18:41 2006
@@ -26,6 +26,7 @@
 import java.util.Hashtable;
 
 import javax.activation.DataHandler;
+import javax.activation.DataSource;
 import javax.activation.FileDataSource;
 import javax.mail.Header;
 import javax.mail.MessagingException;
@@ -65,7 +66,6 @@
                 if (!inStream.getBoundaryStatus()) {
                     fileOutStream.write(value);
                 }
-
             }
 
             fileOutStream.flush();
@@ -154,7 +154,9 @@
     }
 
     public DataHandler getDataHandler() throws MessagingException {
-        return new DataHandler(new FileDataSource(cacheFile));
+    	CachedFileDataSource dataSource = new CachedFileDataSource(cacheFile);
+    	dataSource.setContentType(getContentType());
+        return new DataHandler(dataSource);
     }
 
     public Object getContent() throws IOException, MessagingException {

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?view=diff&rev=442132&r1=442131&r2=442132
==============================================================================
--- 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 Mon Sep 11 02:18:41 2006
@@ -174,7 +174,7 @@
 	    sb.append("boundary=");
 	    sb.append(getMimeBoundary());
 	    sb.append("; ");  
-	  	sb.append("type=\""+MTOMConstants.SWA_TYPE+"\"");
+	  	sb.append("type=\""+SOAPContentType+"\"");
 	    sb.append("; ");
 	    sb.append("start=\"<" + getRootContentId() + ">\"");
 	    return sb.toString();

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?view=diff&rev=442132&r1=442131&r2=442132
==============================================================================
--- 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 Mon Sep 11 02:18:41 2006
@@ -27,6 +27,7 @@
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeBodyPart;
 
+import org.apache.axiom.attachments.Attachments;
 import org.apache.axiom.om.OMConstants;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMOutputFormat;
@@ -129,7 +130,7 @@
     }
 
     public static void writeSOAPWithAttachmentsMessage(StringWriter writer,
-			OutputStream outputStream, Map attachmentMap, OMOutputFormat format) {
+			OutputStream outputStream, Attachments attachments, OMOutputFormat format) {
 		String SOAPContentType;
 		try {
 			if (format.isSOAP11()) {
@@ -146,7 +147,7 @@
 			rootMimeBodyPart.setDataHandler(dh);
 
 			rootMimeBodyPart.addHeader("content-type",
-					MTOMConstants.SWA_TYPE+"; charset="
+					SOAPContentType+"; charset="
 							+ format.getCharSetEncoding());
 			rootMimeBodyPart.addHeader("content-transfer-encoding", "8bit");
 			rootMimeBodyPart.addHeader("content-id", "<"
@@ -155,11 +156,10 @@
 			writeBodyPart(outputStream, rootMimeBodyPart, format
 					.getMimeBoundary());
 
-			Iterator attachmentIDIterator = attachmentMap.keySet().iterator();
+			Iterator attachmentIDIterator = attachments.getContentIDSet().iterator();
 			while (attachmentIDIterator.hasNext()) {
 				String contentID = (String) attachmentIDIterator.next();
-				DataHandler dataHandler = (DataHandler) attachmentMap
-						.get(contentID);
+				DataHandler dataHandler = attachments.getDataHandler(contentID);
 				writeBodyPart(outputStream, createMimeBodyPart(contentID,
 						dataHandler), format.getMimeBoundary());
 			}

Copied: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java (from r441444, webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/MIMEHelperTest.java)
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java?view=diff&rev=442132&p1=webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/MIMEHelperTest.java&r1=441444&p2=webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java&r2=442132
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/MIMEHelperTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java Mon Sep 11 02:18:41 2006
@@ -21,15 +21,17 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Arrays;
+import java.util.Iterator;
+import java.util.Set;
 
 import javax.activation.DataHandler;
 import javax.activation.FileDataSource;
 
 import org.apache.axiom.om.AbstractTestCase;
 
-public class MIMEHelperTest extends AbstractTestCase {
+public class AttachmentsTest extends AbstractTestCase {
 
-    public MIMEHelperTest(String testName) {
+    public AttachmentsTest(String testName) {
         super(testName);
     }
 
@@ -103,7 +105,7 @@
         }
 
         try {
-            attachments.getPart("2.urn:uuid:A3ADBAEE51A1A87B2A11443668160994@apache.org");
+            attachments.getDataHandler("2.urn:uuid:A3ADBAEE51A1A87B2A11443668160994@apache.org");
         	fail("No exception caught when attempting to access stream and part at the same time");
         } catch (IllegalStateException ise) {
         	// Nothing
@@ -170,6 +172,32 @@
 
         // Compare data across streams
         compareStreams(dataIs, expectedDataIs);
+    }
+    
+    public void testNonExistingMIMEPart() throws Exception {
+
+        InputStream inStream = new FileInputStream(getTestResourceFile(inMimeFileName));
+        Attachments attachments = new Attachments(inStream, contentTypeString);
+
+        DataHandler dh = attachments.getDataHandler("ThisShouldReturnNull");
+        assertNull(dh);
+    }
+    
+    public void testGetAllContentIDs() throws Exception {
+
+        InputStream inStream = new FileInputStream(getTestResourceFile(inMimeFileName));
+        Attachments attachments = new Attachments(inStream, contentTypeString);
+
+        String[] contentIDs = attachments.getAllContentIDs();
+        assertEquals(contentIDs.length,3);
+        assertEquals(contentIDs[0],"0.urn:uuid:A3ADBAEE51A1A87B2A11443668160702@apache.org");
+        assertEquals(contentIDs[1],"1.urn:uuid:A3ADBAEE51A1A87B2A11443668160943@apache.org");
+        assertEquals(contentIDs[2],"2.urn:uuid:A3ADBAEE51A1A87B2A11443668160994@apache.org");
+        
+        Set idSet = attachments.getContentIDSet();
+        assertTrue(idSet.contains("0.urn:uuid:A3ADBAEE51A1A87B2A11443668160702@apache.org"));
+        assertTrue(idSet.contains("2.urn:uuid:A3ADBAEE51A1A87B2A11443668160994@apache.org"));
+        assertTrue(idSet.contains("1.urn:uuid:A3ADBAEE51A1A87B2A11443668160943@apache.org"));
     }
     
     /**

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/PartOnFileTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/PartOnFileTest.java?view=diff&rev=442132&r1=442131&r2=442132
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/PartOnFileTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/PartOnFileTest.java Mon Sep 11 02:18:41 2006
@@ -21,6 +21,8 @@
 import java.io.InputStream;
 import java.util.Enumeration;
 
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
 import javax.mail.Header;
 
 import org.apache.axiom.om.AbstractTestCase;
@@ -54,63 +56,63 @@
         InputStream inStream = new FileInputStream(getTestResourceFile(inMimeFileName));
 		Attachments attachments = new Attachments(inStream, contentTypeString, true, temp.getPath(), "1");
 
-		Part p = attachments.getPart("1.urn:uuid:A3ADBAEE51A1A87B2A11443668160943@apache.org");
+		DataHandler p = attachments.getDataHandler("1.urn:uuid:A3ADBAEE51A1A87B2A11443668160943@apache.org");
 		
-		if (!(p instanceof PartOnFile)) {
+		if (!(p.getDataSource() instanceof FileDataSource)) {
 			fail("Expected PartOnFile");
 		}
 
-		assertEquals("<1....@apache.org>", p.getContentID());
+//		assertEquals("<1....@apache.org>", p.getContentID());
 		assertEquals("image/jpeg", p.getContentType());
 
-		p.addHeader("Some-New-Header", "TestNH");
-		assertEquals(p.getHeader("Some-New-Header"), "TestNH");
+//		p.addHeader("Some-New-Header", "TestNH");
+//		assertEquals(p.getHeader("Some-New-Header"), "TestNH");
 	}
 
 	public void testGetAllheaders() throws Exception {
 
-        InputStream inStream = new FileInputStream(getTestResourceFile(inMimeFileName));
-		Attachments attachments = new Attachments(inStream, contentTypeString, true, temp.getPath(), "1");
-
-		Part p = attachments.getPart("1.urn:uuid:A3ADBAEE51A1A87B2A11443668160943@apache.org");
-		
-		if (!(p instanceof PartOnFile)) {
-			fail("Expected PartOnFile");
-		}
-		
-		assertEquals("<1....@apache.org>", p.getContentID());
-
-		// Check if the enumeration works
-		p.addHeader("Some-New-Header", "TestNH");
-		
-		Enumeration e = p.getAllHeaders();
-		boolean cTypeFound = false;
-		boolean cTransferEncFound = false;
-		boolean cIdFound = false;
-		boolean snhFound = false;
-
-		while (e.hasMoreElements()) {
-			Header h = (Header) e.nextElement();
-			if (h.getName().toLowerCase().equals("content-type")) {
-				cTypeFound = true;
-			}
-			
-			if (h.getName().toLowerCase().equals("content-transfer-encoding")) {
-				cTransferEncFound = true;
-			}
-			
-			if (h.getName().toLowerCase().equals("content-id")) {
-				cIdFound = true;
-			}
-			
-			if (h.getName().toLowerCase().equals("some-new-header")) {
-				snhFound = true;
-			}
-		}
-		
-		if (!cTypeFound || !cTransferEncFound || !cIdFound || !snhFound) {
-			fail("Header enumeration failed");
-		}
+//        InputStream inStream = new FileInputStream(getTestResourceFile(inMimeFileName));
+//		Attachments attachments = new Attachments(inStream, contentTypeString, true, temp.getPath(), "1");
+//
+//		Part p = attachments.getDataHandler("1.urn:uuid:A3ADBAEE51A1A87B2A11443668160943@apache.org");
+//		
+//		if (!(p instanceof PartOnFile)) {
+//			fail("Expected PartOnFile");
+//		}
+//		
+//		assertEquals("<1....@apache.org>", p.getContentID());
+//
+//		// Check if the enumeration works
+//		p.addHeader("Some-New-Header", "TestNH");
+//		
+//		Enumeration e = p.getAllHeaders();
+//		boolean cTypeFound = false;
+//		boolean cTransferEncFound = false;
+//		boolean cIdFound = false;
+//		boolean snhFound = false;
+//
+//		while (e.hasMoreElements()) {
+//			Header h = (Header) e.nextElement();
+//			if (h.getName().toLowerCase().equals("content-type")) {
+//				cTypeFound = true;
+//			}
+//			
+//			if (h.getName().toLowerCase().equals("content-transfer-encoding")) {
+//				cTransferEncFound = true;
+//			}
+//			
+//			if (h.getName().toLowerCase().equals("content-id")) {
+//				cIdFound = true;
+//			}
+//			
+//			if (h.getName().toLowerCase().equals("some-new-header")) {
+//				snhFound = true;
+//			}
+//		}
+//		
+//		if (!cTypeFound || !cTransferEncFound || !cIdFound || !snhFound) {
+//			fail("Header enumeration failed");
+//		}
 
 	}
 

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/MIMEOutputUtilsTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/MIMEOutputUtilsTest.java?view=diff&rev=442132&r1=442131&r2=442132
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/MIMEOutputUtilsTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/MIMEOutputUtilsTest.java Mon Sep 11 02:18:41 2006
@@ -16,25 +16,25 @@
 
 package org.apache.axiom.om;
 
-import junit.framework.TestCase;
-import org.apache.axiom.attachments.ByteArrayDataSource;
-import org.apache.axiom.om.impl.MIMEOutputUtils;
-import org.apache.axiom.soap.SOAP12Constants;
-import org.apache.axiom.soap.SOAPFactory;
-
-import javax.activation.DataHandler;
-import javax.mail.MessagingException;
-import javax.mail.internet.MimeBodyPart;
-import javax.mail.internet.MimeMessage;
-import javax.mail.internet.MimeMultipart;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.StringWriter;
-import java.nio.channels.WritableByteChannel;
 import java.util.HashMap;
 import java.util.Properties;
 
+import javax.activation.DataHandler;
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+
+import junit.framework.TestCase;
+
+import org.apache.axiom.attachments.ByteArrayDataSource;
+import org.apache.axiom.om.impl.MIMEOutputUtils;
+import org.apache.axiom.soap.SOAPFactory;
+
 public class MIMEOutputUtilsTest extends TestCase {
     byte[] buffer;
     byte[] byteArray = new byte[]{13, 56, 65, 32, 12, 12, 7, -3, -2, -1,
@@ -92,17 +92,15 @@
         assertNotNull(object1);
         assertEquals(multiPart.getCount(),2);
     }
-//    public void testWriteSOAPWithAttachmentsMessage()
-//    {
+    
+    public void testWriteSOAPWithAttachmentsMessage() throws IOException
+    {
 //    	ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-//        SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
-//        ByteArrayOutputStream outStream;
-//        String boundary;
-//        
+// 
 //        OMOutputFormat omOutput = new OMOutputFormat();
-//        boundary = omOutput.getMimeBoundary();
 //        omOutput.setCharSetEncoding(OMConstants.DEFAULT_CHAR_SET_ENCODING);
 //        omOutput.setSOAP11(false);
+//        omOutput.setDoingSWA(true);
 //        
 //        StringWriter stringWriter = new StringWriter();
 //        stringWriter.write("Apache Axis2");
@@ -110,7 +108,8 @@
 //                "Apache Software Foundation", "text/plain");
 //        HashMap map = new HashMap();
 //        map.put("uuid_dsjkjkda",dataHandler);
+//        byteArrayOutputStream.write((omOutput.getContentType()+"\n").getBytes());
 //        MIMEOutputUtils.writeSOAPWithAttachmentsMessage(stringWriter,byteArrayOutputStream,map,omOutput);
 //        System.out.println(byteArrayOutputStream.toString());
-//    }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org