Blame SOURCES/0001-Mime4j-0.7.2-support.patch

abf604
From 0e66cb23968c8ec56e4c26566790a8f09f380bca Mon Sep 17 00:00:00 2001
abf604
From: Marek Goldmann <marek.goldmann@gmail.com>
abf604
Date: Tue, 16 Jul 2013 14:14:07 +0200
abf604
Subject: [PATCH] Mime4j 0.7.2 support
abf604
abf604
---
abf604
 jaxrs/pom.xml                                      | 14 ++++-
abf604
 jaxrs/providers/multipart/pom.xml                  | 12 ++++-
abf604
 .../multipart/MultipartFormDataInputImpl.java      |  6 +--
abf604
 .../providers/multipart/MultipartInputImpl.java    | 61 ++++++++++------------
abf604
 .../multipart/MultipartRelatedInputImpl.java       |  4 +-
abf604
 jaxrs/security/resteasy-crypto/pom.xml             | 10 +++-
abf604
 6 files changed, 64 insertions(+), 43 deletions(-)
abf604
 mode change 100755 => 100644 jaxrs/pom.xml
abf604
abf604
diff --git a/jaxrs/pom.xml b/jaxrs/pom.xml
abf604
old mode 100755
abf604
new mode 100644
abf604
index 062e8da..45e5e8d
abf604
--- a/jaxrs/pom.xml
abf604
+++ b/jaxrs/pom.xml
abf604
@@ -251,8 +251,18 @@
abf604
             </dependency>
abf604
             <dependency>
abf604
                 <groupId>org.apache.james</groupId>
abf604
-                <artifactId>apache-mime4j</artifactId>
abf604
-                <version>0.6</version>
abf604
+                <artifactId>apache-mime4j-core</artifactId>
abf604
+                <version>0.7.2</version>
abf604
+             </dependency>
abf604
+            <dependency>
abf604
+                <groupId>org.apache.james</groupId>
abf604
+                <artifactId>apache-mime4j-storage</artifactId>
abf604
+                <version>0.7.2</version>
abf604
+             </dependency>
abf604
+            <dependency>
abf604
+                <groupId>org.apache.james</groupId>
abf604
+                <artifactId>apache-mime4j-dom</artifactId>
abf604
+                <version>0.7.2</version>
abf604
              </dependency>
abf604
             <dependency>
abf604
                 <groupId>junit</groupId>
abf604
diff --git a/jaxrs/providers/multipart/pom.xml b/jaxrs/providers/multipart/pom.xml
abf604
index 16bdbd2..a6b25f0 100755
abf604
--- a/jaxrs/providers/multipart/pom.xml
abf604
+++ b/jaxrs/providers/multipart/pom.xml
abf604
@@ -34,7 +34,15 @@
abf604
         </dependency>
abf604
         <dependency>
abf604
             <groupId>org.apache.james</groupId>
abf604
-            <artifactId>apache-mime4j</artifactId>
abf604
+            <artifactId>apache-mime4j-core</artifactId>
abf604
+        </dependency>
abf604
+        <dependency>
abf604
+            <groupId>org.apache.james</groupId>
abf604
+            <artifactId>apache-mime4j-dom</artifactId>
abf604
+        </dependency>
abf604
+        <dependency>
abf604
+            <groupId>org.apache.james</groupId>
abf604
+            <artifactId>apache-mime4j-storage</artifactId>
abf604
         </dependency>
abf604
         <dependency>
abf604
             <groupId>javax.servlet</groupId>
abf604
@@ -81,4 +89,4 @@
abf604
         </plugins>
abf604
     </build>
abf604
 
abf604
-</project>
abf604
\ No newline at end of file
abf604
+</project>
abf604
diff --git a/jaxrs/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartFormDataInputImpl.java b/jaxrs/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartFormDataInputImpl.java
abf604
index d9ed2ad..b7aab17 100644
abf604
--- a/jaxrs/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartFormDataInputImpl.java
abf604
+++ b/jaxrs/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartFormDataInputImpl.java
abf604
@@ -1,9 +1,9 @@
abf604
 package org.jboss.resteasy.plugins.providers.multipart;
abf604
 
abf604
-import org.apache.james.mime4j.field.ContentDispositionField;
abf604
-import org.apache.james.mime4j.field.FieldName;
abf604
+import org.apache.james.mime4j.dom.field.ContentDispositionField;
abf604
+import org.apache.james.mime4j.dom.field.FieldName;
abf604
 import org.apache.james.mime4j.message.BodyPart;
abf604
-import org.apache.james.mime4j.parser.Field;
abf604
+import org.apache.james.mime4j.stream.Field;
abf604
 import org.jboss.resteasy.util.GenericType;
