axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r486906 - in /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2: client/ transport/ transport/http/ transport/http/util/ transport/jms/ transport/local/ transport/mail/ transport/mail/server/ transport/tcp/ util/
Date Thu, 14 Dec 2006 00:29:24 GMT
Author: dims
Date: Wed Dec 13 16:29:24 2006
New Revision: 486906

URL: http://svn.apache.org/viewvc?view=rev&rev=486906
Log:
cleanup creation of all the builders, consolidate it in a helper class called Builder, this is preparation to introduce BuilderSelector

Added:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Builder.java
Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/Stub.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/util/RESTUtil.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/jms/JMSUtils.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/local/LocalTransportReceiver.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/server/MailSorter.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/tcp/TCPWorker.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/Stub.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/Stub.java?view=diff&rev=486906&r1=486905&r2=486906
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/Stub.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/Stub.java Wed Dec 13 16:29:24 2006
@@ -17,14 +17,7 @@
 
 package org.apache.axis2.client;
 
-import java.util.ArrayList;
-
-import javax.xml.stream.XMLStreamReader;
-
 import org.apache.axiom.om.OMAbstractFactory;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
 import org.apache.axiom.soap.SOAP11Constants;
 import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axiom.soap.SOAPEnvelope;
@@ -34,6 +27,8 @@
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.i18n.Messages;
 
