axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thil...@apache.org
Subject svn commit: r219884 - in /webservices/axis/trunk/java/modules/xml: src/org/apache/axis2/attachments/ src/org/apache/axis2/om/impl/ src/org/apache/axis2/om/impl/llom/ src/org/apache/axis2/om/impl/llom/mtom/ test-resources/mtom/ test/org/apache/axis2/om/
Date Wed, 20 Jul 2005 12:11:22 GMT
Author: thilina
Date: Wed Jul 20 05:11:18 2005
New Revision: 219884

URL: http://svn.apache.org/viewcvs?rev=219884&view=rev
Log:
Changing MIME Content-ID processing according to the spec & MSFT way

Modified:
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/MIMEHelper.java
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/MimeBodyPartInputStream.java
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/MIMEOutputUtils.java
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/mtom/MTOMStAXSOAPModelBuilder.java
    webservices/axis/trunk/java/modules/xml/test-resources/mtom/MTOMBuilderTestIn.txt
    webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/MIMEOutputUtilsTest.java

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/MIMEHelper.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/MIMEHelper.java?rev=219884&r1=219883&r2=219884&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/MIMEHelper.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/MIMEHelper.java Wed Jul 20 05:11:18 2005
@@ -1,22 +1,19 @@
 /**
- * Copyright 2001-2004 The Apache Software Foundation.
- * <p/>
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.
- * <p/>
+ * Copyright 2001-2004 The Apache Software Foundation. <p/>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 <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0 <p/>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. <p/>
  */
 package org.apache.axis2.attachments;
 
-import org.apache.axis2.om.OMException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PushbackInputStream;
+import java.util.HashMap;
 
 import javax.activation.DataHandler;
 import javax.mail.MessagingException;
@@ -24,90 +21,94 @@
 import javax.mail.internet.ContentType;
 import javax.mail.internet.MimeBodyPart;
 import javax.mail.internet.ParseException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PushbackInputStream;
-import java.util.HashMap;
 
+import org.apache.axis2.om.OMException;
+
+/**
+ * @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
+ */
 public class MIMEHelper {
     /**
      * if the Message is MTOM optimised then <code>MTOM_TYPE</code>
      */
     public static final String MTOM_TYPE = "application/xop+xml";
-
+    
     /**
      * If the message is Soap with Attachments <code>SwA_TYPE</code>
      */
     public static final String SWA_TYPE = "text/xml";
-
+    
     /**
      * <code>rootPart</code> is used as the key for the root BodyPart in the
      * Parts HashMap
      */
     public static final String ROOT_PART = "SoapPart";
-
+    
     /**
      * <code>ContentType</code> of the MIME message
      */
     ContentType contentType;
-
+    
     /**
      * Mime <code>boundary</code> which seperates mime parts
      */
     byte[] boundary;
-
+    
     /**
      * <code>applicationType</code> used to distinguish between MTOM & SWA If
      * the message is MTOM optimised type is application/xop+xml If the message
      * is SWA, type is ??have to find out
      */
     String applicationType = null;
-
+    
     /**
      * <code>pushbackInStream</code> stores the reference to the incoming
      * stream A PushbackStream has the ability to "push back" or "unread" one
      * byte.
      */
     PushbackInputStream pushbackInStream;
-
+    
     /**
      * <code>mimeBodyPartsMap</code> stores the already parsed Mime Body
      * Parts. This Map will be keyed using the content-ID's
      */
     HashMap bodyPartsMap;
-
+    
     /**
      * <code>partIndex</code>- Number of Mime parts parsed
      */
     int partIndex = 0;
-
+    
+    boolean endOfStreamReached = false;
+    
     String firstPartId = null;
-
+    
     boolean fileCacheEnable = false;
-
+    
     String attachmentRepoDir = null;
-
+    
     public MIMEHelper(InputStream inStream, String contentTypeString,
-                      boolean fileCacheEnable, String attachmentRepoDir)
-            throws OMException {
+            boolean fileCacheEnable, String attachmentRepoDir)
+    throws OMException {
         this.attachmentRepoDir = attachmentRepoDir;
         this.fileCacheEnable = fileCacheEnable;
         bodyPartsMap = new HashMap();
         try {
             contentType = new ContentType(contentTypeString);
         } catch (ParseException e) {
-            throw new OMException("Invalid Content Type Field in the Mime Message"
+            throw new OMException(
+                    "Invalid Content Type Field in the Mime Message"
                     + e.toString());
         }
         // Boundary always have the prefix "--".
         this.boundary = ("--" + contentType.getParameter("boundary"))
-                .getBytes();
-
+        .getBytes();
+        
         //TODO do we need to wrap InputStream from a BufferedInputStream before
         // wrapping from PushbackStream
         pushbackInStream = new PushbackInputStream(inStream,
                 (this.boundary.length + 2));
-
+        
         // Move the read pointer to the begining of the first part
         // read till the end of first boundary
         while (true) {
@@ -121,7 +122,7 @@
                         value = pushbackInStream.read();
                         if (value == -1)
                             throw new OMException(
-                                    "Unexpected End of Stream while searching for first Mime Boundary");
+                            "Unexpected End of Stream while searching for first Mime Boundary");
                         boundaryIndex++;
                     }
                     if (boundaryIndex == boundary.length) { // boundary found
@@ -130,19 +131,19 @@
                     }
                 } else if ((byte) value == -1) {
                     throw new OMException(
-                            "Mime parts not found. Stream ended while searching for the boundary");
+                    "Mime parts not found. Stream ended while searching for the boundary");
                 }
             } catch (IOException e1) {
                 throw new OMException("Stream Error" + e1.toString());
             }
         }
     }
-
+    
     public MIMEHelper(InputStream inStream, String contentTypeString)
