Репозиторий Sisyphus
Последнее обновление: 8 апреля 2020 | Пакетов: 17561 | Посещений: 17851300
en ru br
Репозитории ALT
S:1.7.7-alt1_3jpp8
4.1: 1.2-alt0.1jpp
4.0: 1.2-alt0.1jpp
www.altlinux.org/Changes

Группа :: Разработка/Java
Пакет: axis2

 Главная   Изменения   Спек   Патчи   Sources   Загрузить   Gear   Bugs and FR  Repocop 

Патч: axiom-ContentType.patch
Скачать


From b0d3ba3eca3136b5d348652c8d4901183c5ebb1c Mon Sep 17 00:00:00 2001
From: Andreas Veithen <veithen@apache.org>
Date: Thu, 1 Aug 2013 20:10:19 +0000
Subject: [PATCH] Avoid the dependency on JavaMail (which is no longer a
 dependency of Axiom; see AXIOM-418).
diff --git a/modules/kernel/src/org/apache/axis2/builder/DataSourceBuilder.java b/modules/kernel/src/org/apache/axis2/builder/DataSourceBuilder.java
index 47960bc69c..c3ab90bccb 100644
--- a/modules/kernel/src/org/apache/axis2/builder/DataSourceBuilder.java
+++ b/modules/kernel/src/org/apache/axis2/builder/DataSourceBuilder.java
@@ -28,6 +28,7 @@
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
+import org.apache.axiom.attachments.ByteArrayDataSource;
 import org.apache.axiom.attachments.impl.BufferUtils;
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMDataSource;
@@ -60,7 +61,7 @@ public OMElement processDocument(InputStream inputStream, String contentType,
         return factory.createOMElement(ds, "dummy", ns);
     }
 
-    public class ByteArrayDataSourceEx extends javax.mail.util.ByteArrayDataSource implements OMDataSource {
+    public class ByteArrayDataSourceEx extends ByteArrayDataSource implements OMDataSource {
         private byte[] bytes;
     
         public ByteArrayDataSourceEx(byte[] bytes, String s) {
diff --git a/modules/kernel/src/org/apache/axis2/builder/MIMEBuilder.java b/modules/kernel/src/org/apache/axis2/builder/MIMEBuilder.java
index 9432cbccfc..454bda3cc0 100644
--- a/modules/kernel/src/org/apache/axis2/builder/MIMEBuilder.java
+++ b/modules/kernel/src/org/apache/axis2/builder/MIMEBuilder.java
@@ -20,6 +20,7 @@
 package org.apache.axis2.builder;
 
 import org.apache.axiom.attachments.Attachments;
+import org.apache.axiom.mime.ContentType;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
 import org.apache.axis2.AxisFault;
@@ -27,9 +28,8 @@
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.util.MessageProcessorSelector;
 
-import javax.mail.internet.ContentType;
-import javax.mail.internet.ParseException;
 import java.io.InputStream;
+import java.text.ParseException;
 
 public class MIMEBuilder implements Builder {
 
diff --git a/modules/transport/base/src/main/java/org/apache/axis2/format/TextMessageBuilderAdapter.java b/modules/transport/base/src/main/java/org/apache/axis2/format/TextMessageBuilderAdapter.java
index e6937afee0..9af6ab070e 100644
--- a/modules/transport/base/src/main/java/org/apache/axis2/format/TextMessageBuilderAdapter.java
+++ b/modules/transport/base/src/main/java/org/apache/axis2/format/TextMessageBuilderAdapter.java
@@ -22,10 +22,9 @@
 import java.io.InputStream;
 import java.io.Reader;
 import java.io.StringReader;
+import java.text.ParseException;
 
-import javax.mail.internet.ContentType;
-import javax.mail.internet.ParseException;
-
+import org.apache.axiom.mime.ContentType;
 import org.apache.axiom.om.OMElement;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
diff --git a/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java b/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java
index 1e6c94f17d..e5a5f4c985 100644
--- a/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java
+++ b/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java
@@ -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 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 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 AttachmentPart createAttachmentPart() {
     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 void saveChanges() throws SOAPException {
                 }
                 
                 //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 void writeTo(OutputStream out) throws SOAPException, IOException {
             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 @@ private String getSingleHeaderValue(String name) {
         }
     }
     
-    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 @@ private String getBaseType() throws SOAPException {
      * @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);
diff --git a/modules/saaj/src/org/apache/axis2/saaj/SOAPPartImpl.java b/modules/saaj/src/org/apache/axis2/saaj/SOAPPartImpl.java
index 77075a0b5b..b16b68f359 100644
--- a/modules/saaj/src/org/apache/axis2/saaj/SOAPPartImpl.java
+++ b/modules/saaj/src/org/apache/axis2/saaj/SOAPPartImpl.java
@@ -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.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.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 SOAPPartImpl(SOAPMessageImpl parentSoapMsg, InputStream inputStream,
             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 {
diff --git a/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java b/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java
index f5d760417a..cd020d75b8 100644
--- a/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java
+++ b/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java
@@ -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.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.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 void testContentTypeGeneration() throws Exception{
         //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 void testCreateMessageWithMimeHeaders() throws Exception{
         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 void testContentTypeUpdateWithAttachmentChanges() throws Exception{
         
         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) {
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin