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 th...@apache.org on 2006/12/19 14:39:02 UTC

svn commit: r488675 - in /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2: Constants.java transport/TransportUtils.java transport/http/HTTPTransportUtils.java util/Builder.java

Author: thilina
Date: Tue Dec 19 05:39:02 2006
New Revision: 488675

URL: http://svn.apache.org/viewvc?view=rev&rev=488675
Log:
1. Further refactoring the builder creation logic.. 
Axis2 has been using two seperate builder creation logics for the server side receiving and in receiving a response message.. This commit unifies those two logics..
TransportUtils can now be used as a generic builder creation logic for any transport.. 

2. Initial code drop for the builder selector implementation 
3. Cleaned up some code duplicates


Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.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/util/Builder.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java?view=diff&rev=488675&r1=488674&r2=488675
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java Tue Dec 19 05:39:02 2006
@@ -219,6 +219,12 @@
     public static final String ADDRESSING_ACTION = "WS-Addressing:Action";
     public static final String HTTP_FRONTEND_HOST_URL = "httpFrontendHostUrl";
     public static final String DEFAULT_REST_PATH = "rest";
+    
+    /**
+     * Field Builder Selector
+     */
+    public static final String BUILDER_SELECTOR = "builderselector";
+
 
     public static interface Configuration {
         public static final String ENABLE_REST = "enableREST";

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=488675&r1=488674&r2=488675
==============================================================================
--- 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 Tue Dec 19 05:39:02 2006
@@ -17,8 +17,21 @@
 
 package org.apache.axis2.transport;
 
+import java.io.InputStream;
+
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.builder.StAXBuilder;
+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.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;
@@ -27,64 +40,136 @@
 import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.axis2.util.Builder;
 
-import java.io.InputStream;
-
 public class TransportUtils {
 
-    public static SOAPEnvelope createSOAPMessage(MessageContext msgContext, String soapNamespaceURI)
-            throws AxisFault {
-        InputStream inStream = (InputStream) msgContext.getProperty(MessageContext.TRANSPORT_IN);
-
-        msgContext.setProperty(MessageContext.TRANSPORT_IN, null);
-
-        // this inputstram is set by the TransportSender represents a two way transport or
-        // by a Transport Recevier
-        if (inStream == null) {
-            throw new AxisFault(Messages.getMessage("inputstreamNull"));
-        }
-
-        return createSOAPMessage(msgContext, inStream, soapNamespaceURI);
-    }
-
-    public static SOAPEnvelope createSOAPMessage(MessageContext msgContext, InputStream inStream,
-                                                  String soapNamespaceURI)
-            throws AxisFault {
-        try {
-            Object contentType ;
-            OperationContext opContext = msgContext.getOperationContext();
-
-            if (opContext != null) {
-                contentType = opContext.getProperty(HTTPConstants.MTOM_RECEIVED_CONTENT_TYPE);
-            } else {
-                throw new AxisFault(Messages.getMessage("cannotBeNullOperationContext"));
-            }
-
-            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);
-                OMXMLParserWrapper builder = Builder.getAttachmentsBuilder(msgContext, inStream,
-                        (String) contentType, true);
-                envelope = (SOAPEnvelope) builder.getDocumentElement();
-            } else if (msgContext.isDoingREST()) {
-                OMXMLParserWrapper builder = Builder.getPOXBuilder(inStream, charSetEnc, soapNamespaceURI);
-                envelope = (SOAPEnvelope) builder.getDocumentElement();
+    public static SOAPEnvelope createSOAPMessage(MessageContext msgContext,
+			String soapNamespaceURI) throws AxisFault {
+		try {
+			InputStream inStream = (InputStream) msgContext
+					.getProperty(MessageContext.TRANSPORT_IN);
+
+			msgContext.setProperty(MessageContext.TRANSPORT_IN, null);
+
+			// this inputstram is set by the TransportSender represents a two
+			// way transport or by a Transport Recevier
+			if (inStream == null) {
+				throw new AxisFault(Messages.getMessage("inputstreamNull"));
+			}
+			Object contentType;
+			boolean isMIME = false;
+			OperationContext opContext = msgContext.getOperationContext();
+
+			if (opContext != null) {
+				contentType = opContext
+						.getProperty(HTTPConstants.MTOM_RECEIVED_CONTENT_TYPE);
+			} else {
+				throw new AxisFault(Messages
+						.getMessage("cannotBeNullOperationContext"));
+			}
+			//TODO: we can improve this logic
+			if (contentType!=null){
+				isMIME=true;
+			}
+			
+			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;
+			}
+			return createSOAPMessage(msgContext, inStream, soapNamespaceURI,
+					isMIME, (String) contentType, charSetEnc);
+		} catch (AxisFault e) {
+			throw e;
+		} catch (OMException e) {
+			throw new AxisFault(e);
+		} catch (XMLStreamException e) {
+			throw new AxisFault(e);
+		} catch (FactoryConfigurationError e) {
+			throw new AxisFault(e);
+		}
+	}
+
+    /**
+	 * Objective of this method is to capture the SOAPEnvelope creation logic
+	 * and make it a common for all the transports and to in/out flows.
+	 * 
+	 * @param msgContext
+	 * @param inStream
+	 * @param soapNamespaceURI
+	 * @param isMIME
+	 * @param contentType
+	 * @param charSetEnc
+	 * @return the SOAPEnvelope
+	 * @throws AxisFault
+	 * @throws OMException
+	 * @throws XMLStreamException
+	 * @throws FactoryConfigurationError
+	 */
+    public static SOAPEnvelope createSOAPMessage(MessageContext msgContext,
+			InputStream inStream, String soapNamespaceURI, boolean isMIME,
+			String contentType, String charSetEnc) throws AxisFault,
+			OMException, XMLStreamException, FactoryConfigurationError {
+    	StAXBuilder builder;
+		OMElement documentElement;
+		if (isMIME) {
+			msgContext.setDoingMTOM(true);
+			builder = Builder.getAttachmentsBuilder(
+					msgContext, inStream, (String) contentType, !(msgContext
+							.isDoingREST()));
+		} else if (msgContext.isDoingREST()) {
+			builder = Builder.getPOXBuilder(inStream,
+					charSetEnc, soapNamespaceURI);
+		} else {
+			builder = Builder.getBuilderFromSelector(contentType, msgContext);
+			if (builder == null) {
+				builder = Builder.getBuilder(inStream, charSetEnc,
+						soapNamespaceURI);
+			}
+		}
+		
+		documentElement = builder.getDocumentElement();
+		SOAPEnvelope envelope;
+		//Check whether we have received a SOAPEnvelope or not
+		if (documentElement instanceof SOAPEnvelope) {
+			envelope = (SOAPEnvelope) documentElement;
+		} else {
+			//If it is not a SOAPEnvelope we wrap that with a fake SOAPEnvelope.
+			SOAPFactory soapFactory = new SOAP11Factory();
+			SOAPEnvelope intermediateEnvelope = soapFactory
+					.getDefaultEnvelope();
+			intermediateEnvelope.getBody().addChild(
+					builder.getDocumentElement());
+
+			// We now have the message inside an envelope. However, this is
+			// only an OM; We need to build a SOAP model from it.
+			builder = new StAXSOAPModelBuilder(intermediateEnvelope
+					.getXMLStreamReader(), soapNamespaceURI);
+			envelope = (SOAPEnvelope) builder.getDocumentElement();
+		}
+
+		String charsetEncoding = builder.getDocument().getCharsetEncoding();
+		if ((charsetEncoding != null)
+				&& !"".equals(charsetEncoding)
+				&& (msgContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING) != null)
+				&& !charsetEncoding.equalsIgnoreCase((String) msgContext
+								.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING))) {
+			String faultCode;
+
+            if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(
+                    envelope.getNamespace().getNamespaceURI())) {
+                faultCode = SOAP12Constants.FAULT_CODE_SENDER;
             } else {
-                OMXMLParserWrapper builder = Builder.getBuilder(inStream, charSetEnc, soapNamespaceURI);
-                envelope = (SOAPEnvelope) builder.getDocumentElement();
+                faultCode = SOAP11Constants.FAULT_CODE_SENDER;
             }
 
-            return envelope;
-        } catch (Exception e) {
-            throw new AxisFault(e);
+            throw new AxisFault(
+                    "Character Set Encoding from " + "transport information do not match with "
+                    + "character set encoding in the received SOAP message", faultCode);
         }