-            throws OMException {
+    throws OMException {
         this(inStream, contentTypeString, false, null);
     }
-
+    
     /**
      * @return whether Message Type is SOAP with Attachments or MTOM optimised
      *         by checking the application type parameter in the Contant Type
@@ -156,12 +157,12 @@
                 this.applicationType = SWA_TYPE;
             } else {
                 throw new OMException(
-                        "Invalid Application type. Support available for MTOM & SwA only.");
+                "Invalid Application type. Support available for MTOM & SwA only.");
             }
         }
         return this.applicationType;
     }
-
+    
     /**
      * @return the InputStream which includes the SOAP Envelope We assumes that
      *         the root mime part is always pointed by "start" parameter in
@@ -169,6 +170,7 @@
      */
     public InputStream getSOAPPartInputStream() throws OMException {
         String rootContentID = contentType.getParameter("start");
+        
         // to handle the Start parameter not mentioned situation
         if (rootContentID == null) {
             if (partIndex == 0) {
@@ -177,13 +179,23 @@
             rootContentID = firstPartId;
         } else {
             rootContentID.trim();
+            // Keep it here till we make sure the two angle brackets are
+            // required or not
+            if ((rootContentID.indexOf("<") > -1)
+                    & (rootContentID.indexOf(">") > -1))
+                rootContentID = rootContentID.substring(1, (rootContentID
+                        .length() - 1));
+        }
+        // Strips off the "cid" part from content-id
+        if (rootContentID.substring(0, 3).equalsIgnoreCase("cid")) {
+            rootContentID = rootContentID.substring(4);
         }
         DataHandler dh;
         try {
             dh = getDataHandler(rootContentID);
             if (dh == null) {
                 throw new OMException(
-                        "Mandatory Root MIME part containing the SOAP Envelope is missing");
+                "Mandatory Root MIME part containing the SOAP Envelope is missing");
             }
             return dh.getInputStream();
         } catch (IOException e) {
@@ -191,21 +203,22 @@
                     "Problem with DataHandler of the Root Mime Part. " + e);
         }
     }
-
+    
     /**
      * @param blobContentID
      * @return The DataHandler of the mime part refered by the content-Id
-     * @throws OMException First checks whether the MIME part is already parsed by
-     *                     checking the parts HashMap. If it is not parsed yet then call
-     *                     the getNextPart() till we find the required part.
+     * @throws OMException
+     *             First checks whether the MIME part is already parsed by
+     *             checking the parts HashMap. If it is not parsed yet then call
+     *             the getNextPart() till we find the required part.
      */
     public DataHandler getDataHandler(String blobContentID) throws OMException {
-
+        
         Part bodyPart;
+        //	blobContentID = "<" + blobContentID + ">";
         boolean attachmentFound = false;
-
-        //		// without the following part a Null Pointer Exception is thrown
-        //
+        
+        //TODO make sure to add surrounding angle brackets to the content ID
         if (bodyPartsMap.containsKey(blobContentID)) {
             bodyPart = (Part) bodyPartsMap.get(blobContentID);
             attachmentFound = true;
@@ -231,40 +244,53 @@
                     }
                 }
             } catch (MessagingException e) {
-                throw new OMException("Invalid Mime Message " + e.toString());
+                throw new OMException("Invalid Mime Message " + e);
             }
         }
-
+        
     }
-
+    
+    protected void setEndOfStream(boolean value)
+    {
+        this.endOfStreamReached = value;
+        
+    }
+    
     /**
      * @return The next MIME Body part in the stream Uses the MimeBodyPartStream
      *         to obtain streams delimited by boundaries.
-     * @throws MessagingException
+     * @throws OMException
      */
-    // TODO do we need Locking for this
     private MimeBodyPart getMimeBodyPart() throws OMException {
+        // 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.");
+        
         MimeBodyPart mimeBodyPart = null;
-
         MimeBodyPartInputStream partStream;
-        partStream = new MimeBodyPartInputStream(pushbackInStream,
-                boundary);
+        partStream = new MimeBodyPartInputStream(pushbackInStream, boundary,
+                this);
         try {
             mimeBodyPart = new MimeBodyPart(partStream);
+            
+            // This will take care if stream ended without having MIME message terminator
+            if (mimeBodyPart.getSize() <= 0) {
+                throw new OMException(
+                "Referenced MIME part not found.End of Stream reached.");
+            }
         } catch (MessagingException e) {
             throw new OMException("Problem reading Mime Part No "
                     + (partIndex + 1) + ". " + e);
         }
-
         partIndex++;
         return mimeBodyPart;
     }
-
+    
     /**
-     * @return The Mime body part which contains the SOAP Envelope In MTOM case
-     *         it is the first part In SwA case we assumes it to be first
-     *         part.Have to FIX This
-     * @throws MessagingException
+     * @return
+     * @throws OMException
      */
     private MimeBodyPart getRootMimeBodyPart() throws OMException {
         MimeBodyPart rootMimeBodyPart;
@@ -276,7 +302,7 @@
         }
         return rootMimeBodyPart;
     }