abf604
 
abf604
 import javax.ws.rs.core.MediaType;
abf604
diff --git a/jaxrs/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartInputImpl.java b/jaxrs/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartInputImpl.java
abf604
index 938c88e..01ddfa1 100644
abf604
--- a/jaxrs/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartInputImpl.java
abf604
+++ b/jaxrs/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartInputImpl.java
abf604
@@ -4,22 +4,22 @@ import org.apache.james.mime4j.MimeException;
abf604
 import org.apache.james.mime4j.MimeIOException;
abf604
 import org.apache.james.mime4j.codec.Base64InputStream;
abf604
 import org.apache.james.mime4j.codec.QuotedPrintableInputStream;
abf604
-import org.apache.james.mime4j.descriptor.BodyDescriptor;
abf604
-import org.apache.james.mime4j.field.ContentTypeField;
abf604
-import org.apache.james.mime4j.message.BinaryBody;
abf604
-import org.apache.james.mime4j.message.Body;
abf604
+import org.apache.james.mime4j.message.MessageImpl;
abf604
+import org.apache.james.mime4j.parser.AbstractContentHandler;
abf604
+import org.apache.james.mime4j.stream.BodyDescriptor;
abf604
 import org.apache.james.mime4j.message.BodyFactory;
abf604
+import org.apache.james.mime4j.dom.MessageBuilder;
abf604
+import org.apache.james.mime4j.dom.MessageServiceFactory;
abf604
+import org.apache.james.mime4j.dom.field.ContentTypeField;
abf604
+import org.apache.james.mime4j.dom.BinaryBody;
abf604
+import org.apache.james.mime4j.dom.Body;
abf604
+import org.apache.james.mime4j.dom.Entity;
abf604
 import org.apache.james.mime4j.message.BodyPart;
abf604
-import org.apache.james.mime4j.message.Entity;
abf604
-import org.apache.james.mime4j.message.Message;
abf604
-import org.apache.james.mime4j.message.MessageBuilder;
abf604
-import org.apache.james.mime4j.message.Multipart;
abf604
-import org.apache.james.mime4j.message.TextBody;
abf604
-import org.apache.james.mime4j.parser.Field;
abf604
+import org.apache.james.mime4j.dom.Message;
abf604
+import org.apache.james.mime4j.dom.Multipart;
abf604
+import org.apache.james.mime4j.dom.TextBody;
abf604
+import org.apache.james.mime4j.stream.Field;
abf604
 import org.apache.james.mime4j.parser.MimeStreamParser;
abf604
-import org.apache.james.mime4j.storage.DefaultStorageProvider;
abf604
-import org.apache.james.mime4j.storage.StorageProvider;
abf604
-import org.apache.james.mime4j.util.CharsetUtil;
abf604
 import org.apache.james.mime4j.util.MimeUtil;
abf604
 import org.jboss.resteasy.spi.HttpRequest;
abf604
 import org.jboss.resteasy.spi.ResteasyProviderFactory;
abf604
@@ -43,6 +43,7 @@ import java.lang.annotation.Annotation;
abf604
 import java.lang.reflect.InvocationTargetException;
abf604
 import java.lang.reflect.Method;
abf604
 import java.lang.reflect.Type;
abf604
+import java.nio.charset.Charset;
abf604
 import java.util.ArrayList;
abf604
 import java.util.HashMap;
abf604
 import java.util.Iterator;
abf604
@@ -65,7 +66,7 @@ public class MultipartInputImpl implements MultipartInput
abf604
    protected String defaultPartCharset = null;
abf604
 
abf604
    // We hack MIME4j so that it always returns a BinaryBody so we don't have to deal with Readers and their charset conversions
abf604
-   private static class BinaryOnlyMessageBuilder extends MessageBuilder
abf604
+   private static class BinaryOnlyMessageBuilder extends AbstractContentHandler
abf604
    {
abf604
       private Method expectMethod;
abf604
       private java.lang.reflect.Field bodyFactoryField;
abf604
@@ -88,18 +89,6 @@ public class MultipartInputImpl implements MultipartInput
abf604
          }
abf604
       }
abf604
 
abf604
-      private BinaryOnlyMessageBuilder(Entity entity)
abf604
-      {
abf604
-         super(entity);
abf604
-         init();
abf604
-      }
abf604
-
abf604
-      private BinaryOnlyMessageBuilder(Entity entity, StorageProvider storageProvider)
abf604
-      {
abf604
-         super(entity, storageProvider);
abf604
-         init();
abf604
-      }
abf604
-
abf604
       @Override