-    }
+		return envelope;
+	}
 }

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=488675&r1=488674&r2=488675
==============================================================================
--- 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 Tue Dec 19 05:39:02 2006
@@ -37,6 +37,7 @@
 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;
@@ -139,7 +140,6 @@
         msgContext.setTo(new EndpointReference(requestURI));
         msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
         msgContext.setServerSide(true);
-
         SOAPEnvelope envelope = HTTPTransportUtils.createEnvelopeFromGetRequest(requestURI,
                                                                                 requestParameters, configurationContext);
 
@@ -148,11 +148,8 @@
         } else {
             msgContext.setDoingREST(true);
             msgContext.setEnvelope(envelope);
-
             AxisEngine engine = new AxisEngine(configurationContext);
-
             engine.receive(msgContext);
-
             return true;
         }
     }
@@ -193,7 +190,7 @@
             msgContext.setServerSide(true);
 
             SOAPEnvelope envelope = null;
-            StAXBuilder builder = null;
+            boolean isMIME=false;
 
             // get the type of char encoding
             String charSetEnc = Builder.getCharSetEncoding(contentType);
@@ -205,65 +202,35 @@
 
             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 = Builder.getAttachmentsBuilder(msgContext, in, contentType, true);
-                    envelope = (SOAPEnvelope) builder.getDocumentElement();
-                } 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);
-
-                            SOAPFactory soapFactory = new SOAP11Factory();
-                            envelope = soapFactory.getDefaultEnvelope();
-
-                            builder = Builder.getBuilder(soapFactory, in, charSetEnc);
-                            envelope.getBody().addChild(builder.getDocumentElement());
-                        }
-                    }
-                }
-            }
-
-            if (builder == null) {
-                builder = Builder.getBuilder(in, charSetEnc, soapNS);
-                envelope = (SOAPEnvelope) builder.getDocumentElement();
-            }
-
-            String charsetEncoding = builder.getDocument().getCharsetEncoding();
-
-            if ((charsetEncoding != null) && !"".equals(charsetEncoding)
-                && ! charsetEncoding.equalsIgnoreCase((String) msgContext.getProperty(
-                    Constants.Configuration.CHARACTER_SET_ENCODING))) {
-                String faultCode;
-
-                if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(
-                        envelope.getNamespace().getNamespaceURI())) {
-                    faultCode = SOAP12Constants.FAULT_CODE_SENDER;
-                } else {
-                    faultCode = SOAP11Constants.FAULT_CODE_SENDER;
-                }
-
-                throw new AxisFault(
-                        "Character Set Encoding from " + "transport information do not match with "
-                        + "character set encoding in the received SOAP message", faultCode);
-            }
-
+				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)
+					isMIME = true;
+				} else if (soapVersion == VERSION_SOAP11) {
+					// Deployment configuration parameter
+					Parameter enableREST = msgContext
+							.getParameter(Constants.Configuration.ENABLE_REST);
+					if ((soapActionHeader == null) && (enableREST != null)) {
+						if (Constants.VALUE_TRUE.equals(enableREST.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);
+						}
+					}
+				}
+			}
+            envelope = TransportUtils.createSOAPMessage(msgContext,in,soapNS,isMIME,contentType,charSetEnc);
             msgContext.setEnvelope(envelope);