-
+    
     private Part getNextPart() throws OMException {
         MimeBodyPart nextMimeBodyPart;
         nextMimeBodyPart = getMimeBodyPart();
@@ -284,31 +310,51 @@
             String partContentID;
             try {
                 partContentID = nextMimeBodyPart.getContentID();
+                
                 if (partContentID == null & partIndex == 1) {
                     bodyPartsMap.put("firstPart", nextMimeBodyPart);
                     firstPartId = "firstPart";
                     return nextMimeBodyPart;
+                }
+                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 (fileCacheEnable) {
-                    PartOnFile part = new PartOnFile(nextMimeBodyPart,
-                            partContentID,
-                            attachmentRepoDir);
-                    return part;
-                } else {
-                    bodyPartsMap.put(partContentID, nextMimeBodyPart);
-                    return nextMimeBodyPart;
+                if (bodyPartsMap.containsKey(partContentID))
+                {
+                    throw new OMException("Two MIME parts with the same Content-ID not allowed.");
                 }
+       /*
+        * Temporary File storage support is deffered till 1.0
+        */         
+                //                if (fileCacheEnable) {
+                //                    PartOnFile part = new PartOnFile(nextMimeBodyPart,
+                //                            partContentID,
+                //                            attachmentRepoDir);
+                //                    return part;
+                //                } else {
+                bodyPartsMap.put(partContentID, nextMimeBodyPart);
+                return nextMimeBodyPart;
+                //                }
             } catch (MessagingException e) {
-                throw new OMException("Error Reading Content-ID from Mime Part No "
-                        + partIndex + ". " + e);
-            } catch (Exception e) {
-                throw new OMException("Error Creating File  Storage Part"
+                throw new OMException(
+                        "Error Reading Content-ID from Mime Part No "
                         + partIndex + ". " + e);
             }
+            //            } catch (Exception e) {
+            //                throw new OMException("Error Creating File Storage Part"
+            //                        + partIndex + ". " + e);
+            //            }
         } else
             return null;
     }
-
+    
 }

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/MimeBodyPartInputStream.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/MimeBodyPartInputStream.java?rev=219884&r1=219883&r2=219884&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/MimeBodyPartInputStream.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/MimeBodyPartInputStream.java Wed Jul 20 05:11:18 2005
@@ -1,18 +1,12 @@
 /**
- * Copyright 2001-2004 The Apache Software Foundation.
- * <p/>
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.
- * <p/>
+ * Copyright 2001-2004 The Apache Software Foundation. <p/>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 <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0 <p/>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. <p/>
  */
 package org.apache.axis2.attachments;
 
@@ -25,15 +19,22 @@
 
     boolean boundaryFound = false;
 
+    MIMEHelper parent = null;
+
     byte[] boundary;
 
