resteasy/resteasy-2.3.2.Final-mime4j-0.7.2.patch
2012-04-24 13:41:10 +02:00

114 lines
5.6 KiB
Diff

diff --git a/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartFormDataInputImpl.java b/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartFormDataInputImpl.java
index 6763d4e..cc41e2f 100644
--- a/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartFormDataInputImpl.java
+++ b/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartFormDataInputImpl.java
@@ -10,10 +10,10 @@ import java.util.Map;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Providers;
-import org.apache.james.mime4j.field.ContentDispositionField;
-import org.apache.james.mime4j.field.FieldName;
+import org.apache.james.mime4j.dom.field.ContentDispositionField;
+import org.apache.james.mime4j.dom.field.FieldName;
import org.apache.james.mime4j.message.BodyPart;
-import org.apache.james.mime4j.parser.Field;
+import org.apache.james.mime4j.stream.Field;
import org.jboss.resteasy.util.GenericType;
/**
diff --git a/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartInputImpl.java b/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartInputImpl.java
index 2865174..d5a1e0c 100644
--- a/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartInputImpl.java
+++ b/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartInputImpl.java
@@ -1,14 +1,18 @@
package org.jboss.resteasy.plugins.providers.multipart;
-import org.apache.james.mime4j.field.ContentTypeField;
-import org.apache.james.mime4j.message.BinaryBody;
-import org.apache.james.mime4j.message.Body;
+import org.apache.james.mime4j.dom.MessageBuilder;
+import org.apache.james.mime4j.dom.MessageServiceFactory;
+import org.apache.james.mime4j.dom.field.ContentTypeField;
+import org.apache.james.mime4j.dom.BinaryBody;
+import org.apache.james.mime4j.dom.Body;
+import org.apache.james.mime4j.dom.Entity;
import org.apache.james.mime4j.message.BodyPart;
-import org.apache.james.mime4j.message.Message;
-import org.apache.james.mime4j.message.Multipart;
-import org.apache.james.mime4j.message.TextBody;
-import org.apache.james.mime4j.parser.Field;
+import org.apache.james.mime4j.dom.Message;
+import org.apache.james.mime4j.dom.Multipart;
+import org.apache.james.mime4j.dom.TextBody;
+import org.apache.james.mime4j.stream.Field;
import org.apache.james.mime4j.util.CharsetUtil;
+import org.apache.james.mime4j.MimeException;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.util.CaseInsensitiveMap;
@@ -29,6 +33,7 @@ import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -73,8 +78,14 @@ public class MultipartInputImpl implements MultipartInput
public void parse(InputStream is) throws IOException
{
- mimeMessage = new Message(addHeaderToHeadlessStream(is));
- extractParts();
+ try {
+ MessageServiceFactory factory = MessageServiceFactory.newInstance();
+ MessageBuilder builder = factory.newMessageBuilder();
+ mimeMessage = builder.parseMessage(addHeaderToHeadlessStream(is));
+ extractParts();
+ } catch (MimeException e) {
+ throw new IOException("Couldn't parse message", e);
+ }
}
protected InputStream addHeaderToHeadlessStream(InputStream is)
@@ -104,8 +115,8 @@ public class MultipartInputImpl implements MultipartInput
protected void extractParts() throws IOException
{
Multipart multipart = (Multipart) mimeMessage.getBody();
- for (BodyPart bodyPart : multipart.getBodyParts())
- parts.add(extractPart(bodyPart));
+ for (Entity bodyPart : multipart.getBodyParts())
+ parts.add(extractPart((BodyPart) bodyPart));
}
protected InputPart extractPart(BodyPart bodyPart) throws IOException
@@ -197,8 +208,11 @@ public class MultipartInputImpl implements MultipartInput
try
{
String charset = contentType.getParameters().get("charset");
- if (charset != null)
- charset = CharsetUtil.toJavaCharset(charset);
+ if (charset != null) {
+ Charset c = CharsetUtil.lookup(charset);
+ if (c != null)
+ charset = c.name();
+ }
inputStreamReader = charset == null ? new InputStreamReader(
inputStream)
: new InputStreamReader(inputStream, charset);
diff --git a/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartRelatedInputImpl.java b/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartRelatedInputImpl.java
index da7f0b7..2063a76 100644
--- a/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartRelatedInputImpl.java
+++ b/providers/multipart/src/main/java/org/jboss/resteasy/plugins/providers/multipart/MultipartRelatedInputImpl.java
@@ -8,8 +8,8 @@ import java.util.Map;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Providers;
-import org.apache.james.mime4j.field.ContentTypeField;
-import org.apache.james.mime4j.field.FieldName;
+import org.apache.james.mime4j.dom.field.ContentTypeField;
+import org.apache.james.mime4j.dom.field.FieldName;
import org.apache.james.mime4j.message.BodyPart;
/**