Author: veithen Date: Sun Aug 4 09:53:19 2013 New Revision: 1510122 URL: http://svn.apache.org/r1510122 Log: Eliminated the dependency between the SAAJ implementation and JavaMail.
Modified: axis/axis2/java/core/trunk/modules/jaxws/pom.xml axis/axis2/java/core/trunk/modules/saaj/pom.xml axis/axis2/java/core/trunk/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java axis/axis2/java/core/trunk/modules/saaj/src/org/apache/axis2/saaj/SOAPPartImpl.java axis/axis2/java/core/trunk/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java Modified: axis/axis2/java/core/trunk/modules/jaxws/pom.xml URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/pom.xml?rev=1510122&r1=1510121&r2=1510122&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/jaxws/pom.xml (original) +++ axis/axis2/java/core/trunk/modules/jaxws/pom.xml Sun Aug 4 09:53:19 2013 @@ -54,6 +54,10 @@ <version>${project.version}</version> </dependency> <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-javamail_1.4_spec</artifactId> + </dependency> + <dependency> <groupId>xml-resolver</groupId> <artifactId>xml-resolver</artifactId> </dependency> Modified: axis/axis2/java/core/trunk/modules/saaj/pom.xml URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/saaj/pom.xml?rev=1510122&r1=1510121&r2=1510122&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/saaj/pom.xml (original) +++ axis/axis2/java/core/trunk/modules/saaj/pom.xml Sun Aug 4 09:53:19 2013 @@ -42,10 +42,6 @@ <artifactId>geronimo-saaj_1.3_spec</artifactId> </dependency> <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-javamail_1.4_spec</artifactId> - </dependency> - <dependency> <groupId>org.apache.ws.commons.axiom</groupId> <artifactId>axiom-dom</artifactId> <scope>runtime</scope> Modified: axis/axis2/java/core/trunk/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java?rev=1510122&r1=1510121&r2=1510122&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java (original) +++ axis/axis2/java/core/trunk/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java Sun Aug 4 09:53:19 2013 @@ -20,19 +20,18 @@ package org.apache.axis2.saaj; import org.apache.axiom.attachments.Attachments; +import org.apache.axiom.mime.ContentTypeBuilder; +import org.apache.axiom.mime.MediaType; import org.apache.axiom.om.OMException; import org.apache.axiom.om.OMOutputFormat; import org.apache.axiom.om.impl.OMMultipartWriter; import org.apache.axiom.soap.SOAP11Version; -import org.apache.axiom.soap.SOAP12Version; import org.apache.axiom.soap.SOAPEnvelope; import org.apache.axiom.soap.SOAPFactory; import org.apache.axiom.util.UIDGenerator; import org.apache.axis2.saaj.util.SAAJUtil; import org.apache.axis2.transport.http.HTTPConstants; -import javax.mail.internet.ContentType; -import javax.mail.internet.ParseException; import javax.xml.soap.AttachmentPart; import javax.xml.soap.MimeHeader; import javax.xml.soap.MimeHeaders; @@ -46,6 +45,7 @@ import javax.xml.soap.SOAPPart; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.text.ParseException; import java.util.ArrayList; import java.util.Collection; import java.util.Hashtable; @@ -63,12 +63,7 @@ public class SOAPMessageImpl extends SOA public SOAPMessageImpl(SOAPEnvelopeImpl soapEnvelope) { this.mimeHeaders = new MimeHeaders(); - if (((SOAPFactory)soapEnvelope.omTarget.getOMFactory()).getSOAPVersion() == SOAP11Version.getSingleton()) { - this.mimeHeaders.addHeader("content-type", HTTPConstants.MEDIA_TYPE_TEXT_XML); - } else if (((SOAPFactory)soapEnvelope.omTarget.getOMFactory()).getSOAPVersion() == SOAP12Version.getSingleton()) { - this.mimeHeaders.addHeader("content-type", - HTTPConstants.MEDIA_TYPE_APPLICATION_SOAP_XML); - } + this.mimeHeaders.addHeader("content-type", ((SOAPFactory)soapEnvelope.omTarget.getOMFactory()).getSOAPVersion().getMediaType().toString()); soapPart = new SOAPPartImpl(this, soapEnvelope); } @@ -275,23 +270,20 @@ public class SOAPMessageImpl extends SOA public void saveChanges() throws SOAPException { try { String contentTypeValue = getSingleHeaderValue(HTTPConstants.HEADER_CONTENT_TYPE); - ContentType contentType = null; + ContentTypeBuilder contentType; if (isEmptyString(contentTypeValue)) { - if (attachmentParts.size() > 0) { - contentTypeValue = HTTPConstants.MEDIA_TYPE_MULTIPART_RELATED; - } else { - contentTypeValue = getBaseType(); + contentType = new ContentTypeBuilder(attachmentParts.size() > 0 ? MediaType.MULTIPART_RELATED : getMediaType()); + } else { + contentType = new ContentTypeBuilder(contentTypeValue); + //Use configures the baseType with multipart/related while no attachment exists or all the attachments are removed + if (contentType.getMediaType().equals(MediaType.MULTIPART_RELATED) && attachmentParts.size() == 0) { + contentType.setMediaType(getMediaType()); + contentType.clearParameters(); } } - contentType = new ContentType(contentTypeValue); - - //Use configures the baseType with multipart/related while no attachment exists or all the attachments are removed - if(contentType.getBaseType().equals(HTTPConstants.MEDIA_TYPE_MULTIPART_RELATED) && attachmentParts.size() == 0) { - contentType = new ContentType(getBaseType()); - } //If it is of multipart/related, initialize those required values in the content-type, including boundary etc. - if (contentType.getBaseType().equals(HTTPConstants.MEDIA_TYPE_MULTIPART_RELATED)) { + if (contentType.getMediaType().equals(MediaType.MULTIPART_RELATED)) { //Configure boundary String boundaryParam = contentType.getParameter("boundary"); @@ -315,15 +307,15 @@ public class SOAPMessageImpl extends SOA } //Configure type - contentType.setParameter("type", getBaseType()); + contentType.setParameter("type", getMediaType().toString()); //Configure charset String soapPartContentTypeValue = getSingleHeaderValue(soapPart.getMimeHeader(HTTPConstants.HEADER_CONTENT_TYPE)); - ContentType soapPartContentType = null; + ContentTypeBuilder soapPartContentType = null; if (isEmptyString(soapPartContentTypeValue)) { - soapPartContentType = new ContentType(soapPartContentTypeValue); + soapPartContentType = new ContentTypeBuilder(soapPartContentTypeValue); } else { - soapPartContentType = new ContentType(getBaseType()); + soapPartContentType = new ContentTypeBuilder(getMediaType()); } setCharsetParameter(soapPartContentType); } else { @@ -382,7 +374,7 @@ public class SOAPMessageImpl extends SOA if (attachmentParts.isEmpty()) { envelope.serialize(out, format); } else { - ContentType contentType = new ContentType(getSingleHeaderValue(HTTPConstants.HEADER_CONTENT_TYPE)); + ContentTypeBuilder contentType = new ContentTypeBuilder(getSingleHeaderValue(HTTPConstants.HEADER_CONTENT_TYPE)); String boundary = contentType.getParameter("boundary"); if(isEmptyString(boundary)) { boundary = UIDGenerator.generateMimeBoundary(); @@ -612,9 +604,8 @@ public class SOAPMessageImpl extends SOA } } - private String getBaseType() throws SOAPException { - boolean isSOAP12 = ((SOAPFactory)((SOAPEnvelopeImpl) soapPart.getEnvelope()).omTarget.getOMFactory()).getSOAPVersion() == SOAP12Version.getSingleton(); - return isSOAP12 ? HTTPConstants.MEDIA_TYPE_APPLICATION_SOAP_XML : HTTPConstants.MEDIA_TYPE_TEXT_XML; + private MediaType getMediaType() throws SOAPException { + return ((SOAPFactory)((SOAPEnvelopeImpl) soapPart.getEnvelope()).omTarget.getOMFactory()).getSOAPVersion().getMediaType(); } /** @@ -624,7 +615,7 @@ public class SOAPMessageImpl extends SOA * @param contentType * @throws SOAPException */ - private void setCharsetParameter(ContentType contentType) throws SOAPException{ + private void setCharsetParameter(ContentTypeBuilder contentType) throws SOAPException{ String charset = (String)getProperty(CHARACTER_SET_ENCODING); if (!isEmptyString(charset)) { contentType.setParameter("charset", charset); Modified: axis/axis2/java/core/trunk/modules/saaj/src/org/apache/axis2/saaj/SOAPPartImpl.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/saaj/src/org/apache/axis2/saaj/SOAPPartImpl.java?rev=1510122&r1=1510121&r2=1510122&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/saaj/src/org/apache/axis2/saaj/SOAPPartImpl.java (original) +++ axis/axis2/java/core/trunk/modules/saaj/src/org/apache/axis2/saaj/SOAPPartImpl.java Sun Aug 4 09:53:19 2013 @@ -20,6 +20,8 @@ package org.apache.axis2.saaj; import org.apache.axiom.attachments.Attachments; +import org.apache.axiom.mime.ContentType; +import org.apache.axiom.mime.MediaType; import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMMetaFactory; import org.apache.axiom.om.impl.MTOMConstants; @@ -52,8 +54,6 @@ import org.w3c.dom.ProcessingInstruction import org.w3c.dom.Text; import org.w3c.dom.UserDataHandler; -import javax.mail.internet.ContentType; -import javax.mail.internet.ParseException; import javax.xml.soap.MimeHeaders; import javax.xml.soap.SOAPElement; import javax.xml.soap.SOAPEnvelope; @@ -71,9 +71,11 @@ import javax.xml.transform.TransformerFa import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; +import java.text.ParseException; import java.util.Iterator; public class SOAPPartImpl extends SOAPPart { @@ -146,25 +148,29 @@ public class SOAPPartImpl extends SOAPPa soapFactory = metaFactory.getSOAP11Factory(); soapEnvelopeNamespaceURI = null; } else { - String baseType = contentType.getBaseType().toLowerCase(); - String soapContentType; - if (baseType.equals(MTOMConstants.MTOM_TYPE)) { + MediaType baseType = contentType.getMediaType(); + MediaType soapContentType; + if (baseType.equals(MediaType.APPLICATION_XOP_XML)) { isMTOM = true; String typeParam = contentType.getParameter("type"); if (typeParam == null) { throw new SOAPException("Missing 'type' parameter in XOP content type"); } else { - soapContentType = typeParam.toLowerCase(); + try { + soapContentType = new ContentType(typeParam).getMediaType(); + } catch (ParseException ex) { + throw new SOAPException("Failed to parse the 'type' parameter", ex); + } } } else { isMTOM = false; soapContentType = baseType; } - if (soapContentType.equals(HTTPConstants.MEDIA_TYPE_TEXT_XML)) { + if (soapContentType.equals(MediaType.TEXT_XML)) { soapEnvelopeNamespaceURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI; soapFactory = metaFactory.getSOAP11Factory(); - } else if (soapContentType.equals(HTTPConstants.MEDIA_TYPE_APPLICATION_SOAP_XML)) { + } else if (soapContentType.equals(MediaType.APPLICATION_SOAP_XML)) { soapEnvelopeNamespaceURI = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI; soapFactory = metaFactory.getSOAP12Factory(); } else { Modified: axis/axis2/java/core/trunk/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java?rev=1510122&r1=1510121&r2=1510122&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java (original) +++ axis/axis2/java/core/trunk/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java Sun Aug 4 09:53:19 2013 @@ -20,6 +20,9 @@ package org.apache.axis2.saaj; import junit.framework.Assert; + +import org.apache.axiom.mime.ContentType; +import org.apache.axiom.mime.MediaType; import org.apache.axis2.saaj.util.SAAJDataSource; import org.apache.axis2.transport.http.HTTPConstants; import org.junit.Before; @@ -27,7 +30,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import javax.activation.DataHandler; -import javax.mail.internet.ContentType; import javax.xml.namespace.QName; import javax.xml.soap.AttachmentPart; import javax.xml.soap.MessageFactory; @@ -46,6 +48,7 @@ import javax.xml.soap.SOAPHeaderElement; import javax.xml.soap.SOAPMessage; import javax.xml.soap.SOAPPart; import javax.xml.transform.stream.StreamSource; + import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -247,7 +250,7 @@ public class SOAPMessageTest extends Ass //start parameter is not checked, due to it is optional parameter, and seems RI will not add this value //assertNotNull("start parameter should exist in the content-type header", contentType.getParameter("start")); assertNotNull("type parameter should exist in the content-type header", contentType.getParameter("type")); - assertEquals(HTTPConstants.MEDIA_TYPE_MULTIPART_RELATED, contentType.getBaseType()); + assertEquals(MediaType.MULTIPART_RELATED, contentType.getMediaType()); } @Validated @Test @@ -266,7 +269,7 @@ public class SOAPMessageTest extends Ass msg2.saveChanges(); ContentType contentType2 = new ContentType(msg2.getMimeHeaders().getHeader(HTTPConstants.HEADER_CONTENT_TYPE)[0]); - assertEquals(contentType.getBaseType(), contentType2.getBaseType()); + assertEquals(contentType.getMediaType(), contentType2.getMediaType()); assertEquals(contentType.getParameter("boundary"), contentType2.getParameter("boundary")); assertEquals(contentType.getParameter("type"), contentType2.getParameter("type")); //start parameter is not checked, due to it is an optional parameter, and seems RI will not add this value @@ -284,14 +287,14 @@ public class SOAPMessageTest extends Ass assertNotNull(msg.getMimeHeaders().getHeader(HTTPConstants.HEADER_CONTENT_TYPE)); ContentType contentType = new ContentType(msg.getMimeHeaders().getHeader(HTTPConstants.HEADER_CONTENT_TYPE)[0]); - assertEquals(HTTPConstants.MEDIA_TYPE_MULTIPART_RELATED, contentType.getBaseType()); + assertEquals(MediaType.MULTIPART_RELATED, contentType.getMediaType()); msg.removeAllAttachments(); msg.saveChanges(); assertNotNull(msg.getMimeHeaders().getHeader(HTTPConstants.HEADER_CONTENT_TYPE)); contentType = new ContentType(msg.getMimeHeaders().getHeader(HTTPConstants.HEADER_CONTENT_TYPE)[0]); - assertEquals("text/xml", contentType.getBaseType()); + assertEquals(MediaType.TEXT_XML, contentType.getMediaType()); } private StringBuffer copyToBuffer(InputStream inputStream) {