-
             AxisEngine engine = new AxisEngine(msgContext.getConfigurationContext());
 
             if (envelope.getBody().hasFault()) {
@@ -311,7 +278,6 @@
                         .substring(1, soapAction.length() - 1);
             }
             msgContext.setSoapAction(soapAction);
-
         }
     }
 

Modified: 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=diff&rev=488675&r1=488674&r2=488675
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Builder.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Builder.java Tue Dec 19 05:39:02 2006
@@ -1,34 +1,37 @@
 package org.apache.axis2.util;
 
-import org.apache.axiom.om.OMXMLParserWrapper;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PushbackInputStream;
+import java.io.Reader;
+import java.util.HashMap;
+
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.attachments.Attachments;
+import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+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.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.SOAP12Constants;
 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.AxisFault;
 import org.apache.axis2.Constants;
+import org.apache.axis2.context.MessageContext;
 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;
+import org.apache.axis2.transport.http.HTTPConstants;
 
 public class Builder {
     public static final int BOM_SIZE = 4;
@@ -36,19 +39,11 @@
     public static StAXBuilder getPOXBuilder(InputStream inStream, String charSetEnc, String soapNamespaceURI) throws XMLStreamException {
         StAXBuilder builder;
         SOAPEnvelope envelope;
+        SOAPFactory soapFactory = new SOAP11Factory();
         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;
     }
 
@@ -160,16 +155,17 @@
 			InputStream inStream, String contentTypeString, boolean isSOAP)
 			throws OMException, XMLStreamException, FactoryConfigurationError {
 		StAXBuilder builder = null;
+		XMLStreamReader streamReader;
 
         Attachments attachments = createAttachment(msgContext, inStream, contentTypeString);
 		String charSetEncoding = getCharSetEncoding(attachments.getSOAPPartContentType());
 
-        XMLStreamReader streamReader;
-
 		if ((charSetEncoding == null)
 				|| "null".equalsIgnoreCase(charSetEncoding)) {
 			charSetEncoding = MessageContext.UTF_8;
 		}
+		msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
+				charSetEncoding);
 
 		try {
 			streamReader = StAXUtils.createXMLStreamReader(getReader(
@@ -178,42 +174,25 @@
 			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
-		 */
+		
+		//  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
-		 */
+		// 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;
-		}
+		String soapEnvelopeNamespaceURI = getEnvelopeNamespace(contentTypeString);
 
 		if (isSOAP) {
 			if (attachments.getAttachmentSpecType().equals(
-					MTOMConstants.MTOM_TYPE)
-					& null != soapEnvelopeNamespaceURI) {
-
-				/*
-				 * Creates the MTOM specific MTOMStAXSOAPModelBuilder
-				 */
+					MTOMConstants.MTOM_TYPE)) {
+				//Creates the MTOM specific MTOMStAXSOAPModelBuilder
 				builder = new MTOMStAXSOAPModelBuilder(streamReader,
 						attachments, soapEnvelopeNamespaceURI);
 
 			} else if (attachments.getAttachmentSpecType().equals(
-					MTOMConstants.SWA_TYPE)
-					& null != soapEnvelopeNamespaceURI) {
+					MTOMConstants.SWA_TYPE)) {
 				builder = new StAXSOAPModelBuilder(streamReader,
 						soapEnvelopeNamespaceURI);
 			}
@@ -320,4 +299,40 @@
         builder = new StAXOMBuilder(soapFactory, xmlreader);
         return builder;
     }