-    public MimeBodyPartInputStream(PushbackInputStream inStream,
-                                   byte[] boundary) {
+    public MimeBodyPartInputStream(PushbackInputStream inStream, byte[] boundary) {
         super();
         this.inStream = inStream;
         this.boundary = boundary;
     }
 
+    public MimeBodyPartInputStream(PushbackInputStream inStream,
+            byte[] boundary, MIMEHelper parent) {
+        this(inStream, boundary);
+        this.parent = parent;
+    }
+
     public int read() throws IOException {
         if (boundaryFound) {
             return -1;
@@ -41,7 +42,8 @@
         // read the next value from stream
         int value = inStream.read();
 
-        // A problem occured because all the mime parts tends to have a /r/n at the end. Making it hard to transform them to correct DataSources.
+        // A problem occured because all the mime parts tends to have a /r/n at
+        // the end. Making it hard to transform them to correct DataSources.
         // This logic introduced to handle it
         //TODO look more in to this && for a better way to do this
         if (value == 13) {
@@ -64,22 +66,23 @@
         // read value is the first byte of the boundary. Start matching the
         // next characters to find a boundary
         int boundaryIndex = 0;
-        while ((boundaryIndex < boundary.length)
+        while ((boundaryIndex < (boundary.length - 1))
                 && ((byte) value == boundary[boundaryIndex])) {
             value = inStream.read();
             boundaryIndex++;
         }
 
-        if (boundaryIndex == boundary.length) { // boundary found
+        if (boundaryIndex == (boundary.length - 1)) { // boundary found
             boundaryFound = true;
             // read the end of line character
-            if (inStream.read() == 45) {
+            if ((value = inStream.read()) == 45) {
                 //check whether end of stream
                 //Last mime boundary should have a succeeding "--"
-                if (!((value = inStream.read()) == 45)) {
-                    inStream.unread(value);
+                if ((value = inStream.read()) == 45 && parent!=null) {
+                    parent.setEndOfStream(true);
                 }
-
+            } else {
+                inStream.read();
             }
 
             return -1;

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/MIMEOutputUtils.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/MIMEOutputUtils.java?rev=219884&r1=219883&r2=219884&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/MIMEOutputUtils.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/MIMEOutputUtils.java Wed Jul 20 05:11:18 2005
@@ -15,22 +15,22 @@
  */
 package org.apache.axis2.om.impl;
 
-import org.apache.axis2.om.OMText;
-import org.apache.axis2.om.OMException;
-
-import javax.activation.DataHandler;
-import javax.mail.MessagingException;
-import javax.mail.internet.ContentType;
-import javax.mail.internet.MimeBodyPart;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.Random;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Random;
+
+import javax.activation.DataHandler;
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeBodyPart;
+
+import org.apache.axis2.om.OMException;
+import org.apache.axis2.om.OMText;
 
 public class MIMEOutputUtils {
 
@@ -51,7 +51,7 @@
             rootMimeBodyPart.addHeader("content-type",
                     "application/xop+xml; charset=utf-8; type=\"text/xml; charset=utf-8\"");
             rootMimeBodyPart.addHeader("content-transfer-encoding", "binary");
-            rootMimeBodyPart.addHeader("content-id", contentId);
+            rootMimeBodyPart.addHeader("content-id","<"+contentId+">");
 
             writeBodyPart(outStream, rootMimeBodyPart, boundary);
 
@@ -73,7 +73,7 @@
             throws MessagingException {
         MimeBodyPart mimeBodyPart = new MimeBodyPart();
         mimeBodyPart.setDataHandler(node.getDataHandler());
-        mimeBodyPart.addHeader("content-id", node.getContentID());
+        mimeBodyPart.addHeader("content-id", "<"+node.getContentID()+">");
         mimeBodyPart.addHeader("content-type", "application/octet-stream");
         mimeBodyPart.addHeader("content-transfer-encoding", "binary");
         return mimeBodyPart;
@@ -133,7 +133,7 @@
         sb.append("; ");
         sb.append("type=\"application/xop+xml\"");
         sb.append("; ");
-        sb.append("start=\"" + contentId + "\"");
+        sb.append("start=\"<" + "cid:"+contentId + ">\"");
         sb.append("; ");
         sb.append("start-info=\"text/xml; charset=utf-8\"");
         return sb.toString();

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java?rev=219884&r1=219883&r2=219884&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java Wed Jul 20 05:11:18 2005
@@ -15,20 +15,16 @@
  */
 package org.apache.axis2.om.impl;
 
-import org.apache.axis2.om.OMText;
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.util.LinkedList;
 
 import javax.xml.stream.FactoryConfigurationError;
 import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
-import java.io.ByteArrayOutputStream;
-import java.io.OutputStream;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.LinkedList;
-import java.util.Random;
+
+import org.apache.axis2.om.OMText;
 
 /**
  * For the moment this assumes that transport takes the decision of whether
@@ -104,20 +100,20 @@
 
     public String getMimeBoundary() {
         if(mimeBoundary == null) {
-            mimeBoundary = "--MIMEBoundary" + MIMEOutputUtils.getRandomStringOf18Characters();
+            mimeBoundary = "MIMEBoundary" + MIMEOutputUtils.getRandomStringOf18Characters();
         }
         return mimeBoundary;
     }
 
     public String getRootContentId() {
         if(rootContentId == null) {
-            rootContentId = "cid:0." + MIMEOutputUtils.getRandomStringOf18Characters() + "@apache.org";
+            rootContentId = "0." + MIMEOutputUtils.getRandomStringOf18Characters() + "@apache.org";
         }
         return rootContentId;
     }
 
     public String getNextContentId() {
         nextid++;
-        return "cid:" + nextid + "." + MIMEOutputUtils.getRandomStringOf18Characters() + "@apache.org";
+        return nextid + "." + MIMEOutputUtils.getRandomStringOf18Characters() + "@apache.org";
     }
 }

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java?rev=219884&r1=219883&r2=219884&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java Wed Jul 20 05:11:18 2005
@@ -1,20 +1,29 @@
 /*
  * 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
- *
+ * 
+ * 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.
+ * 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.axis2.om.impl.llom;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.Random;
+
+import javax.activation.DataHandler;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
 import org.apache.axis2.attachments.Base64;
 import org.apache.axis2.attachments.ByteArrayDataSource;
 import org.apache.axis2.attachments.IOUtils;
@@ -24,386 +33,406 @@
 import org.apache.axis2.om.OMException;
 import org.apache.axis2.om.OMNamespace;
 import org.apache.axis2.om.OMNode;
-import org.apache.axis2.om.impl.OMOutputImpl;
-import org.apache.axis2.om.impl.MIMEOutputUtils;
 import org.apache.axis2.om.OMText;
 import org.apache.axis2.om.OMXMLParserWrapper;
+import org.apache.axis2.om.impl.MIMEOutputUtils;
+import org.apache.axis2.om.impl.OMOutputImpl;
 import org.apache.axis2.om.impl.llom.mtom.MTOMStAXSOAPModelBuilder;
 
-import javax.activation.DataHandler;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Date;
-import java.util.Random;
-
 public class OMTextImpl extends OMNodeImpl implements OMText, OMConstants {
-    protected String value = null;
-    protected String mimeType;
-    protected boolean optimize = false;
-    protected boolean isBinary = false;
-    private static Random rnd = new Random(new Date().getTime());
-    /**
-     * Field contentID for the mime part used when serialising Binary stuff as
-     * MTOM optimised
-     */
-    private String contentID = null;
-    /**
-     * Field dataHandler
-     */
-    private DataHandler dataHandler = null;
-    /**
-     * Field nameSpace used when serialising Binary stuff as MTOM optimised
-     */
-    protected OMNamespace ns = new OMNamespaceImpl(
-            "http://www.w3.org/2004/08/xop/include", "xop");
-    /**
-     * Field localName used when serialising Binary stuff as MTOM optimised
-     */
-    protected String localName = "Include";
-    /**
-     * Field attributes used when serialising Binary stuff as MTOM optimised
-     */
-    protected OMAttribute attribute;
-
-    /**
-     * Constructor OMTextImpl
-     *
-     * @param s
-     */
-    public OMTextImpl(String s) {
-        this.value = s;
-        this.nodeType = TEXT_NODE;
-    }
-
-    /**
-     * Constructor OMTextImpl
-     *
-     * @param parent
-     * @param text
-     */
-    public OMTextImpl(OMElement parent, String text) {
-        super(parent);
-        this.value = text;
-        done = true;
-        this.nodeType = TEXT_NODE;
-    }
-
-    /**
-     * @param s        -
-     *                 base64 encoded String representation of Binary
-     * @param mimeType of the Binary
-     */
-    public OMTextImpl(String s, String mimeType, boolean optimize) {
-        this(null, s, mimeType, optimize);
-    }
-
-    /**
-     * @param parent
-     * @param s        -
-     *                 base64 encoded String representation of Binary
-     * @param mimeType of the Binary
-     */
-    public OMTextImpl(OMElement parent, String s, String mimeType,
-                      boolean optimize) {
-        this(parent, s);
-        this.mimeType = mimeType;
-        this.optimize = optimize;
-        done = true;
-        this.nodeType = TEXT_NODE;
-    }
-
-    /**
-     * @param dataHandler To send binary optimised content Created programatically.
-     */
-    public OMTextImpl(DataHandler dataHandler) {
-        this(dataHandler, true);
-    }
-
-    /**
-     * @param dataHandler
-     * @param optimize    To send binary content. Created progrmatically.
-     */
-    public OMTextImpl(DataHandler dataHandler, boolean optimize) {
-        this.dataHandler = dataHandler;
-        this.isBinary = true;
-        this.optimize = optimize;
-        done = true;
-        this.nodeType = TEXT_NODE;
-    }
-
-    /**
-     * @param contentID
-     * @param parent
-     * @param builder   Used when the builder is encountered with a XOP:Include tag
-     *                  Stores a reference to the builder and the content-id. Supports
-     *                  deffered parsing of MIME messages
-     */
-    public OMTextImpl(String contentID, OMElement parent,
-                      OMXMLParserWrapper builder) {
-        super(parent);
-        this.contentID = contentID;
-        this.optimize = true;
-        this.isBinary = true;
-        this.builder = builder;
-        this.nodeType = TEXT_NODE;
-    }
-
-    /**
-     * @param omOutput
-     * @throws XMLStreamException
-     */
-    public void serializeWithCache(org.apache.axis2.om.impl.OMOutputImpl omOutput) throws XMLStreamException {
-        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
-        int type = getType();
-        if (type == TEXT_NODE) {
-            writer.writeCharacters(this.value);
-        } else if (type == CDATA_SECTION_NODE) {
-            writer.writeCData(this.value);
-        }
-        OMNode nextSibling = this.getNextSibling();
-        if (nextSibling != null) {
-            nextSibling.serializeWithCache(omOutput);
-        }
-    }
-
-    /**
-     * Returns the value
-     */
-    public String getText() throws OMException {
-        if (this.value != null) {
-            return this.value;
-        } else {
-            try {
-                InputStream inStream;
-                inStream = this.getInputStream();
-                byte[] data;
-                data = new byte[inStream.available()];
-                IOUtils.readFully(inStream, data);
-                return Base64.encode(data);
-            } catch (Exception e) {
-                throw new OMException("Cannot read from Stream taken form the Data Handler"
-                        + e);
-            }
-        }
-    }
-
-    public boolean isOptimized() {
-        return optimize;
-    }
-
-    public void setOptimize(boolean value) {
-        this.optimize = value;
-    }
-
-    /**
-     * @return
-     * @throws org.apache.axis2.om.OMException
-     *
-     * @throws OMException
-     */
-    public DataHandler getDataHandler() {
-        /*
-        * this should return a DataHandler containing the binary data
-        * reperesented by the Base64 strings stored in OMText
-        */
-        if (value != null) {
-            ByteArrayDataSource dataSource;
-            byte[] data = Base64.decode(value);
-            if (mimeType != null) {
-                dataSource = new ByteArrayDataSource(data, mimeType);
-            } else {
-                // Assumes type as application/octet-stream
-                dataSource = new ByteArrayDataSource(data);
-            }
-            return new DataHandler(dataSource);
-        } else {
-            if (contentID == null){
-                throw new RuntimeException("ContentID is null");
-            }
-            if (dataHandler == null) {
-                dataHandler = ((MTOMStAXSOAPModelBuilder) builder)
-                        .getDataHandler(contentID);
-            }
-            return dataHandler;
-        }
-    }
-
-    public String getLocalName() {
-        return localName;
-    }
-
-    public java.io.InputStream getInputStream() throws OMException {
-        if (isBinary) {
-            if (dataHandler == null) {
-                getDataHandler();
-            }
-            InputStream inStream;
-            try {
-                inStream = dataHandler.getDataSource().getInputStream();
-            } catch (IOException e) {
-                throw new OMException(
-                        "Cannot get InputStream from DataHandler." + e);
-            }
-            return inStream;
-        } else {
-            throw new OMException("Unsupported Operation");
-        }
-    }
-
-    public String getContentID() {
-        if(contentID == null) {
-            contentID = "cid:" + MIMEOutputUtils.getRandomStringOf18Characters() + "@apache.org";
-        }
-        return this.contentID;
-    }
-
-    public boolean isComplete() {
-        return done;
-    }
-
-    public void serialize(org.apache.axis2.om.impl.OMOutputImpl omOutput) throws XMLStreamException {
-        if (!this.isBinary) {
-            serializeWithCache(omOutput);
-        } else {
-            if (omOutput.isOptimized()) {
-                if(contentID == null){
-                    contentID = omOutput.getNextContentId();
-                }
-                // send binary as MTOM optimised
-                this.attribute =
-                        new OMAttributeImpl("href",
-                                new OMNamespaceImpl("", ""),
-                                getContentID());
-                this.serializeStartpart(omOutput);
-                omOutput.writeOptimized(this);
-                omOutput.getXmlStreamWriter().writeEndElement();
-            } else {
-                omOutput.getXmlStreamWriter().writeCharacters(this.getText());
-            }
-            // TODO do we need these
-            OMNode nextSibling = this.getNextSibling();
-            if (nextSibling != null) {
-                // serilize next sibling
-                nextSibling.serialize(omOutput);
-            } else {
-                // TODO : See whether following part is really needed
-                if (parent != null && !parent.isComplete()) {
-                    // do the special serialization
-                    // Only the push serializer is left now
-                    builder.next();
-                }
-            }
-        }
-    }
-
-    /*
-    * Methods to copy from OMSerialize utils
-    */
-    private void serializeStartpart(OMOutputImpl omOutput)
-            throws XMLStreamException {
-        String nameSpaceName;
-        String writer_prefix;
-        String prefix;
-        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
-        if (this.ns != null) {
-            nameSpaceName = this.ns.getName();
-            writer_prefix = writer.getPrefix(nameSpaceName);
-            prefix = this.ns.getPrefix();
-            if (nameSpaceName != null) {
-                if (writer_prefix != null) {
-                    writer.writeStartElement(nameSpaceName,
-                            this.getLocalName());
-                } else {
-                    if (prefix != null) {
-                        writer.writeStartElement(prefix, this.getLocalName(),
-                                nameSpaceName);
-                        //TODO FIX ME
-                        //writer.writeNamespace(prefix, nameSpaceName);
-                        writer.setPrefix(prefix, nameSpaceName);
-                    } else {
-                        writer.writeStartElement(nameSpaceName,
-                                this.getLocalName());
-                        writer.writeDefaultNamespace(nameSpaceName);
-                        writer.setDefaultNamespace(nameSpaceName);
-                    }
-                }
-            } else {
-                writer.writeStartElement(this.getLocalName());
-            }
-        } else {
-            writer.writeStartElement(this.getLocalName());
-        }
-        // add the elements attribute "href"
-        serializeAttribute(this.attribute, omOutput);
-        // add the namespace
-        serializeNamespace(this.ns, omOutput);
-    }
-
-    /**
-     * Method serializeAttribute
-     *
-     * @param attr
-     * @param omOutput
-     * @throws XMLStreamException
-     */
-    static void serializeAttribute(OMAttribute attr, OMOutputImpl omOutput)
-            throws XMLStreamException {
-        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
-        // first check whether the attribute is associated with a namespace
-        OMNamespace ns = attr.getNamespace();
-        String prefix;
-        String namespaceName;
-        if (ns != null) {
-            // add the prefix if it's availble
-            prefix = ns.getPrefix();
-            namespaceName = ns.getName();
-            if (prefix != null) {
-                writer.writeAttribute(prefix,
-                        namespaceName,
-                        attr
-                                .getLocalName(),
-                        attr.getValue());
-            } else {
-                writer.writeAttribute(namespaceName,
-                        attr.getLocalName(),
-                        attr
-                                .getValue());
-            }
-        } else {
-            writer.writeAttribute(attr.getLocalName(), attr.getValue());
-        }
-    }
-
-    /**
-     * Method serializeNamespace
-     *
-     * @param namespace
-     * @param omOutput
-     * @throws XMLStreamException
-     */
-    static void serializeNamespace(OMNamespace namespace, org.apache.axis2.om.impl.OMOutputImpl omOutput)
-            throws XMLStreamException {
-        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
-        if (namespace != null) {
-            String uri = namespace.getName();
-            String ns_prefix = namespace.getPrefix();
-            writer.writeNamespace(ns_prefix, namespace.getName());
-            writer.setPrefix(ns_prefix, uri);
-        }
-    }
-
-    /**
-     * Slightly different implementation of the discard method
-     *
-     * @throws OMException
-     */
-    public void discard() throws OMException {
-        if (done) {
-            this.detach();
-        } else {
-            builder.discard((OMElement) this.parent);
-        }
-    }
+	protected String value = null;
+
+	protected String mimeType;
+
+	protected boolean optimize = false;
+
+	protected boolean isBinary = false;
+
+	private static Random rnd = new Random(new Date().getTime());
+
+	/**
+	 * Field contentID for the mime part used when serialising Binary stuff as
+	 * MTOM optimised
+	 */
+	private String contentID = null;
+
+	/**
+	 * Field dataHandler
+	 */
+	private DataHandler dataHandler = null;
+
+	/**
+	 * Field nameSpace used when serialising Binary stuff as MTOM optimised
+	 */
+	protected OMNamespace ns = new OMNamespaceImpl(
+			"http://www.w3.org/2004/08/xop/include", "xop");
+
+	/**
+	 * Field localName used when serialising Binary stuff as MTOM optimised
+	 */
+	protected String localName = "Include";
+
+	/**
+	 * Field attributes used when serialising Binary stuff as MTOM optimised
+	 */
+	protected OMAttribute attribute;
+
+	/**
+	 * Constructor OMTextImpl
+	 * 
+	 * @param s
+	 */
+	public OMTextImpl(String s) {
+		this.value = s;
+		this.nodeType = TEXT_NODE;
+	}
+
+	/**
+	 * Constructor OMTextImpl
+	 * 
+	 * @param parent
+	 * @param text
+	 */
+	public OMTextImpl(OMElement parent, String text) {
+		super(parent);
+		this.value = text;
+		done = true;
+		this.nodeType = TEXT_NODE;
+	}
+
+	/**
+	 * @param s -
+	 *            base64 encoded String representation of Binary
+	 * @param mimeType
+	 *            of the Binary
+	 */
+	public OMTextImpl(String s, String mimeType, boolean optimize) {
+		this(null, s, mimeType, optimize);
+	}
+
+	/**
+	 * @param parent
+	 * @param s -
+	 *            base64 encoded String representation of Binary
+	 * @param mimeType
+	 *            of the Binary
+	 */
+	public OMTextImpl(OMElement parent, String s, String mimeType,
+			boolean optimize) {
+		this(parent, s);
+		this.mimeType = mimeType;
+		this.optimize = optimize;
+		done = true;
+		this.nodeType = TEXT_NODE;
+	}
+
+	/**
+	 * @param dataHandler
+	 *            To send binary optimised content Created programatically.
+	 */
+	public OMTextImpl(DataHandler dataHandler) {
+		this(dataHandler, true);
+	}
+
+	/**
+	 * @param dataHandler
+	 * @param optimize
+	 *            To send binary content. Created progrmatically.
+	 */
+	public OMTextImpl(DataHandler dataHandler, boolean optimize) {
+		this.dataHandler = dataHandler;
+		this.isBinary = true;
+		this.optimize = optimize;
+		done = true;
+		this.nodeType = TEXT_NODE;
+	}
+
+	/**
+	 * @param contentID
+	 * @param parent
+	 * @param builder
+	 *            Used when the builder is encountered with a XOP:Include tag
+	 *            Stores a reference to the builder and the content-id. Supports
+	 *            deffered parsing of MIME messages
+	 */
+	public OMTextImpl(String contentID, OMElement parent,
+			OMXMLParserWrapper builder) {
+		super(parent);
+		this.contentID = contentID;
+		this.optimize = true;
+		this.isBinary = true;
+		this.builder = builder;
+		this.nodeType = TEXT_NODE;
+	}
+
+	/**
+	 * @param omOutput
+	 * @throws XMLStreamException
+	 */
+	public void serializeWithCache(
+			org.apache.axis2.om.impl.OMOutputImpl omOutput)
+			throws XMLStreamException {
+		XMLStreamWriter writer = omOutput.getXmlStreamWriter();
+		int type = getType();
+		if (type == TEXT_NODE) {
+			writer.writeCharacters(this.value);
+		} else if (type == CDATA_SECTION_NODE) {
+			writer.writeCData(this.value);
+		}
+		OMNode nextSibling = this.getNextSibling();
+		if (nextSibling != null) {
+			nextSibling.serializeWithCache(omOutput);
+		}
+	}
+
+	/**
+	 * Returns the value
+	 */
+	public String getText() throws OMException {
+		if (this.value != null) {
+			return this.value;
+		} else {
+			try {
+				InputStream inStream;
+				inStream = this.getInputStream();
+				int x = inStream.available();
+				byte[] data;
+				// There are times, this inStream reports the Available bytes incorrectly.
+				// Reading the First byte & then getting the available number of bytes fixed it.
+				if (x==0)
+				{
+				int firstByte = inStream.read();
+				data = new byte[inStream.available()+1];
+				data[0] = (byte)firstByte;
+				IOUtils.readFully(inStream, data,1,data.length-1);
+				}
+				else
+				{	
+					data = new byte[inStream.available()];
+					IOUtils.readFully(inStream, data);
+				}
+				return Base64.encode(data);
+			} catch (Exception e) {
+				throw new OMException(
+						"Cannot read from Stream taken form the Data Handler"
+								+ e);
+			}
+		}
+	}
+
+	public boolean isOptimized() {
+		return optimize;
+	}
+
+	public void setOptimize(boolean value) {
+		this.optimize = value;
+	}
+
+	/**
+	 * @return
+	 * @throws org.apache.axis2.om.OMException
+	 * 
+	 * @throws OMException
+	 */
+	public DataHandler getDataHandler() {
+		/*
+		 * this should return a DataHandler containing the binary data
+		 * reperesented by the Base64 strings stored in OMText
+		 */
+		if (value != null) {
+			ByteArrayDataSource dataSource;
+			byte[] data = Base64.decode(value);
+			if (mimeType != null) {
+				dataSource = new ByteArrayDataSource(data, mimeType);
+			} else {
+				// Assumes type as application/octet-stream
+				dataSource = new ByteArrayDataSource(data);
+			}
+			return new DataHandler(dataSource);
+		} else {
+			
+			if (dataHandler == null) {
+				if (contentID == null) {
+					throw new RuntimeException("ContentID is null");
+				}
+				dataHandler = ((MTOMStAXSOAPModelBuilder) builder)
+						.getDataHandler(contentID);
+			}
+			return dataHandler;
+		}
+	}
+
+	public String getLocalName() {
+		return localName;
+	}
+
+	public java.io.InputStream getInputStream() throws OMException {
+		if (isBinary) {
+			if (dataHandler == null) {
+				getDataHandler();
+			}
+			InputStream inStream;
+			try {
+				inStream = dataHandler.getDataSource().getInputStream();
+			} catch (IOException e) {
+				throw new OMException(
+						"Cannot get InputStream from DataHandler." + e);
+			}
+			return inStream;
+		} else {
+			throw new OMException("Unsupported Operation");
+		}
+	}
+
+	public String getContentID() {
+		if (contentID == null) {
+			contentID = MIMEOutputUtils.getRandomStringOf18Characters()
+					+ "@apache.org";
+		}
+		return this.contentID;
+	}
+
+	public boolean isComplete() {
+		return done;
+	}
+
+	public void serialize(org.apache.axis2.om.impl.OMOutputImpl omOutput)
+			throws XMLStreamException {
+		if (!this.isBinary) {
+			serializeWithCache(omOutput);
+		} else {
+			if (omOutput.isOptimized()) {
+				if (contentID == null) {
+					contentID = omOutput.getNextContentId();
+				}
+				// send binary as MTOM optimised
+				this.attribute = new OMAttributeImpl("href",
+						new OMNamespaceImpl("", ""), "cid:" + getContentID());
+				this.serializeStartpart(omOutput);
+				omOutput.writeOptimized(this);
+				omOutput.getXmlStreamWriter().writeEndElement();
+			} else {
+				omOutput.getXmlStreamWriter().writeCharacters(this.getText());
+			}
+			// TODO do we need these
+			OMNode nextSibling = this.getNextSibling();
+			if (nextSibling != null) {
+				// serilize next sibling
+				nextSibling.serialize(omOutput);
+			} else {
+				// TODO : See whether following part is really needed
+				if (parent != null && !parent.isComplete()) {
+					// do the special serialization
+					// Only the push serializer is left now
+					builder.next();
+				}
+			}
+		}
+	}
+
+	/*
+	 * Methods to copy from OMSerialize utils
+	 */
+	private void serializeStartpart(OMOutputImpl omOutput)
+			throws XMLStreamException {
+		String nameSpaceName;
+		String writer_prefix;
+		String prefix;
+		XMLStreamWriter writer = omOutput.getXmlStreamWriter();
+		if (this.ns != null) {
+			nameSpaceName = this.ns.getName();
+			writer_prefix = writer.getPrefix(nameSpaceName);
+			prefix = this.ns.getPrefix();
+			if (nameSpaceName != null) {
+				if (writer_prefix != null) {
+					writer
+							.writeStartElement(nameSpaceName, this
+									.getLocalName());
+				} else {
+					if (prefix != null) {
+						writer.writeStartElement(prefix, this.getLocalName(),
+								nameSpaceName);
+						//TODO FIX ME
+						//writer.writeNamespace(prefix, nameSpaceName);
+						writer.setPrefix(prefix, nameSpaceName);
+					} else {
+						writer.writeStartElement(nameSpaceName, this
+								.getLocalName());
+						writer.writeDefaultNamespace(nameSpaceName);
+						writer.setDefaultNamespace(nameSpaceName);
+					}
+				}
+			} else {
+				writer.writeStartElement(this.getLocalName());
+			}
+		} else {
+			writer.writeStartElement(this.getLocalName());
+		}
+		// add the elements attribute "href"
+		serializeAttribute(this.attribute, omOutput);
+		// add the namespace
+		serializeNamespace(this.ns, omOutput);
+	}
+
+	/**
+	 * Method serializeAttribute
+	 * 
+	 * @param attr
+	 * @param omOutput
+	 * @throws XMLStreamException
+	 */
+	static void serializeAttribute(OMAttribute attr, OMOutputImpl omOutput)
+			throws XMLStreamException {
+		XMLStreamWriter writer = omOutput.getXmlStreamWriter();
+		// first check whether the attribute is associated with a namespace
+		OMNamespace ns = attr.getNamespace();
+		String prefix;
+		String namespaceName;
+		if (ns != null) {
+			// add the prefix if it's availble
+			prefix = ns.getPrefix();
+			namespaceName = ns.getName();
+			if (prefix != null) {
+				writer.writeAttribute(prefix, namespaceName, attr
+						.getLocalName(), attr.getValue());
+			} else {
+				writer.writeAttribute(namespaceName, attr.getLocalName(), attr
+						.getValue());
+			}
+		} else {
+			writer.writeAttribute(attr.getLocalName(), attr.getValue());
+		}
+	}
+
+	/**
+	 * Method serializeNamespace
+	 * 
+	 * @param namespace
+	 * @param omOutput
+	 * @throws XMLStreamException
+	 */
+	static void serializeNamespace(OMNamespace namespace,
+			org.apache.axis2.om.impl.OMOutputImpl omOutput)
+			throws XMLStreamException {
+		XMLStreamWriter writer = omOutput.getXmlStreamWriter();
+		if (namespace != null) {
+			String uri = namespace.getName();
+			String ns_prefix = namespace.getPrefix();
+			writer.writeNamespace(ns_prefix, namespace.getName());
+			writer.setPrefix(ns_prefix, uri);
+		}
+	}
+
+	/**
+	 * Slightly different implementation of the discard method
+	 * 
+	 * @throws OMException
+	 */
+	public void discard() throws OMException {
+		if (done) {
+			this.detach();
+		} else {
+			builder.discard((OMElement) this.parent);
+		}
+	}
 }

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/mtom/MTOMStAXSOAPModelBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/mtom/MTOMStAXSOAPModelBuilder.java?rev=219884&r1=219883&r2=219884&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/mtom/MTOMStAXSOAPModelBuilder.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/mtom/MTOMStAXSOAPModelBuilder.java Wed Jul 20 05:11:18 2005
@@ -86,7 +86,8 @@
                 if (contentIDName.equalsIgnoreCase("href")
                         & contentID.substring(0, 3).equalsIgnoreCase("cid")) {
                     contentID = contentID.substring(4);
-                } else {
+                } else if (!(contentIDName.equalsIgnoreCase("href")
+                       & (!contentID.equals("")))) {                    
                     throw new OMException(
                             "contentID not Found in XOP:Include element");
                 }

Modified: webservices/axis/trunk/java/modules/xml/test-resources/mtom/MTOMBuilderTestIn.txt
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/test-resources/mtom/MTOMBuilderTestIn.txt?rev=219884&r1=219883&r2=219884&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/test-resources/mtom/MTOMBuilderTestIn.txt (original)
+++ webservices/axis/trunk/java/modules/xml/test-resources/mtom/MTOMBuilderTestIn.txt Wed Jul 20 05:11:18 2005
@@ -7,6 +7,5 @@
 ------=_AxIs2_Def_boundary_=42214532
 Content-Transfer-Encoding: binary
 Content-ID: -1609420109260943731
-
-
8A ýþÿb
+
8A ???b
 ------=_AxIs2_Def_boundary_=42214532--

Modified: webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/MIMEOutputUtilsTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/MIMEOutputUtilsTest.java?rev=219884&r1=219883&r2=219884&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/MIMEOutputUtilsTest.java (original)
+++ webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/MIMEOutputUtilsTest.java Wed Jul 20 05:11:18 2005
@@ -19,6 +19,7 @@
 import org.apache.axis2.attachments.ByteArrayDataSource;
 import org.apache.axis2.soap.SOAPFactory;
 import org.apache.axis2.om.impl.MIMEOutputUtils;
+import org.apache.axis2.om.impl.OMOutputImpl;
 
 import javax.activation.DataHandler;
 import javax.mail.MessagingException;
@@ -43,9 +44,12 @@
         super.setUp();
         SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
         ByteArrayOutputStream outStream;
-        String boundary = "----TemporaryBoundary";
+        String boundary;
+        
+        OMOutputImpl omOutput = new OMOutputImpl(null);
+        boundary = omOutput.getMimeBoundary();
 
-        String contentType = org.apache.axis2.om.impl.MIMEOutputUtils.getContentTypeForMime(boundary, "cid:0.632569289925808400@example.org");
+        String contentType = org.apache.axis2.om.impl.MIMEOutputUtils.getContentTypeForMime(boundary,omOutput.getRootContentId());
         DataHandler dataHandler;
         dataHandler = new DataHandler(new ByteArrayDataSource(byteArray));
         OMText textData = factory.createText(dataHandler, true);



Mime
View raw message