You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ch...@apache.org on 2005/05/06 09:13:08 UTC

svn commit: r168550 - in /webservices/axis/trunk/archive/java/scratch/Thilina/MTOM2/src/java/org/apache/axis/om/impl/llom: builder/MTOMStAXSOAPModelBuilder.java mtom/MTOMHelper.java

Author: chinthaka
Date: Fri May  6 00:13:06 2005
New Revision: 168550

URL: http://svn.apache.org/viewcvs?rev=168550&view=rev
Log:
Applying the patch for Thilina.

Modified:
    webservices/axis/trunk/archive/java/scratch/Thilina/MTOM2/src/java/org/apache/axis/om/impl/llom/builder/MTOMStAXSOAPModelBuilder.java
    webservices/axis/trunk/archive/java/scratch/Thilina/MTOM2/src/java/org/apache/axis/om/impl/llom/mtom/MTOMHelper.java

Modified: webservices/axis/trunk/archive/java/scratch/Thilina/MTOM2/src/java/org/apache/axis/om/impl/llom/builder/MTOMStAXSOAPModelBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Thilina/MTOM2/src/java/org/apache/axis/om/impl/llom/builder/MTOMStAXSOAPModelBuilder.java?rev=168550&r1=168549&r2=168550&view=diff
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Thilina/MTOM2/src/java/org/apache/axis/om/impl/llom/builder/MTOMStAXSOAPModelBuilder.java (original)
+++ webservices/axis/trunk/archive/java/scratch/Thilina/MTOM2/src/java/org/apache/axis/om/impl/llom/builder/MTOMStAXSOAPModelBuilder.java Fri May  6 00:13:06 2005
@@ -3,10 +3,20 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.LinkedList;
+import java.util.ListIterator;
+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 javax.mail.internet.MimePartDataSource;
 import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
 
 import org.apache.axis.om.OMAttribute;
 import org.apache.axis.om.OMElement;
@@ -14,7 +24,6 @@
 import org.apache.axis.om.OMFactory;
 import org.apache.axis.om.OMNode;
 import org.apache.axis.om.impl.llom.OMBlobImpl;
-import org.apache.axis.om.impl.llom.mtom.MTOMHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -23,36 +32,68 @@
  */
 public class MTOMStAXSOAPModelBuilder extends StAXSOAPModelBuilder {
     private Log log = LogFactory.getLog(getClass());
-
-    MTOMHelper mtomHelper;
-
+    
+    InputStream inStream;
+    
+    LinkedList mimeBodyPartsList;
+    
+    MimeMessage mimeMessage;
+    
+    int partIndex = 0;
+    
     public MTOMStAXSOAPModelBuilder(OMFactory ombuilderFactory,
             InputStream inStream) throws XMLStreamException,
             FactoryConfigurationError, OMException {
         super(ombuilderFactory);
-        mtomHelper = new MTOMHelper(inStream);
-        this.parser = mtomHelper.getParser();
+        this.inStream = inStream;
+        this.parser = getParserFromMime();
     }
-
+    
     public MTOMStAXSOAPModelBuilder(InputStream inStream)
-            throws XMLStreamException, FactoryConfigurationError, IOException,
-            MessagingException {
+    throws XMLStreamException, FactoryConfigurationError, IOException,
+    MessagingException {
         super();
-        mtomHelper = new MTOMHelper(inStream);
-        this.parser = mtomHelper.getParser();
+        this.inStream = inStream;
+        this.parser = getParserFromMime();
+    }
+    
+    private XMLStreamReader getParserFromMime() throws OMException, XMLStreamException, FactoryConfigurationError
+    {        
+        mimeBodyPartsList = new LinkedList();
+        Properties props = new Properties();
+        javax.mail.Session session = javax.mail.Session.getInstance(props, null);
+        try {
+            mimeMessage = new MimeMessage(session, inStream);
+            
+            MimeBodyPart rootMimeBodyPart;
+            try {
+                rootMimeBodyPart = getRootMimeBodyPart();
+                return XMLInputFactory.newInstance().createXMLStreamReader(
+                        rootMimeBodyPart.getInputStream());
+                
+            } catch (IOException e1) {
+                throw new OMException(e1.toString());
+                
+            } catch (MessagingException e) {
+                throw new OMException("Unable to extract root MIME part "
+                        + e.toString());
+            }
+        } catch (MessagingException e) {
+            throw new OMException(
+            "Message identified as MTOM optimised doesn't contain a valid MIME Stream");
+        }
     }
-
     protected OMNode createOMElement() throws OMException {
-
+        
         String elementName = parser.getLocalName();
-
+        
         String namespaceURI = parser.getNamespaceURI();
-
+        
         // create an OMBlob if the element is an <xop:Include>
         if (elementName.equalsIgnoreCase("Include")
                 & namespaceURI
-                        .equalsIgnoreCase("http://www.w3.org/2004/08/xop/include")) {
-
+                .equalsIgnoreCase("http://www.w3.org/2004/08/xop/include")) {
+            
             OMBlobImpl node;
             String contentID = null;
             String contentIDName = null;
@@ -60,7 +101,7 @@
             if (lastNode == null) {
                 // Decide whether to ckeck the level >3 or not
                 throw new OMException(
-                        "XOP:Include element is not supported here");
+                "XOP:Include element is not supported here");
             }
             if (parser.getAttributeCount() > 0) {
                 contentID = parser.getAttributeValue(0);
@@ -71,26 +112,24 @@
                     contentID = contentID.substring(4);
                 } else {
                     throw new OMException(
-                            "contentID not Found in XOP:Include element");
+                    "contentID not Found in XOP:Include element");
                 }
             } else {
                 throw new OMException(
-                        "Href attribute not found in XOP:Include element");
+                "Href attribute not found in XOP:Include element");
             }