+    
+    /**
+     * Initial work for a builder selector which selects the builder for a given message format based on the the content type of the recieved message.
+     * content-type to builder mapping can be specified through the Axis2.xml.
+     * @param contentType
+     * @param msgContext
+     * @return the builder registered against the given content-type
+     * @throws AxisFault
+     */
+    public static StAXBuilder getBuilderFromSelector(String contentType, MessageContext msgContext) throws AxisFault {
+    	HashMap map= (HashMap)msgContext.getConfigurationContext().getProperty(Constants.BUILDER_SELECTOR);
+    	String builderClassName=null;
+    	
+    	if(map!=null)
+    	builderClassName = (String)map.get(contentType);
+  
+    	if (builderClassName==null)
+    	{
+    		//fall back if there aren't any builders registered for this content type
+    		return null;
+    	}
+    	try {
+			Class builderClass = Loader.loadClass(builderClassName);
+			StAXBuilder builder = (StAXBuilder) builderClass.newInstance();
+			builder.setOMBuilderFactory(OMAbstractFactory.getOMFactory());
+			return builder;
+		} catch (ClassNotFoundException e) {
+			throw new AxisFault("Specified Builder class cannot be found.", e);
+		} catch (InstantiationException e) {
+			throw new AxisFault(
+					"Cannot instantiate the specified Builder Class.", e);
+		} catch (IllegalAccessException e) {
+			throw new AxisFault(
+					"Cannot instantiate the specified Builder Class.", e);
+		}
+	}
 }



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