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

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