+import java.util.ArrayList;
+
 /**
  * Base class for generated client stubs. This defines several client API
  * (<code>public</code>) methods shared between all types of stubs, along with
@@ -80,20 +75,6 @@
      */
     protected static SOAPEnvelope createEnvelope(Options options) throws SOAPProcessingException {
         return getFactory(options.getSoapVersionURI()).getDefaultEnvelope();
-    }
-
-    /**
-     * Read a root element from the parser.
-     * TODO generated stub code should use this method
-     * 
-     * @param reader
-     * @return root element
-     */
-    protected static OMElement getElementFromReader(XMLStreamReader reader) {
-        StAXOMBuilder builder =
-                OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory.getOMFactory(), reader);
-
-        return builder.getDocumentElement();
     }
 
     /**

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java?view=diff&rev=486906&r1=486905&r2=486906
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java Wed Dec 13 16:29:24 2006
@@ -17,40 +17,19 @@
 
 package org.apache.axis2.transport;
 
-import org.apache.axiom.attachments.Attachments;
-import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.util.StAXUtils;
-import org.apache.axiom.om.impl.MTOMConstants;
-import org.apache.axiom.om.impl.builder.StAXBuilder;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-import org.apache.axiom.om.impl.builder.XOPAwareStAXOMBuilder;
-import org.apache.axiom.soap.SOAP11Constants;
-import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.soap.SOAPFactory;
-import org.apache.axiom.soap.impl.builder.MTOMStAXSOAPModelBuilder;
-import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
-import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.context.OperationContext;
-import org.apache.axis2.description.Parameter;
 import org.apache.axis2.i18n.Messages;
 import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.util.Builder;
 
-import javax.xml.parsers.FactoryConfigurationError;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import java.io.BufferedReader;
-import java.io.IOException;
 import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.PushbackInputStream;
-import java.io.Reader;
 
 public class TransportUtils {
-    private static final int BOM_SIZE = 4;
 
     public static SOAPEnvelope createSOAPMessage(MessageContext msgContext, String soapNamespaceURI)
             throws AxisFault {
@@ -80,44 +59,26 @@
                 throw new AxisFault(Messages.getMessage("cannotBeNullOperationContext"));
             }
 
-            StAXBuilder builder;
             SOAPEnvelope envelope ;
             String charSetEnc =
                     (String) msgContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
-
             if (charSetEnc == null) {
                 charSetEnc = (String) opContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
             }
-
             if (charSetEnc == null) {
                 charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
             }
 
             if (contentType != null) {
                 msgContext.setDoingMTOM(true);
-                builder = selectBuilderForMIME(msgContext, inStream,
-                        (String) contentType,true);
+                OMXMLParserWrapper builder = Builder.getAttachmentsBuilder(msgContext, inStream,
+                        (String) contentType, true);
                 envelope = (SOAPEnvelope) builder.getDocumentElement();
             } else if (msgContext.isDoingREST()) {
-                XMLStreamReader xmlreader =
-                        StAXUtils.createXMLStreamReader(inStream, charSetEnc);
-                SOAPFactory soapFactory = new SOAP11Factory();
-
-                builder = new StAXOMBuilder(xmlreader);
-                builder.setOMBuilderFactory(soapFactory);
-                envelope = soapFactory.getDefaultEnvelope();
-                envelope.getBody().addChild(builder.getDocumentElement());
-                
-                // We now have the message inside an envolope. However, this is 
-                // only an OM; We need to build a SOAP model from it.
-
-                builder = new StAXSOAPModelBuilder(envelope.getXMLStreamReader(), soapNamespaceURI);
+                OMXMLParserWrapper builder = Builder.getPOXBuilder(inStream, charSetEnc, soapNamespaceURI);
                 envelope = (SOAPEnvelope) builder.getDocumentElement();
             } else {
-                XMLStreamReader xmlreader =
-                        StAXUtils.createXMLStreamReader(inStream, charSetEnc);
-
-                builder = new StAXSOAPModelBuilder(xmlreader, soapNamespaceURI);
+                OMXMLParserWrapper builder = Builder.getBuilder(inStream, charSetEnc, soapNamespaceURI);
                 envelope = (SOAPEnvelope) builder.getDocumentElement();
             }
 
@@ -125,220 +86,5 @@
         } catch (Exception e) {
             throw new AxisFault(e);
         }
-    }
-
-    /**
-     * Extracts and returns the character set encoding from the
-     * Content-type header
-     * Example:
-     * Content-Type: text/xml; charset=utf-8
-     *
-     * @param contentType
-     */
-    public static String getCharSetEncoding(String contentType) {
-        int index = contentType.indexOf(HTTPConstants.CHAR_SET_ENCODING);
-
-        if (index == -1) {    // Charset encoding not found in the content-type header
-            // Using the default UTF-8
-            return MessageContext.DEFAULT_CHAR_SET_ENCODING;
-        }
-
-        // If there are spaces around the '=' sign
-        int indexOfEq = contentType.indexOf("=", index);
-
-        // There can be situations where "charset" is not the last parameter of the Content-Type header
-        int indexOfSemiColon = contentType.indexOf(";", indexOfEq);
-        String value;
-
-        if (indexOfSemiColon > 0) {
-            value = (contentType.substring(indexOfEq + 1, indexOfSemiColon));
-        } else {
-            value = (contentType.substring(indexOfEq + 1, contentType.length())).trim();
-        }
-
-        // There might be "" around the value - if so remove them
-        if(value.indexOf('\"')!=-1){
-            value = value.replaceAll("\"", "");
-        }
-
-        return value.trim();
-    }
-
-	public static StAXBuilder selectBuilderForMIME(MessageContext msgContext,
-			InputStream inStream, String contentTypeString, boolean isSOAP)
-			throws OMException, XMLStreamException, FactoryConfigurationError {
-		StAXBuilder builder = null;
-
-		Object cacheAttachmentProperty = msgContext
-				.getProperty(Constants.Configuration.CACHE_ATTACHMENTS);
-		String cacheAttachmentString = null;
-		boolean fileCacheForAttachments;
-
-		if (cacheAttachmentProperty != null
-				&& cacheAttachmentProperty instanceof String) {
-			cacheAttachmentString = (String) cacheAttachmentProperty;
-			fileCacheForAttachments = (Constants.VALUE_TRUE
-					.equals(cacheAttachmentString));
-		} else {
-			Parameter parameter_cache_attachment = msgContext
-					.getParameter(Constants.Configuration.CACHE_ATTACHMENTS);
-			cacheAttachmentString = (parameter_cache_attachment != null) ? (String) parameter_cache_attachment
-					.getValue()
-					: null;
-		}
-		fileCacheForAttachments = (Constants.VALUE_TRUE
-				.equals(cacheAttachmentString));
-
-		String attachmentRepoDir = null;
-		String attachmentSizeThreshold = null;
-
-		if (fileCacheForAttachments) {
-			Object attachmentRepoDirProperty = msgContext
-					.getProperty(Constants.Configuration.ATTACHMENT_TEMP_DIR);
-
-			if (attachmentRepoDirProperty != null) {
-				attachmentRepoDir = (String) attachmentRepoDirProperty;
-			} else {
-				Parameter attachmentRepoDirParameter = msgContext
-						.getParameter(Constants.Configuration.ATTACHMENT_TEMP_DIR);
-				attachmentRepoDir = (attachmentRepoDirParameter != null) ? (String) attachmentRepoDirParameter
-						.getValue()
-						: null;
-			}
-
-			Object attachmentSizeThresholdProperty = msgContext
-					.getProperty(Constants.Configuration.FILE_SIZE_THRESHOLD);
-			if (attachmentSizeThresholdProperty != null
-					&& attachmentSizeThresholdProperty instanceof String) {
-				attachmentSizeThreshold = (String) attachmentSizeThresholdProperty;
-			} else {
-				Parameter attachmentSizeThresholdParameter = msgContext
-						.getParameter(Constants.Configuration.FILE_SIZE_THRESHOLD);
-				attachmentSizeThreshold = attachmentSizeThresholdParameter
-						.getValue().toString();
-			}
-		}
-
-		Attachments attachments = new Attachments(inStream, contentTypeString,
-				fileCacheForAttachments, attachmentRepoDir,
-				attachmentSizeThreshold);
-		String charSetEncoding = getCharSetEncoding(attachments
-				.getSOAPPartContentType());
-		XMLStreamReader streamReader;
-
-		if ((charSetEncoding == null)
-				|| "null".equalsIgnoreCase(charSetEncoding)) {
-			charSetEncoding = MessageContext.UTF_8;
-		}
-
-		try {
-			streamReader = StAXUtils.createXMLStreamReader(getReader(
-					attachments.getSOAPPartInputStream(), charSetEncoding));
-		} catch (IOException e) {
-			throw new XMLStreamException(e);
-		}
-
-		msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
-				charSetEncoding);
-
-		/*
-		 * Put a reference to Attachments Map in to the message context For
-		 * backword compatibility with Axis2 1.0
-		 */
-		msgContext.setProperty(MTOMConstants.ATTACHMENTS, attachments);
-
-		/*
-		 * Setting the Attachments map to new SwA API
-		 */
-		msgContext.setAttachmentMap(attachments);
-
-		String soapEnvelopeNamespaceURI = null;
-		if (contentTypeString.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
-			soapEnvelopeNamespaceURI = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI;
-		} else if (contentTypeString
-				.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
-			soapEnvelopeNamespaceURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
-		}
-
-		if (isSOAP) {
-			if (attachments.getAttachmentSpecType().equals(
-					MTOMConstants.MTOM_TYPE)
-					& null != soapEnvelopeNamespaceURI) {
-
-				/*
-				 * Creates the MTOM specific MTOMStAXSOAPModelBuilder
-				 */
-				builder = new MTOMStAXSOAPModelBuilder(streamReader,
-						attachments, soapEnvelopeNamespaceURI);
-
-			} else if (attachments.getAttachmentSpecType().equals(
-					MTOMConstants.SWA_TYPE)
-					& null != soapEnvelopeNamespaceURI) {
-				builder = new StAXSOAPModelBuilder(streamReader,
-						soapEnvelopeNamespaceURI);
-			}
-		}
-		// To handle REST XOP case
-		else {
-			if (attachments.getAttachmentSpecType().equals(
-					MTOMConstants.MTOM_TYPE)) {
-				XOPAwareStAXOMBuilder stAXOMBuilder = new XOPAwareStAXOMBuilder(
-						streamReader, attachments);
-				builder = stAXOMBuilder;
-
-			} else if (attachments.getAttachmentSpecType().equals(
-					MTOMConstants.SWA_TYPE)) {
-				builder = new StAXOMBuilder(streamReader);
-			}
-		}
-
-		return builder;
-	}
-
-    /**
-	 * Use the BOM Mark to identify the encoding to be used. Fall back to
-	 * default encoding specified
-	 * 
-	 * @param is
-	 * @param charSetEncoding
-	 * @throws java.io.IOException
-	 */
-    private static Reader getReader(InputStream is, String charSetEncoding) throws IOException {
-        PushbackInputStream is2 = new PushbackInputStream(is, BOM_SIZE);
-        String encoding;
-        byte bom[] = new byte[BOM_SIZE];
-        int n, unread;
-
-        n = is2.read(bom, 0, bom.length);
-
-        if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF)) {
-            encoding = "UTF-8";
-            unread = n - 3;
-        } else if ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) {
-            encoding = "UTF-16BE";
-            unread = n - 2;
-        } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)) {
-            encoding = "UTF-16LE";
-            unread = n - 2;
-        } else if ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00) && (bom[2] == (byte) 0xFE)
-                && (bom[3] == (byte) 0xFF)) {
-            encoding = "UTF-32BE";
-            unread = n - 4;
-        } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE) && (bom[2] == (byte) 0x00)
-                && (bom[3] == (byte) 0x00)) {
-            encoding = "UTF-32LE";
-            unread = n - 4;
-        } else {
-
-            // Unicode BOM mark not found, unread all bytes
-            encoding = charSetEncoding;
-            unread = n;
-        }
-
-        if (unread > 0) {
-            is2.unread(bom, (n - unread), unread);
-        }
-
-        return new BufferedReader(new InputStreamReader(is2, encoding));
     }
 }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPTransportUtils.java?view=diff&rev=486906&r1=486905&r2=486906
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPTransportUtils.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPTransportUtils.java Wed Dec 13 16:29:24 2006
@@ -21,10 +21,11 @@
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.impl.builder.StAXBuilder;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-import org.apache.axiom.om.util.StAXUtils;
-import org.apache.axiom.soap.*;
-import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.SOAPProcessingException;
 import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
 import org.apache.axiom.soap.impl.llom.soap12.SOAP12Factory;
 import org.apache.axis2.AxisFault;
