You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2007/03/16 21:20:10 UTC

svn commit: r519126 - /webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPPartImpl.java

Author: dims
Date: Fri Mar 16 13:20:09 2007
New Revision: 519126

URL: http://svn.apache.org/viewvc?view=rev&rev=519126
Log:
Fix for SOAP1.2 + Attachments

Modified:
    webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPPartImpl.java

Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPPartImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPPartImpl.java?view=diff&rev=519126&r1=519125&r2=519126
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPPartImpl.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPPartImpl.java Fri Mar 16 13:20:09 2007
@@ -43,13 +43,18 @@
 import org.apache.axiom.attachments.Attachments;
 import org.apache.axiom.attachments.utils.IOUtils;
 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.soap.SOAP11Constants;
 import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
+import org.apache.axiom.soap.impl.builder.MTOMStAXSOAPModelBuilder;
 import org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory;
 import org.apache.axiom.soap.impl.dom.soap12.SOAP12Factory;
 import org.apache.axis2.saaj.util.IDGenerator;
 import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.builder.BuilderUtil;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.w3c.dom.Attr;
@@ -92,85 +97,130 @@
     }
 
     public SOAPPartImpl(SOAPMessageImpl parentSoapMsg,
-                        InputStream inputStream,javax.xml.soap.MimeHeaders mimeHeaders
-                        ) throws SOAPException {
-    	String contentType = ""; 
-    	String fullContentTypeStr = "";
-    	if(mimeHeaders == null){
-    		//TODO : read string from constants
-    		mimeHeaders = new MimeHeaders();
-    		mimeHeaders.addHeader("Content-ID", IDGenerator.generateID());
-    		mimeHeaders.addHeader("content-type", HTTPConstants.MEDIA_TYPE_APPLICATION_SOAP_XML);
-    	}else{
-    		String contentTypes[] = mimeHeaders.getHeader(HTTPConstants.CONTENT_TYPE);
-    		if(contentTypes != null && contentTypes.length > 0){
-    			fullContentTypeStr = contentTypes[0];
-    			//tmpContentType can be like 'application/soap+xml; charset=UTF-8;'
-    			//Only the first part is important
-    			if(fullContentTypeStr.indexOf(";") > -1){
-    				contentType = fullContentTypeStr.substring(0, fullContentTypeStr.indexOf(";"));    			
-    			}else{
-    				contentType = fullContentTypeStr;
-    			}
-    		}    		
-    	}
-    	
-    	Iterator mimeHeaderIterator = mimeHeaders.getAllHeaders();
-    	while (mimeHeaderIterator.hasNext()) {
-			MimeHeader mimeHeader = (MimeHeader) mimeHeaderIterator.next();
-			String value = mimeHeader.getValue();
-			setMimeHeader(mimeHeader.getName(), value);
-		}
-    	InputStream modifiedInputStream = null;
-    	if(contentType.indexOf("multipart/related") == 0){
-    		//This contains attachements
-        	try {
-                Attachments attachments = new Attachments(inputStream,fullContentTypeStr,false, "","");
-                modifiedInputStream = attachments.getSOAPPartInputStream();
-      		} catch (Exception e) {
-	            throw new SOAPException(e);
-      		}
-    	}else{
-    		modifiedInputStream = inputStream;
-    	}    	
+                        InputStream inputStream, javax.xml.soap.MimeHeaders mimeHeaders
+    ) throws SOAPException {
+        String contentType = "";
+        String fullContentTypeStr = "";
+        if (mimeHeaders == null) {
+            //TODO : read string from constants
+            mimeHeaders = new MimeHeaders();
+            mimeHeaders.addHeader("Content-ID", IDGenerator.generateID());
+            mimeHeaders.addHeader("content-type", HTTPConstants.MEDIA_TYPE_APPLICATION_SOAP_XML);
+        } else {
+            String contentTypes[] = mimeHeaders.getHeader(HTTPConstants.CONTENT_TYPE);
+            if (contentTypes != null && contentTypes.length > 0) {
+                fullContentTypeStr = contentTypes[0];
+                contentType = extractFirstPart(fullContentTypeStr);
+            }
+        }
+
+        Iterator mimeHeaderIterator = mimeHeaders.getAllHeaders();
+        while (mimeHeaderIterator.hasNext()) {
+            MimeHeader mimeHeader = (MimeHeader) mimeHeaderIterator.next();
+            String value = mimeHeader.getValue();
+            setMimeHeader(mimeHeader.getName(), value);
+        }
         soapMessage = parentSoapMsg;
 
-        try {
-            InputStreamReader isReader = new InputStreamReader(modifiedInputStream);
-            StAXSOAPModelBuilder builder = null;
-            
-            if(HTTPConstants.MEDIA_TYPE_TEXT_XML.equals(contentType)){
-                builder = new StAXSOAPModelBuilder(StAXUtils.createXMLStreamReader(isReader),
-                        new SOAP11Factory(),
-                        SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-            	
-            }else if(HTTPConstants.MEDIA_TYPE_APPLICATION_SOAP_XML.equals(contentType)){
-                builder = new StAXSOAPModelBuilder(StAXUtils.createXMLStreamReader(isReader),
-                        new SOAP12Factory(),
-                        SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-            	
-            }else if(HTTPConstants.MEDIA_TYPE_MULTIPART_RELATED.equals(contentType)){
-                builder = new StAXSOAPModelBuilder(StAXUtils.createXMLStreamReader(isReader),
-                        new SOAP11Factory(),
-                        null);            	
-            }else{
-                builder = new StAXSOAPModelBuilder(StAXUtils.createXMLStreamReader(isReader),
-                        new SOAP11Factory(),
-                        null);             	
+        InputStream modifiedInputStream = null;
+        StAXSOAPModelBuilder builder = null;
+        InputStreamReader isReader = null;
+
+        if (contentType.indexOf("multipart/related") == 0) {
+            //This contains attachements
+            try {
+                Attachments attachments = new Attachments(inputStream, fullContentTypeStr, false, "", "");
+                modifiedInputStream = attachments.getSOAPPartInputStream();
+                isReader = new InputStreamReader(modifiedInputStream);
+
+                String soapEnvelopeNamespaceURI = BuilderUtil.getEnvelopeNamespace(fullContentTypeStr);
+
+                String charSetEncoding = BuilderUtil.getCharSetEncoding(attachments.getSOAPPartContentType());
+
+                XMLStreamReader streamReader = StAXUtils.createXMLStreamReader(BuilderUtil.getReader(
+                        attachments.getSOAPPartInputStream(), charSetEncoding));
+
+                SOAPFactory factory;
+                if(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(soapEnvelopeNamespaceURI)){
+                    factory = new SOAP11Factory();
+                } else {
+                    factory = new SOAP12Factory();
+                }
+                if (attachments.getAttachmentSpecType().equals(
+                        MTOMConstants.MTOM_TYPE)) {
+                    //Creates the MTOM specific MTOMStAXSOAPModelBuilder
+                    builder = new MTOMStAXSOAPModelBuilder(streamReader,
+                            factory,
+                            attachments,
+                            soapEnvelopeNamespaceURI);
+                } else if (attachments.getAttachmentSpecType().equals(
+                        MTOMConstants.SWA_TYPE)) {
+                    builder = new StAXSOAPModelBuilder(streamReader,
+                            factory,
+                            soapEnvelopeNamespaceURI);
+                } else if (attachments.getAttachmentSpecType().equals(
+                        MTOMConstants.SWA_TYPE_12)) {
+                    builder = new StAXSOAPModelBuilder(streamReader,
+                            factory,
+                            soapEnvelopeNamespaceURI);
+                }
+
+            } catch (Exception e) {
+                throw new SOAPException(e);
+            }
+        } else {
+            modifiedInputStream = inputStream;
+            try {
+                isReader = new InputStreamReader(modifiedInputStream);
+
+                if (HTTPConstants.MEDIA_TYPE_TEXT_XML.equals(contentType)) {
+                    builder = new StAXSOAPModelBuilder(StAXUtils.createXMLStreamReader(isReader),
+                            new SOAP11Factory(),
+                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+
+                } else if (HTTPConstants.MEDIA_TYPE_APPLICATION_SOAP_XML.equals(contentType)) {
+                    builder = new StAXSOAPModelBuilder(StAXUtils.createXMLStreamReader(isReader),
+                            new SOAP12Factory(),
+                            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+
+                } else if (HTTPConstants.MEDIA_TYPE_MULTIPART_RELATED.equals(contentType)) {
+                    builder = new StAXSOAPModelBuilder(StAXUtils.createXMLStreamReader(isReader),
+                            new SOAP11Factory(),
+                            null);
+                } else {
+                    builder = new StAXSOAPModelBuilder(StAXUtils.createXMLStreamReader(isReader),
+                            new SOAP11Factory(),
+                            null);
+                }
+            } catch (XMLStreamException e) {
+                throw new SOAPException(e);
             }
+        }
+        try {
             org.apache.axiom.soap.SOAPEnvelope soapEnvelope = builder.getSOAPEnvelope();
-            envelope = new SOAPEnvelopeImpl((org.apache.axiom.soap.impl.dom.SOAPEnvelopeImpl)soapEnvelope);
+            envelope = new SOAPEnvelopeImpl((org.apache.axiom.soap.impl.dom.SOAPEnvelopeImpl) soapEnvelope);
             envelope.element.build();
             this.document = envelope.getOwnerDocument();
             javax.xml.transform.Source xmlSource =
-                new javax.xml.transform.stream.StreamSource(isReader);
-            this.source = xmlSource;            
-        } catch (XMLStreamException e) {
+                    new javax.xml.transform.stream.StreamSource(isReader);
+            this.source = xmlSource;
+        } catch (Exception e) {
             throw new SOAPException(e);
         }
     }
 
-    
+    private String extractFirstPart(String fullContentTypeStr) {
+        String contentType;//tmpContentType can be like 'application/soap+xml; charset=UTF-8;'
+        //Only the first part is important
+        if (fullContentTypeStr.indexOf(";") > -1) {
+            contentType = fullContentTypeStr.substring(0, fullContentTypeStr.indexOf(";"));
+        } else {
+            contentType = fullContentTypeStr;
+        }
+        return contentType;
+    }
+
+
     public SOAPPartImpl(SOAPMessageImpl parentSoapMsg,
     		InputStream inputStream) throws SOAPException {
     	this(parentSoapMsg,inputStream,null);



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