-
+            
             if (lastNode.isComplete()) {
-                node = new OMBlobImpl(contentID, lastNode.getParent(),
-                        mtomHelper, this);
+                node = new OMBlobImpl(contentID, lastNode.getParent(),this);
                 lastNode.setNextSibling(node);
                 node.setPreviousSibling(lastNode);
             } else {
                 OMElement e = (OMElement) lastNode;
-                node = new OMBlobImpl(contentID, (OMElement) lastNode,
-                        mtomHelper, this);
+                node = new OMBlobImpl(contentID, (OMElement) lastNode, this);
                 e.setFirstChild(node);
             }
             return node;
-
+            
         } else {
             OMElement node;
             if (lastNode == null) {
@@ -104,7 +143,7 @@
                 node = constructNode((OMElement) lastNode, elementName, false);
                 e.setFirstChild(node);
             }
-
+            
             // fill in the attributes
             processAttributes(node);
             log.info("Build the OMElelment {" + node.getNamespaceName() + '}'
@@ -112,4 +151,74 @@
             return node;
         }
     }
-}
\ No newline at end of file
+    
+    public DataHandler getDataHandler(String blobContentID) throws OMException {
+        /*
+         * First checks whether the part is already parsed by checking the parts
+         * linked list. If it is not parsed yet then call the getnextPart() till
+         * we find the required part.
+         */
+        MimeBodyPart mimeBodyPart;
+        
+        boolean attachmentFound = false;
+        ListIterator partsIterator = mimeBodyPartsList.listIterator();
+        try {
+            while (partsIterator.hasNext()) {
+                mimeBodyPart = (MimeBodyPart) partsIterator.next();
+                if (blobContentID.equals(mimeBodyPart.getContentID())) {
+                    attachmentFound = true;
+                    DataHandler dh = mimeBodyPart.getDataHandler();
+                    return dh;
+                }
+            }
+            while (!attachmentFound) {
+                mimeBodyPart = this.getNextMimeBodyPart();
+                
+                if (mimeBodyPart == null) {
+                    break;
+                }
+                String partContentID = mimeBodyPart.getContentID();
+                String delimitedBlobContentID = "<" + blobContentID + ">";
+                if (delimitedBlobContentID.equals(partContentID)) {
+                    attachmentFound = true;
+                    DataHandler dh = mimeBodyPart.getDataHandler();
+                    return dh;
+                }
+            }
+            return null;
+        } catch (MessagingException e) {
+            throw new OMException("Invalid Mime Message "
+                    + e.toString());
+        }
+    }
+    private MimeBodyPart getMimeBodyPart() throws MessagingException {
+        MimeBodyPart mimeBodyPart = null;
+        
+        DataHandler dh = mimeMessage.getDataHandler();
+        MimeMultipart multiPart = new MimeMultipart((MimePartDataSource) dh.getDataSource());
+        mimeBodyPart = (MimeBodyPart) multiPart.getBodyPart(partIndex);
+        
+        partIndex++;
+        return mimeBodyPart;
+    }
+    private MimeBodyPart getRootMimeBodyPart() throws MessagingException {
+        MimeBodyPart rootMimeBodyPart;
+        if (mimeBodyPartsList.isEmpty()) {
+            rootMimeBodyPart = getMimeBodyPart();
+            mimeBodyPartsList.add(rootMimeBodyPart);
+        } else {
+            rootMimeBodyPart = (MimeBodyPart) mimeBodyPartsList.getFirst();
+        }
+        return rootMimeBodyPart;
+    }
+    
+    private MimeBodyPart getNextMimeBodyPart() throws MessagingException {
+        MimeBodyPart nextMimeBodyPart;
+        nextMimeBodyPart = getMimeBodyPart();
+        if (nextMimeBodyPart != null) {
+            mimeBodyPartsList.add(nextMimeBodyPart);
+            return nextMimeBodyPart;
+        } else
+            return null;
+    }
+}