@@ -36,13 +37,12 @@
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.engine.AxisEngine;
 import org.apache.axis2.engine.Handler.InvocationResponse;
-import org.apache.axis2.transport.TransportUtils;
+import org.apache.axis2.util.Builder;
 import org.apache.axis2.util.JavaUtils;
 import org.apache.axis2.util.Utils;
 
 import javax.xml.parsers.FactoryConfigurationError;
 import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -195,108 +195,51 @@
             SOAPEnvelope envelope = null;
             StAXBuilder builder = null;
 
-            if (contentType != null) {
+            // get the type of char encoding
+            String charSetEnc = Builder.getCharSetEncoding(contentType);
+            if(charSetEnc == null){
+                charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
+            }
+            // Setting the value in msgCtx
+            msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
 
+            String soapNS = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
+            if (contentType != null) {
                 if (contentType.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
                     soapVersion = VERSION_SOAP12;
+                    soapNS = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI;
+                    processContentTypeForAction(contentType, msgContext);
                 } else if (contentType.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
                     soapVersion = VERSION_SOAP11;
+                    soapNS = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
                 }
                 if (JavaUtils.indexOfIgnoreCase(contentType, HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED) > -1) {
                     // It is MIME (MTOM or SwA)
-                    builder = TransportUtils.selectBuilderForMIME(msgContext, in, contentType,true);
+                    builder = Builder.getAttachmentsBuilder(msgContext, in, contentType, true);
                     envelope = (SOAPEnvelope) builder.getDocumentElement();
-                } else {
-                    XMLStreamReader xmlreader;
-
-                    // Figure out the char set encoding and create the reader
-
-                    // If charset is not specified
-                    if (TransportUtils.getCharSetEncoding(contentType) == null) {
-                        xmlreader = StAXUtils.createXMLStreamReader(in,
-                                                                    MessageContext.DEFAULT_CHAR_SET_ENCODING);
-
-                        // Set the encoding scheme in the message context
-                        msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
-                                               MessageContext.DEFAULT_CHAR_SET_ENCODING);
-                    } else {
-
-                        // get the type of char encoding
-                        String charSetEnc = TransportUtils.getCharSetEncoding(contentType);
-
-                        xmlreader = StAXUtils.createXMLStreamReader(in,
-                                                                    charSetEnc);
-
-                        // Setting the value in msgCtx
-                        msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
-                    }
+                } else if (soapVersion == VERSION_SOAP11) {
+                    // Deployment configuration parameter
+                    Parameter enable =
+                            msgContext.getParameter(Constants.Configuration.ENABLE_REST);
+
+                    if ((soapActionHeader == null) && (enable != null)) {
+                        if (Constants.VALUE_TRUE.equals(enable.getValue())) {
+                            // If the content Type is text/xml (BTW which is the SOAP 1.1 Content type ) and
+                            // the SOAP Action is absent it is rest !!
+                            msgContext.setDoingREST(true);
 
-                    if (soapVersion == VERSION_SOAP12) {
-                        //Check for action header and set it in as soapAction in MessageContext
-                        int index = contentType.indexOf("action");
-                        if (index > -1) {
-                            String transientString = contentType.substring(index, contentType.length());
-                            int equal = transientString.indexOf("=");
-                            int firstSemiColon = transientString.indexOf(";");
-                            String soapAction; // This will contain "" in the string
-                            if (firstSemiColon > -1) {
-                                soapAction = transientString.substring(equal + 1, firstSemiColon);
-                            } else {
-                                soapAction = transientString.substring(equal + 1, transientString.length());
-                            }
-                            if ((soapAction != null) && soapAction.startsWith("\"")
-                                && soapAction.endsWith("\"")) {
-                                soapAction = soapAction
-                                        .substring(1, soapAction.length() - 1);
-                            }
-                            msgContext.setSoapAction(soapAction);
+                            SOAPFactory soapFactory = new SOAP11Factory();
+                            envelope = soapFactory.getDefaultEnvelope();
 
-                        }
-
-                        // it is SOAP 1.2
-                        builder =
-                                new StAXSOAPModelBuilder(xmlreader,
-                                                         SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-                        envelope = (SOAPEnvelope) builder.getDocumentElement();
-                    } else if (soapVersion == VERSION_SOAP11) {
-                        /**
-                         * Configuration via Deployment
-                         */
-                        Parameter enable =
-                                msgContext.getParameter(Constants.Configuration.ENABLE_REST);
-
-                        if ((soapActionHeader == null) && (enable != null)) {
-                            if (Constants.VALUE_TRUE.equals(enable.getValue())) {
-
-                                // If the content Type is text/xml (BTW which is the SOAP 1.1 Content type ) and
-                                // the SOAP Action is absent it is rest !!
-                                msgContext.setDoingREST(true);
-
-                                SOAPFactory soapFactory = new SOAP11Factory();
-
-                                builder = new StAXOMBuilder(xmlreader);
-                                builder.setOMBuilderFactory(soapFactory);
-                                envelope = soapFactory.getDefaultEnvelope();
-                                envelope.getBody().addChild(builder.getDocumentElement());
-                            }
-                        } else {
-                            builder = new StAXSOAPModelBuilder(
-                                    xmlreader, SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-                            envelope = (SOAPEnvelope) builder.getDocumentElement();
+                            builder = Builder.getBuilder(soapFactory, in, charSetEnc);
+                            envelope.getBody().addChild(builder.getDocumentElement());
                         }
                     }
                 }
             }
 
             if (builder == null) {
-                XMLStreamReader xmlreader = StAXUtils.createXMLStreamReader(in,
-                                                                            MessageContext.DEFAULT_CHAR_SET_ENCODING);
-
-                // Set the encoding scheme in the message context
-                msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
-                                       MessageContext.DEFAULT_CHAR_SET_ENCODING);
-                builder = new StAXSOAPModelBuilder(
-                        xmlreader, SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+                builder = Builder.getBuilder(in, charSetEnc, soapNS);
                 envelope = (SOAPEnvelope) builder.getDocumentElement();
             }
 
@@ -346,6 +289,29 @@
             if ((msgContext.getEnvelope() == null) && soapVersion != VERSION_SOAP11) {
                 msgContext.setEnvelope(new SOAP12Factory().getDefaultEnvelope());
             }
+        }
+    }
+
+    private static void processContentTypeForAction(String contentType, MessageContext msgContext) {
+        //Check for action header and set it in as soapAction in MessageContext
+        int index = contentType.indexOf("action");
+        if (index > -1) {
+            String transientString = contentType.substring(index, contentType.length());
+            int equal = transientString.indexOf("=");
+            int firstSemiColon = transientString.indexOf(";");
+            String soapAction; // This will contain "" in the string
+            if (firstSemiColon > -1) {
+                soapAction = transientString.substring(equal + 1, firstSemiColon);
+            } else {
+                soapAction = transientString.substring(equal + 1, transientString.length());
+            }
+            if ((soapAction != null) && soapAction.startsWith("\"")
+                && soapAction.endsWith("\"")) {
+                soapAction = soapAction
+                        .substring(1, soapAction.length() - 1);
+            }
+            msgContext.setSoapAction(soapAction);
+
         }
     }
 

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/util/RESTUtil.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/util/RESTUtil.java?view=diff&rev=486906&r1=486905&r2=486906
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/util/RESTUtil.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/util/RESTUtil.java Wed Dec 13 16:29:24 2006
@@ -17,8 +17,7 @@
 
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.impl.OMNodeEx;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.om.impl.builder.StAXBuilder;
 import org.apache.axiom.soap.SOAPBody;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.SOAPFactory;
@@ -30,8 +29,8 @@
 import org.apache.axis2.description.AxisOperation;
 import org.apache.axis2.engine.AxisEngine;
 import org.apache.axis2.engine.RequestURIBasedDispatcher;
-import org.apache.axis2.transport.TransportUtils;
 import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.util.Builder;
 import org.apache.axis2.util.SchemaUtil;
 import org.apache.axis2.wsdl.WSDLConstants;
 import org.apache.ws.commons.schema.XmlSchemaElement;
@@ -39,7 +38,6 @@
 import javax.servlet.ServletInputStream;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.xml.stream.XMLStreamReader;
 import java.io.IOException;
 
 /**
@@ -184,34 +182,25 @@
             // I'm assuming here that the user is sending this data according to the schema.
             if (checkContentType(org.apache.axis2.transport.http.HTTPConstants.MEDIA_TYPE_TEXT_XML, contentType)) {
 
-                // If charset is not specified
-                XMLStreamReader xmlreader;
-                if (TransportUtils.getCharSetEncoding(contentType) == null) {
-                    xmlreader = StAXUtils.createXMLStreamReader(inputStream, MessageContext.DEFAULT_CHAR_SET_ENCODING);
-
-                    // Set the encoding scheme in the message context
-                    msgCtxt.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
-                            MessageContext.DEFAULT_CHAR_SET_ENCODING);
+                String charSetEnc;
+                if (Builder.getCharSetEncoding(contentType) == null) {
+                    // If charset is not specified
+                    charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
                 } else {
-
                     // get the type of char encoding
-                    String charSetEnc = TransportUtils.getCharSetEncoding(contentType);
-
-                    xmlreader = StAXUtils.createXMLStreamReader(inputStream,
-                            charSetEnc);
-
-                    // Setting the value in msgCtx
-                    msgCtxt.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
+                    charSetEnc = Builder.getCharSetEncoding(contentType);
                 }
+                // Setting the value in msgCtx
+                msgCtxt.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
 
-                OMNodeEx documentElement = (OMNodeEx) new StAXOMBuilder(xmlreader).getDocumentElement();
+                StAXBuilder builder = Builder.getBuilder(inputStream, charSetEnc, null);
+                OMNodeEx documentElement = (OMNodeEx) builder.getDocumentElement();
                 documentElement.setParent(null);
                 body.addChild(documentElement);
 
                 // if the media type is multipart/related, get help from Axis2 :)
-            } else
-            if (checkContentType(org.apache.axis2.transport.http.HTTPConstants.MEDIA_TYPE_MULTIPART_RELATED, contentType)) {
-                body.addChild(TransportUtils.selectBuilderForMIME(msgCtxt,
+            } else if (checkContentType(org.apache.axis2.transport.http.HTTPConstants.MEDIA_TYPE_MULTIPART_RELATED, contentType)) {
+                body.addChild(Builder.getAttachmentsBuilder(msgCtxt,
                         inputStream,
                         contentType, false).getDocumentElement());
             }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/jms/JMSUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/jms/JMSUtils.java?view=diff&rev=486906&r1=486905&r2=486906
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/jms/JMSUtils.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/jms/JMSUtils.java Wed Dec 13 16:29:24 2006
@@ -17,21 +17,19 @@
 
 import org.apache.axiom.om.OMOutputFormat;
 import org.apache.axiom.om.impl.builder.StAXBuilder;
-import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axiom.soap.SOAP11Constants;
 import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
-import org.apache.axis2.util.JavaUtils;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.context.OperationContext;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.engine.AxisConfiguration;
-import org.apache.axis2.transport.TransportUtils;
 import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.util.Builder;
+import org.apache.axis2.util.JavaUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -40,7 +38,6 @@
 import javax.jms.Message;
 import javax.jms.TextMessage;
 import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
@@ -163,7 +160,7 @@
                     return
                         new ByteArrayInputStream(
                             txtMsg.getText().getBytes(
-                            TransportUtils.getCharSetEncoding(contentType)));
+                            Builder.getCharSetEncoding(contentType)));
                 } else {
                     return
                         new ByteArrayInputStream(txtMsg.getText().getBytes());
@@ -294,65 +291,23 @@
         throws XMLStreamException {
 
         SOAPEnvelope envelope = null;
-        StAXBuilder builder = null;
-
+        StAXBuilder builder;
         String contentType = JMSUtils.getProperty(message, JMSConstants.CONTENT_TYPE);
 
-        if (contentType != null) {
-            if (contentType.indexOf(
+        if (contentType != null && contentType.indexOf(
                 HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED) > -1) {
-                // It is MTOM
-                builder = TransportUtils.selectBuilderForMIME(
-                    msgContext, in, contentType,true);
-                envelope = (SOAPEnvelope) builder.getDocumentElement();
-
-            } else {
-                // Figure out the char set encoding and create the reader
-                XMLStreamReader xmlreader;
-
-                // If charset is not specified
-                if (TransportUtils.getCharSetEncoding(contentType) == null) {
-                    xmlreader = StAXUtils.createXMLStreamReader(in,
-                                                                MessageContext.DEFAULT_CHAR_SET_ENCODING);
-
-                    // Set the encoding scheme in the message context
-                    msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
-                                           MessageContext.DEFAULT_CHAR_SET_ENCODING);
-
-                } else {
-                    // get the type of char encoding
-                    String charSetEnc = TransportUtils.getCharSetEncoding(contentType);
-                    xmlreader = StAXUtils.createXMLStreamReader(in, charSetEnc);
-
-                    // Setting the value in msgCtx
-                    msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
-                }
-
-                if (contentType.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
-                    // it is SOAP 1.2
-                    builder = new StAXSOAPModelBuilder(xmlreader,
-                                                       SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-                    envelope = (SOAPEnvelope) builder.getDocumentElement();
-                } else if (contentType.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
-                    // SOAP 1.1
-                    builder =  new StAXSOAPModelBuilder(xmlreader,
-                                                        SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-                    envelope = (SOAPEnvelope) builder.getDocumentElement();
-                }
-            }
-        }
-
-        if (builder == null) {
-            XMLStreamReader xmlreader = StAXUtils.createXMLStreamReader(in,
-                                                                        MessageContext.DEFAULT_CHAR_SET_ENCODING);
+            builder = Builder.getAttachmentsBuilder(
+                    msgContext, in, contentType, true);
+            envelope = (SOAPEnvelope) builder.getDocumentElement();
+        } else {
+            String charSetEnc = Builder.getCharSetEncoding(contentType);
+            String soapNS = Builder.getEnvelopeNamespace(contentType);
+            builder = Builder.getBuilder(in, charSetEnc, soapNS);
 
             // Set the encoding scheme in the message context
-            msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
-                                   MessageContext.DEFAULT_CHAR_SET_ENCODING);
-            builder = new StAXSOAPModelBuilder(
-                xmlreader, SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-            envelope = (SOAPEnvelope) builder.getDocumentElement();
+            msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
         }
+        envelope = (SOAPEnvelope) builder.getDocumentElement();
 
         String charEncOfMessage = builder.getDocument().getCharsetEncoding();
         String charEncOfTransport = ((String) msgContext.getProperty(

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/local/LocalTransportReceiver.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/local/LocalTransportReceiver.java?view=diff&rev=486906&r1=486905&r2=486906
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/local/LocalTransportReceiver.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/local/LocalTransportReceiver.java Wed Dec 13 16:29:24 2006
@@ -17,10 +17,8 @@
 
 package org.apache.axis2.transport.local;
 
-import org.apache.axiom.om.impl.builder.StAXBuilder;
-import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
 import org.apache.axis2.addressing.EndpointReference;
@@ -29,13 +27,11 @@
 import org.apache.axis2.description.TransportInDescription;
 import org.apache.axis2.description.TransportOutDescription;
 import org.apache.axis2.engine.AxisEngine;
+import org.apache.axis2.util.Builder;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.FactoryConfigurationError;
-import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import java.io.BufferedReader;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 
@@ -71,9 +67,8 @@
             msgCtx.setServerSide(true);
             msgCtx.setProperty(MessageContext.TRANSPORT_OUT, sender.getResponse());
 
-            XMLStreamReader reader = StAXUtils.createXMLStreamReader(
-                    new BufferedReader(new InputStreamReader(in)));
-            StAXBuilder builder = new StAXSOAPModelBuilder(reader, null);
+            InputStreamReader streamReader = new InputStreamReader(in);
+            OMXMLParserWrapper builder = Builder.getBuilder(streamReader);
             SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
 
             msgCtx.setEnvelope(envelope);

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java?view=diff&rev=486906&r1=486905&r2=486906
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java Wed Dec 13 16:29:24 2006
@@ -21,12 +21,10 @@
 import edu.emory.mathcs.backport.java.util.concurrent.LinkedBlockingQueue;
 import edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor;
 import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
-import org.apache.axiom.om.impl.builder.StAXBuilder;
-import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.soap.SOAP11Constants;
 import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
 import org.apache.axis2.addressing.EndpointReference;
@@ -38,19 +36,24 @@
 import org.apache.axis2.description.TransportOutDescription;
 import org.apache.axis2.i18n.Messages;
 import org.apache.axis2.transport.TransportListener;
-import org.apache.axis2.transport.TransportUtils;
+import org.apache.axis2.util.Builder;
 import org.apache.axis2.util.Utils;
 import org.apache.axis2.util.threadpool.DefaultThreadFactory;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import javax.mail.*;
+import javax.mail.Flags;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Multipart;
+import javax.mail.Part;
+import javax.mail.URLName;
 import javax.mail.internet.MimeMessage;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.Properties;
@@ -294,10 +297,10 @@
                         String soapNamespaceURI = "";
 
                         /* Set the Charactorset Encoding */
-                        if (TransportUtils.getCharSetEncoding(part.getContentType()) != null) {
+                        if (Builder.getCharSetEncoding(part.getContentType()) != null) {
                             msgContext.setProperty(
                                     org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING,
-                                    TransportUtils.getCharSetEncoding(
+                                    Builder.getCharSetEncoding(
                                             part.getContentType()));
                         } else {
                             msgContext.setProperty(
@@ -319,9 +322,6 @@
                             msgContext.setTo(new EndpointReference(contentDescription));
                         }
 
-                        XMLStreamReader reader =
-                                StAXUtils.createXMLStreamReader(part.getInputStream());
-
                         if (part.getContentType().indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE)
                             > -1) {
                             soapNamespaceURI = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI;
@@ -356,7 +356,8 @@
                                     "MailWorker found a message other than text/xml or application/soap+xml");
                         }
 
-                        StAXBuilder builder = new StAXSOAPModelBuilder(reader, soapNamespaceURI);
+                        InputStream inputStream = part.getInputStream();
+                        OMXMLParserWrapper builder = Builder.getBuilder(inputStream, null, soapNamespaceURI);
                         SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
                         msgContext.setEnvelope(envelope);
                     }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/server/MailSorter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/server/MailSorter.java?view=diff&rev=486906&r1=486905&r2=486906
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/server/MailSorter.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/server/MailSorter.java Wed Dec 13 16:29:24 2006
@@ -17,18 +17,17 @@
 package org.apache.axis2.transport.mail.server;
 
 import org.apache.axiom.om.impl.builder.StAXBuilder;
-import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axiom.soap.SOAP11Constants;
 import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
 import org.apache.axis2.AxisFault;
-import org.apache.axis2.transport.mail.Constants;
-import org.apache.axis2.util.MessageContextBuilder;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.engine.AxisEngine;
+import org.apache.axis2.transport.mail.Constants;
+import org.apache.axis2.util.Builder;
+import org.apache.axis2.util.MessageContextBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -36,7 +35,6 @@
 import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeMessage;
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamReader;
 import java.io.ByteArrayInputStream;
 import java.util.ArrayList;
 
@@ -116,8 +114,6 @@
             log.info("message[" + message + "]");
 
             ByteArrayInputStream bais = new ByteArrayInputStream(message.getBytes());
-            XMLStreamReader reader =
-                    StAXUtils.createXMLStreamReader(bais);
             String soapNamespaceURI = "";
 
             if (mimeMessage.getContentType().indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
@@ -127,7 +123,8 @@
                 soapNamespaceURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
             }
 
-            StAXBuilder builder = new StAXSOAPModelBuilder(reader, soapNamespaceURI);
+            StAXBuilder builder = Builder.getBuilder(bais, null, soapNamespaceURI);
+
             SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
 
             msgContext.setEnvelope(envelope);

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/tcp/TCPWorker.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/tcp/TCPWorker.java?view=diff&rev=486906&r1=486905&r2=486906
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/tcp/TCPWorker.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/tcp/TCPWorker.java Wed Dec 13 16:29:24 2006
@@ -17,10 +17,8 @@
 
 package org.apache.axis2.transport.tcp;
 
-import org.apache.axiom.om.impl.builder.StAXBuilder;
-import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
 import org.apache.axis2.context.ConfigurationContext;
@@ -30,12 +28,12 @@
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.engine.AxisEngine;
 import org.apache.axis2.i18n.Messages;
+import org.apache.axis2.util.Builder;
 import org.apache.axis2.util.MessageContextBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
@@ -82,8 +80,7 @@
 
                 // create the SOAP Envelope
                 Reader in = new InputStreamReader(socket.getInputStream());
-                XMLStreamReader xmlreader = StAXUtils.createXMLStreamReader(in);
-                StAXBuilder builder = new StAXSOAPModelBuilder(xmlreader, null);
+                OMXMLParserWrapper builder = Builder.getBuilder(in);
                 SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
 
                 msgContext.setEnvelope(envelope);

Added: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Builder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Builder.java?view=auto&rev=486906
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Builder.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Builder.java Wed Dec 13 16:29:24 2006
@@ -0,0 +1,318 @@
+package org.apache.axis2.util;
+
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.builder.StAXBuilder;
+import org.apache.axiom.om.impl.builder.XOPAwareStAXOMBuilder;
+import org.apache.axiom.om.impl.MTOMConstants;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.attachments.Attachments;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.impl.builder.MTOMStAXSOAPModelBuilder;
+import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
+import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.Constants;
+import org.apache.axis2.description.Parameter;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.parsers.FactoryConfigurationError;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.PushbackInputStream;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+public class Builder {
+    public static final int BOM_SIZE = 4;
+
+    public static StAXBuilder getPOXBuilder(InputStream inStream, String charSetEnc, String soapNamespaceURI) throws XMLStreamException {
+        StAXBuilder builder;
+        SOAPEnvelope envelope;
+        XMLStreamReader xmlreader =
+                StAXUtils.createXMLStreamReader(inStream, charSetEnc);
+        SOAPFactory soapFactory = new SOAP11Factory();
+
+        builder = new StAXOMBuilder(xmlreader);
+        builder.setOMBuilderFactory(soapFactory);
+        envelope = soapFactory.getDefaultEnvelope();
+        envelope.getBody().addChild(builder.getDocumentElement());
+
+        // We now have the message inside an envolope. However, this is
+        // only an OM; We need to build a SOAP model from it.
+
+        builder = new StAXSOAPModelBuilder(envelope.getXMLStreamReader(), soapNamespaceURI);
+        return builder;
+    }
+
+    /**
+	 * Use the BOM Mark to identify the encoding to be used. Fall back to
+	 * default encoding specified
+	 *
+	 * @param is
+	 * @param charSetEncoding
+	 * @throws java.io.IOException
+	 */
+    public static Reader getReader(InputStream is, String charSetEncoding) throws IOException {
+        PushbackInputStream is2 = new PushbackInputStream(is, BOM_SIZE);
+        String encoding;
+        byte bom[] = new byte[BOM_SIZE];
+        int n, unread;
+
+        n = is2.read(bom, 0, bom.length);
+
+        if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF)) {
+            encoding = "UTF-8";
+            unread = n - 3;
+        } else if ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) {
+            encoding = "UTF-16BE";
+            unread = n - 2;
+        } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)) {
+            encoding = "UTF-16LE";
+            unread = n - 2;
+        } else if ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00) && (bom[2] == (byte) 0xFE)
+                && (bom[3] == (byte) 0xFF)) {
+            encoding = "UTF-32BE";
+            unread = n - 4;
+        } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE) && (bom[2] == (byte) 0x00)
+                && (bom[3] == (byte) 0x00)) {
+            encoding = "UTF-32LE";
+            unread = n - 4;
+        } else {
+
+            // Unicode BOM mark not found, unread all bytes
+            encoding = charSetEncoding;
+            unread = n;
+        }
+
+        if (unread > 0) {
+            is2.unread(bom, (n - unread), unread);
+        }
+
+        return new BufferedReader(new InputStreamReader(is2, encoding));
+    }
+
+
+    public static String getEnvelopeNamespace(String contentType) {
+        String soapNS = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
+        if(contentType != null) {
+            if (contentType.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
+                // it is SOAP 1.2
+                soapNS = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI;
+            } else if (contentType.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
+                // SOAP 1.1
+                soapNS = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
+            }
+        }
+        return soapNS;
+    }
+
+    /**
+     * Extracts and returns the character set encoding from the
+     * Content-type header
+     * Example:
+     * Content-Type: text/xml; charset=utf-8
+     *
+     * @param contentType
+     */
+    public static String getCharSetEncoding(String contentType) {
+        if (contentType == null) {
+            // Using the default UTF-8
+            return MessageContext.DEFAULT_CHAR_SET_ENCODING;
+        }
+
+        int index = contentType.indexOf(HTTPConstants.CHAR_SET_ENCODING);
+
+        if (index == -1) {    // Charset encoding not found in the content-type header
+            // Using the default UTF-8
+            return MessageContext.DEFAULT_CHAR_SET_ENCODING;
+        }
+
+        // If there are spaces around the '=' sign
+        int indexOfEq = contentType.indexOf("=", index);
+
+        // There can be situations where "charset" is not the last parameter of the Content-Type header
+        int indexOfSemiColon = contentType.indexOf(";", indexOfEq);
+        String value;
+
+        if (indexOfSemiColon > 0) {
+            value = (contentType.substring(indexOfEq + 1, indexOfSemiColon));
+        } else {
+            value = (contentType.substring(indexOfEq + 1, contentType.length())).trim();
+        }
+
+        // There might be "" around the value - if so remove them
+        if(value.indexOf('\"')!=-1){
+            value = value.replaceAll("\"", "");
+        }
+
+        return value.trim();
+    }
+
+    public static StAXBuilder getAttachmentsBuilder(MessageContext msgContext,
+			InputStream inStream, String contentTypeString, boolean isSOAP)
+			throws OMException, XMLStreamException, FactoryConfigurationError {
+		StAXBuilder builder = null;
+
+		Object cacheAttachmentProperty = msgContext
+				.getProperty(Constants.Configuration.CACHE_ATTACHMENTS);
+		String cacheAttachmentString = null;
+		boolean fileCacheForAttachments;
+
+		if (cacheAttachmentProperty != null
+				&& cacheAttachmentProperty instanceof String) {
+			cacheAttachmentString = (String) cacheAttachmentProperty;
+			fileCacheForAttachments = (Constants.VALUE_TRUE
+					.equals(cacheAttachmentString));
+		} else {
+			Parameter parameter_cache_attachment = msgContext
+					.getParameter(Constants.Configuration.CACHE_ATTACHMENTS);
+			cacheAttachmentString = (parameter_cache_attachment != null) ? (String) parameter_cache_attachment
+					.getValue()
+					: null;
+		}
+		fileCacheForAttachments = (Constants.VALUE_TRUE
+				.equals(cacheAttachmentString));
+
+		String attachmentRepoDir = null;
+		String attachmentSizeThreshold = null;
+
+		if (fileCacheForAttachments) {
+			Object attachmentRepoDirProperty = msgContext
+					.getProperty(Constants.Configuration.ATTACHMENT_TEMP_DIR);
+
+			if (attachmentRepoDirProperty != null) {
+				attachmentRepoDir = (String) attachmentRepoDirProperty;
+			} else {
+				Parameter attachmentRepoDirParameter = msgContext
+						.getParameter(Constants.Configuration.ATTACHMENT_TEMP_DIR);
+				attachmentRepoDir = (attachmentRepoDirParameter != null) ? (String) attachmentRepoDirParameter
+						.getValue()
+						: null;
+			}
+
+			Object attachmentSizeThresholdProperty = msgContext
+					.getProperty(Constants.Configuration.FILE_SIZE_THRESHOLD);
+			if (attachmentSizeThresholdProperty != null
+					&& attachmentSizeThresholdProperty instanceof String) {
+				attachmentSizeThreshold = (String) attachmentSizeThresholdProperty;
+			} else {
+				Parameter attachmentSizeThresholdParameter = msgContext
+						.getParameter(Constants.Configuration.FILE_SIZE_THRESHOLD);
+				attachmentSizeThreshold = attachmentSizeThresholdParameter
+						.getValue().toString();
+			}
+		}
+
+		Attachments attachments = new Attachments(inStream, contentTypeString,
+				fileCacheForAttachments, attachmentRepoDir,
+				attachmentSizeThreshold);
+		String charSetEncoding = getCharSetEncoding(attachments
+				.getSOAPPartContentType());
+		XMLStreamReader streamReader;
+
+		if ((charSetEncoding == null)
+				|| "null".equalsIgnoreCase(charSetEncoding)) {
+			charSetEncoding = MessageContext.UTF_8;
+		}
+
+		try {
+			streamReader = StAXUtils.createXMLStreamReader(getReader(
+					attachments.getSOAPPartInputStream(), charSetEncoding));
+		} catch (IOException e) {
+			throw new XMLStreamException(e);
+		}
+
+		msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
+				charSetEncoding);
+
+		/*
+		 * Put a reference to Attachments Map in to the message context For
+		 * backword compatibility with Axis2 1.0
+		 */
+		msgContext.setProperty(MTOMConstants.ATTACHMENTS, attachments);
+
+		/*
+		 * Setting the Attachments map to new SwA API
+		 */
+		msgContext.setAttachmentMap(attachments);
+
+		String soapEnvelopeNamespaceURI = null;
+		if (contentTypeString.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
+			soapEnvelopeNamespaceURI = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI;
+		} else if (contentTypeString
+				.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
+			soapEnvelopeNamespaceURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
+		}
+
+		if (isSOAP) {
+			if (attachments.getAttachmentSpecType().equals(
+					MTOMConstants.MTOM_TYPE)
+					& null != soapEnvelopeNamespaceURI) {
+
+				/*
+				 * Creates the MTOM specific MTOMStAXSOAPModelBuilder
+				 */
+				builder = new MTOMStAXSOAPModelBuilder(streamReader,
+						attachments, soapEnvelopeNamespaceURI);
+
+			} else if (attachments.getAttachmentSpecType().equals(
+					MTOMConstants.SWA_TYPE)
+					& null != soapEnvelopeNamespaceURI) {
+				builder = new StAXSOAPModelBuilder(streamReader,
+						soapEnvelopeNamespaceURI);
+			}
+		}
+		// To handle REST XOP case
+		else {
+			if (attachments.getAttachmentSpecType().equals(
+					MTOMConstants.MTOM_TYPE)) {
+				XOPAwareStAXOMBuilder stAXOMBuilder = new XOPAwareStAXOMBuilder(
+						streamReader, attachments);
+				builder = stAXOMBuilder;
+
+			} else if (attachments.getAttachmentSpecType().equals(
+					MTOMConstants.SWA_TYPE)) {
+				builder = new StAXOMBuilder(streamReader);
+			}
+		}
+
+		return builder;
+	}
+
+    public static StAXBuilder getBuilder(Reader in) throws XMLStreamException {
+        XMLStreamReader xmlreader = StAXUtils.createXMLStreamReader(in);
+        StAXBuilder builder = new StAXSOAPModelBuilder(xmlreader, null);
+        return builder;
+    }
+
+    public static StAXBuilder getBuilder(InputStream inStream, String charSetEnc, String soapNamespaceURI) throws XMLStreamException {
+        StAXBuilder builder;
+        XMLStreamReader xmlreader;
+        if(charSetEnc == null) {
+            xmlreader = StAXUtils.createXMLStreamReader(inStream);
+        } else {
+            xmlreader = StAXUtils.createXMLStreamReader(inStream, charSetEnc);
+        }
+        if(soapNamespaceURI == null) {
+            builder = new StAXOMBuilder(xmlreader);
+        } else {
+            builder = new StAXSOAPModelBuilder(xmlreader, soapNamespaceURI);
+        }
+        return builder;
+    }
+
+    public static StAXBuilder getBuilder(SOAPFactory soapFactory, InputStream in, String charSetEnc) throws XMLStreamException {
+        StAXBuilder builder;
+        XMLStreamReader xmlreader = StAXUtils.createXMLStreamReader(in, charSetEnc);
+        builder = new StAXOMBuilder(soapFactory, xmlreader);
+        return builder;
+    }
+}



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


Mime
View raw message