abf604
       public void body(BodyDescriptor bd, InputStream is) throws MimeException, IOException
abf604
       {
abf604
@@ -143,13 +132,13 @@ public class MultipartInputImpl implements MultipartInput
abf604
       }
abf604
    }
abf604
 
abf604
-   private static class BinaryMessage extends Message
abf604
+   private static class BinaryMessage extends MessageImpl
abf604
    {
abf604
       private BinaryMessage(InputStream is) throws IOException, MimeIOException
abf604
       {
abf604
          try {
abf604
-            MimeStreamParser parser = new MimeStreamParser(null);
abf604
-            parser.setContentHandler(new BinaryOnlyMessageBuilder(this, DefaultStorageProvider.getInstance()));
abf604
+            MimeStreamParser parser = new MimeStreamParser();
abf604
+            parser.setContentHandler(new BinaryOnlyMessageBuilder());
abf604
             parser.parse(is);
abf604
          } catch (MimeException e) {
abf604
             throw new MimeIOException(e);
abf604
@@ -194,8 +183,14 @@ public class MultipartInputImpl implements MultipartInput
abf604
 
abf604
    public void parse(InputStream is) throws IOException
abf604
    {
abf604
-      mimeMessage = new BinaryMessage(addHeaderToHeadlessStream(is));
abf604
-      extractParts();
abf604
+      try {
abf604
+         MessageServiceFactory factory = MessageServiceFactory.newInstance();
abf604
+         MessageBuilder builder = factory.newMessageBuilder();
abf604
+         mimeMessage = builder.parseMessage(addHeaderToHeadlessStream(is));
abf604
+         extractParts();
abf604
+      } catch (MimeException e) {
abf604
+         throw new IOException("Couldn't parse message", e);
abf604
+      }
abf604
    }
abf604
 
abf604
    protected InputStream addHeaderToHeadlessStream(InputStream is)
abf604
@@ -225,8 +220,8 @@ public class MultipartInputImpl implements MultipartInput
abf604
    protected void extractParts() throws IOException
abf604
    {
abf604
       Multipart multipart = (Multipart) mimeMessage.getBody();
abf604
-      for (BodyPart bodyPart : multipart.getBodyParts())
abf604
-         parts.add(extractPart(bodyPart));
abf604
+      for (Entity bodyPart : multipart.getBodyParts())
abf604
+        parts.add(extractPart((BodyPart) bodyPart));
abf604
    }
abf604
 
abf604
    protected InputPart extractPart(BodyPart bodyPart) throws IOException
abf604
diff --git a/jaxrs/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartRelatedInputImpl.java b/jaxrs/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartRelatedInputImpl.java
abf604
index 698f937..fa2d889 100644
abf604
--- a/jaxrs/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartRelatedInputImpl.java
abf604
+++ b/jaxrs/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartRelatedInputImpl.java
abf604
@@ -1,7 +1,7 @@
abf604
 package org.jboss.resteasy.plugins.providers.multipart;
abf604
 
abf604
-import org.apache.james.mime4j.field.ContentTypeField;
abf604
-import org.apache.james.mime4j.field.FieldName;
abf604
+import org.apache.james.mime4j.dom.field.ContentTypeField;
abf604
+import org.apache.james.mime4j.dom.field.FieldName;
abf604
 import org.apache.james.mime4j.message.BodyPart;
abf604
 
abf604
 import javax.ws.rs.core.MediaType;
abf604
diff --git a/jaxrs/security/resteasy-crypto/pom.xml b/jaxrs/security/resteasy-crypto/pom.xml
abf604
index 855f791..bd23c9f 100755
abf604
--- a/jaxrs/security/resteasy-crypto/pom.xml
abf604
+++ b/jaxrs/security/resteasy-crypto/pom.xml
abf604
@@ -70,7 +70,15 @@
abf604
         </dependency>
abf604
         <dependency>
abf604
             <groupId>org.apache.james</groupId>
abf604
-            <artifactId>apache-mime4j</artifactId>
abf604
+            <artifactId>apache-mime4j-dom</artifactId>
abf604
+        </dependency>
abf604
+        <dependency>
abf604
+            <groupId>org.apache.james</groupId>
abf604
+            <artifactId>apache-mime4j-core</artifactId>
abf604
+        </dependency>
abf604
+        <dependency>
abf604
+            <groupId>org.apache.james</groupId>
abf604
+            <artifactId>apache-mime4j-storage</artifactId>
abf604
         </dependency>
abf604
     </dependencies>
abf604
     <build>
abf604
-- 
abf604
1.8.3.1
abf604