Modified: webservices/axis/trunk/archive/java/scratch/Thilina/MTOM2/src/java/org/apache/axis/om/impl/llom/mtom/MTOMHelper.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Thilina/MTOM2/src/java/org/apache/axis/om/impl/llom/mtom/MTOMHelper.java?rev=168550&r1=168549&r2=168550&view=diff
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Thilina/MTOM2/src/java/org/apache/axis/om/impl/llom/mtom/MTOMHelper.java (original)
+++ webservices/axis/trunk/archive/java/scratch/Thilina/MTOM2/src/java/org/apache/axis/om/impl/llom/mtom/MTOMHelper.java Fri May  6 00:13:06 2005
@@ -1,172 +0,0 @@
-package org.apache.axis.om.impl.llom.mtom;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.LinkedList;
-import java.util.ListIterator;
-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 javax.mail.internet.MimePartDataSource;
-import javax.xml.stream.FactoryConfigurationError;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
-import org.apache.axis.om.OMException;
-
-/**
- * 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/>
- */
-
-/**
- * @author Thilina Gunarathne thilina@opensource.lk
- */
-public class MTOMHelper {
-
-    InputStream inStream;
-
-    boolean mime;
-
-    LinkedList mimeBodyPartsList;
-
-    MimeMessage mimeMessage;
-
-    int partIndex = 0;
-
-    public MTOMHelper(InputStream inStream) throws OMException {
-        this.inStream = inStream;
-
-        mimeBodyPartsList = new LinkedList();
-
-        Properties props = new Properties();
-        javax.mail.Session session = javax.mail.Session
-                .getInstance(props, null);
-        try {
-            mimeMessage = new MimeMessage(session, inStream);
-            mime = true;
-        } catch (MessagingException e) {
-            mime = false;
-            throw new OMException(
-                    "MTOM identified message doesn't contain valid MIME Stream");
-        }
-    }
-
-    public DataHandler getDataHandler(String blobContentID) throws OMException {
-        /*
-         * First checks whether the part is already parsed by checking the parts
-         * linked list. If it is not parsed yet then call the getnextPart() till
-         * we find the required part.
-         */
-        MimeBodyPart mimeBodyPart;
-
-        boolean attachmentFound = false;
-        ListIterator partsIterator = mimeBodyPartsList.listIterator();
-        try {
-            while (partsIterator.hasNext()) {
-                mimeBodyPart = (MimeBodyPart) partsIterator.next();
-                if (blobContentID.equals(mimeBodyPart.getContentID())) {
-                    attachmentFound = true;
-                    DataHandler dh = mimeBodyPart.getDataHandler();
-                    return dh;
-                }
-            }
-            while (!attachmentFound) {
-                mimeBodyPart = this.getNextMimeBodyPart();
-
-                if (mimeBodyPart == null) {
-                    break;
-                }
-                String partContentID = mimeBodyPart.getContentID();
-                String delimitedBlobContentID = "<" + blobContentID + ">";
-                if (delimitedBlobContentID.equals(partContentID)) {
-                    attachmentFound = true;
-                    DataHandler dh = mimeBodyPart.getDataHandler();
-                    return dh;
-                }
-            }
-            return null;
-        } catch (MessagingException e) {
-            throw new OMException("Invalid SOAP Message in Root Mime part "
-                    + e.toString());
-        }
-    }
-
-    private MimeBodyPart getMimeBodyPart() throws MessagingException {
-        MimeBodyPart mimeBodyPart = null;
-
-        DataHandler dh = mimeMessage.getDataHandler();
-        MimeMultipart multiPart = new MimeMultipart((MimePartDataSource) dh
-                .getDataSource());
-        mimeBodyPart = (MimeBodyPart) multiPart.getBodyPart(partIndex);
-
-        partIndex++;
-        return mimeBodyPart;
-    }
-
-    private MimeBodyPart getNextMimeBodyPart() throws MessagingException {
-        MimeBodyPart nextMimeBodyPart;
-        nextMimeBodyPart = getMimeBodyPart();
-        if (nextMimeBodyPart != null) {
-            mimeBodyPartsList.add(nextMimeBodyPart);
-            System.out.println("Next part parsed. NO of parts parsed :"
-                    + mimeBodyPartsList.size());
-            return nextMimeBodyPart;
-        } else
-            return null;
-    }
-
-    public XMLStreamReader getParser() throws OMException, XMLStreamException, FactoryConfigurationError {
-
-        if (mime) {
-            MimeBodyPart rootMimeBodyPart;
-            try {
-                rootMimeBodyPart = getRootMimeBodyPart();
-                return XMLInputFactory.newInstance().createXMLStreamReader(
-                        rootMimeBodyPart.getInputStream());
-            
-            } catch (IOException e1) {
-                throw new OMException(e1.toString());
-
-            } catch (MessagingException e) {
-                throw new OMException("Unable to extract root MIME part "
-                        + e.toString());
-            }
-
-        } else {
-            throw new OMException(
-                    "MTOM identified message doesn't contain valid MIME Stream");
-        }
-    }
-
-    private MimeBodyPart getRootMimeBodyPart() throws MessagingException {
-        MimeBodyPart rootMimeBodyPart;
-        if (mimeBodyPartsList.isEmpty()) {
-            rootMimeBodyPart = getMimeBodyPart();
-            mimeBodyPartsList.add(rootMimeBodyPart);
-        } else {
-            rootMimeBodyPart = (MimeBodyPart) mimeBodyPartsList.getFirst();
-        }
-        System.out.println("MIME root parsed. NO of parts parsed :"
-                + mimeBodyPartsList.size());
-        return rootMimeBodyPart;
-    }
-
-}
\ No newline at end of file