Author: dkulp
Date: Fri Aug 9 01:55:00 2013
New Revision: 1512125
URL: http://svn.apache.org/r1512125
Log:
Remove dependency on javax.mail.
Handle base64 decoding of attachments.
Added:
cxf/trunk/api/src/main/java/org/apache/cxf/attachment/Base64DecoderStream.java
Modified:
cxf/trunk/api/pom.xml
cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
cxf/trunk/api/src/main/java/org/apache/cxf/common/util/Base64Utility.java
cxf/trunk/api/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
cxf/trunk/rt/core/pom.xml
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanTest.java
cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java
cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java
Modified: cxf/trunk/api/pom.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/pom.xml?rev=1512125&r1=1512124&r2=1512125&view=diff
==============================================================================
--- cxf/trunk/api/pom.xml (original)
+++ cxf/trunk/api/pom.xml Fri Aug 9 01:55:00 2013
@@ -144,6 +144,7 @@
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-javamail_1.4_spec</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.fastinfoset</groupId>
Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java?rev=1512125&r1=1512124&r2=1512125&view=diff
==============================================================================
---
cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
(original)
+++
cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
Fri Aug 9 01:55:00 2013
@@ -26,13 +26,13 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.activation.DataSource;
-import javax.mail.MessagingException;
-import javax.mail.internet.InternetHeaders;
import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.helpers.HttpHeaderHelper;
@@ -42,7 +42,7 @@ import org.apache.cxf.message.Attachment
import org.apache.cxf.message.Message;
public class AttachmentDeserializer {
-
+ public static final String ATTACHMENT_PART_HEADERS =
AttachmentDeserializer.class.getName() + ".headers";
public static final String ATTACHMENT_DIRECTORY = "attachment-directory";
public static final String ATTACHMENT_MEMORY_THRESHOLD =
"attachment-memory-threshold";
@@ -123,18 +123,14 @@ public class AttachmentDeserializer {
throw new IOException("Couldn't find MIME boundary: " +
boundaryString);
}
- try {
- InternetHeaders ih = new InternetHeaders(stream);
- message.put(InternetHeaders.class.getName(), ih);
- String val = ih.getHeader("Content-Type", "; ");
- if (!StringUtils.isEmpty(val)) {
- String cs = HttpHeaderHelper.findCharset(val);
- if (!StringUtils.isEmpty(cs)) {
- message.put(Message.ENCODING,
HttpHeaderHelper.mapCharset(cs));
- }
+ Map<String, List<String>> ih = loadPartHeaders(stream);
+ message.put(ATTACHMENT_PART_HEADERS, ih);
+ String val = AttachmentUtil.getHeader(ih, "Content-Type", "; ");
+ if (!StringUtils.isEmpty(val)) {
+ String cs = HttpHeaderHelper.findCharset(val);
+ if (!StringUtils.isEmpty(cs)) {
+ message.put(Message.ENCODING,
HttpHeaderHelper.mapCharset(cs));
}
- } catch (MessagingException e) {
- throw new RuntimeException(e);
}
body = new DelegatingInputStream(new
MimeBodyPartInputStream(stream, boundary, pbAmount),
@@ -180,15 +176,7 @@ public class AttachmentDeserializer {
}
stream.unread(v);
-
- InternetHeaders headers;
- try {
- headers = new InternetHeaders(stream);
- } catch (MessagingException e) {
- // TODO create custom IOException
- throw new RuntimeException(e);
- }
-
+ Map<String, List<String>> headers = loadPartHeaders(stream);
return (AttachmentImpl)createAttachment(headers);
}
@@ -281,7 +269,7 @@ public class AttachmentDeserializer {
* @return
* @throws IOException
*/
- private Attachment createAttachment(InternetHeaders headers) throws
IOException {
+ private Attachment createAttachment(Map<String, List<String>> headers)
throws IOException {
InputStream partStream =
new DelegatingInputStream(new MimeBodyPartInputStream(stream,
boundary, pbAmount),
this);
@@ -327,5 +315,121 @@ public class AttachmentDeserializer {
stream.unread(v);
return true;
}
+
+
+
+ private Map<String, List<String>> loadPartHeaders(InputStream in) throws
IOException {
+ List<String> headerLines = new ArrayList<String>(10);
+ StringBuffer buffer = new StringBuffer(128);
+ String line;
+ // loop until we hit the end or a null line
+ while ((line = readLine(in)) != null) {
+ // lines beginning with white space get special handling
+ if (line.startsWith(" ") || line.startsWith("\t")) {
+ // this gets handled using the logic defined by
+ // the addHeaderLine method. If this line is a continuation,
but
+ // there's nothing before it, just call addHeaderLine to add it
+ // to the last header in the headers list
+ if (buffer.length() == 0) {
+ addHeaderLine(headerLines, line);
+ } else {
+ // preserve the line break and append the continuation
+ buffer.append("\r\n");
+ buffer.append(line);
+ }
+ } else {
+ // if we have a line pending in the buffer, flush it
+ if (buffer.length() > 0) {
+ addHeaderLine(headerLines, buffer.toString());
+ buffer.setLength(0);
+ }
+ // add this to the accumulator
+ buffer.append(line);
+ }
+ }
+
+ // if we have a line pending in the buffer, flush it
+ if (buffer.length() > 0) {
+ addHeaderLine(headerLines, buffer.toString());
+ }
+ Map<String, List<String>> heads = new TreeMap<String,
List<String>>(String.CASE_INSENSITIVE_ORDER);
+ for (String h: headerLines) {
+ int separator = h.indexOf(':');
+ String name = null;
+ String value = "";
+ if (separator == -1) {
+ name = h.trim();
+ } else {
+ name = h.substring(0, separator);
+ // step past the separator. Now we need to remove any leading
white space characters.
+ separator++;
+
+ while (separator < h.length()) {
+ char ch = h.charAt(separator);
+ if (ch != ' ' && ch != '\t' && ch != '\r' && ch != '\n') {
+ break;
+ }
+ separator++;
+ }
+ value = h.substring(separator);
+ }
+ List<String> v = heads.get(name);
+ if (v == null) {
+ v = new ArrayList<String>(1);
+ heads.put(name, v);
+ }
+ v.add(value);
+ }
+ return heads;
+ }
+
+ private String readLine(InputStream in) throws IOException {
+ StringBuffer buffer = new StringBuffer(128);
+
+ int c;
+
+ while ((c = in.read()) != -1) {
+ // a linefeed is a terminator, always.
+ if (c == '\n') {
+ break;
+ } else if (c == '\r') {
+ //just ignore the CR. The next character SHOULD be an NL. If
not, we're
+ //just going to discard this
+ continue;
+ } else {
+ // just add to the buffer
+ buffer.append((char)c);
+ }
+ }
+
+ // no characters found...this was either an eof or a null line.
+ if (buffer.length() == 0) {
+ return null;
+ }
+
+ return buffer.toString();
+ }
+ private void addHeaderLine(List<String> headers, String line) {
+ // null lines are a nop
+ if (line.length() == 0) {
+ return;
+ }
+
+ // we need to test the first character to see if this is a
continuation whitespace
+ char ch = line.charAt(0);
+
+ // tabs and spaces are special. This is a continuation of the last
header in the list.
+ if (ch == ' ' || ch == '\t') {
+ int size = headers.size();
+ // it's possible that we have a leading blank line.
+ if (size > 0) {
+ line = headers.remove(size - 1) + line;
+ headers.add(line);
+ }
+ } else {
+ // this just gets appended to the end, preserving the addition
order.
+ headers.add(line);
+ }
+ }
}
Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java?rev=1512125&r1=1512124&r2=1512125&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
(original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
Fri Aug 9 01:55:00 2013
@@ -31,7 +31,6 @@ import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Enumeration;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
@@ -49,8 +48,6 @@ import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.activation.MailcapCommandMap;
import javax.activation.URLDataSource;
-import javax.mail.Header;
-import javax.mail.internet.InternetHeaders;
import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.helpers.HttpHeaderHelper;
@@ -287,16 +284,40 @@ public final class AttachmentUtil {
return id;
}
-
- public static Attachment createAttachment(InputStream stream,
InternetHeaders headers)
+ static String getHeaderValue(List<String> v) {
+ if (v != null && v.size() > 0) {
+ return v.get(0);
+ }
+ return null;
+ }
+ static String getHeaderValue(List<String> v, String delim) {
+ if (v != null && v.size() > 0) {
+ StringBuilder b = new StringBuilder();
+ for (String s : v) {
+ if (b.length() > 0) {
+ b.append(delim);
+ }
+ b.append(s);
+ }
+ return b.toString();
+ }
+ return null;
+ }
+ static String getHeader(Map<String, List<String>> headers, String h) {
+ return getHeaderValue(headers.get(h));
+ }
+ static String getHeader(Map<String, List<String>> headers, String h,
String delim) {
+ return getHeaderValue(headers.get(h), delim);
+ }
+ public static Attachment createAttachment(InputStream stream, Map<String,
List<String>> headers)
throws IOException {
- String id = cleanContentId(headers.getHeader("Content-ID", null));
+ String id = cleanContentId(getHeader(headers, "Content-ID"));
AttachmentImpl att = new AttachmentImpl(id);
- final String ct = headers.getHeader("Content-Type", null);
- String cd = headers.getHeader("Content-Disposition", null);
+ final String ct = getHeader(headers, "Content-Type");
+ String cd = getHeader(headers, "Content-Disposition");
String fileName = null;
if (!StringUtils.isEmpty(cd)) {
StringTokenizer token = new StringTokenizer(cd, ";");
@@ -315,38 +336,47 @@ public final class AttachmentUtil {
}
}
- boolean quotedPrintable = false;
+ String encoding = null;
- for (Enumeration<?> e = headers.getAllHeaders(); e.hasMoreElements();)
{
- Header header = (Header) e.nextElement();
- if
(header.getName().equalsIgnoreCase("Content-Transfer-Encoding")) {
- if (header.getValue().equalsIgnoreCase("binary")) {
+ for (Map.Entry<String, List<String>> e : headers.entrySet()) {
+ String name = e.getKey();
+ if (name.equalsIgnoreCase("Content-Transfer-Encoding")) {
+ encoding = getHeader(headers, name);
+ if ("binary".equalsIgnoreCase(encoding)) {
att.setXOP(true);
- } else if
(header.getValue().equalsIgnoreCase("quoted-printable")) {
- quotedPrintable = true;
}
}
- att.setHeader(header.getName(), header.getValue());
+ att.setHeader(name, getHeaderValue(e.getValue()));
}
-
- if (quotedPrintable) {
- DataSource source = new AttachmentDataSource(ct,
- new
QuotedPrintableDecoderStream(stream));
- if (!StringUtils.isEmpty(fileName)) {
- ((AttachmentDataSource)source).setName(fileName);
- }
- att.setDataHandler(new DataHandler(source));
- } else {
- DataSource source = new AttachmentDataSource(ct, stream);
- if (!StringUtils.isEmpty(fileName)) {
- ((AttachmentDataSource)source).setName(fileName);
- }
- att.setDataHandler(new DataHandler(source));
+ if (encoding == null) {
+ encoding = "binary";
}
-
+ DataSource source = new AttachmentDataSource(ct,
+ decode(stream, encoding));
+ if (!StringUtils.isEmpty(fileName)) {
+ ((AttachmentDataSource)source).setName(fileName);
+ }
+ att.setDataHandler(new DataHandler(source));
return att;
}
+
+ public static InputStream decode(InputStream in, String encoding) throws
IOException {
+ encoding = encoding.toLowerCase();
+
+ // some encodings are just pass-throughs, with no real decoding.
+ if ("binary".equals(encoding)
+ || "7bit".equals(encoding)
+ || "8bit".equals(encoding)) {
+ return in;
+ } else if ("base64".equals(encoding)) {
+ return new Base64DecoderStream(in);
+ } else if ("quoted-printable".equals(encoding)) {
+ return new QuotedPrintableDecoderStream(in);
+ } else {
+ throw new IOException("Unknown encoding " + encoding);
+ }
+ }
public static boolean isTypeSupported(String contentType, List<String>
types) {
if (contentType == null) {
return false;
Added:
cxf/trunk/api/src/main/java/org/apache/cxf/attachment/Base64DecoderStream.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/attachment/Base64DecoderStream.java?rev=1512125&view=auto
==============================================================================
---
cxf/trunk/api/src/main/java/org/apache/cxf/attachment/Base64DecoderStream.java
(added)
+++
cxf/trunk/api/src/main/java/org/apache/cxf/attachment/Base64DecoderStream.java
Fri Aug 9 01:55:00 2013
@@ -0,0 +1,191 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.attachment;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.cxf.common.util.Base64Exception;
+import org.apache.cxf.common.util.Base64Utility;
+
+/**
+ * An implementation of a FilterInputStream that decodes the
+ * stream data in BASE64 encoding format. This version does the
+ * decoding "on the fly" rather than decoding a single block of
+ * data. Since this version is intended for use by the MimeUtilty class,
+ * it also handles line breaks in the encoded data.
+ */
+public class Base64DecoderStream extends FilterInputStream {
+
+ static final String MAIL_BASE64_IGNOREERRORS =
"mail.mime.base64.ignoreerrors";
+
+ // number of decodeable units we'll try to process at one time. We'll
attempt to read that much
+ // data from the input stream and decode in blocks.
+ static final int BUFFERED_UNITS = 2000;
+
+ // can be overridden by a system property.
+ protected boolean ignoreErrors;
+
+ // buffer for reading in chars for decoding (which can support larger bulk
reads)
+ protected char[] encodedChars = new char[BUFFERED_UNITS * 4];
+ // a buffer for one decoding unit's worth of data (3 bytes).
+ protected byte[] decodedChars;
+ // count of characters in the buffer
+ protected int decodedCount;
+ // index of the next decoded character
+ protected int decodedIndex;
+
+
+ public Base64DecoderStream(InputStream in) {
+ super(in);
+ }
+
+ /**
+ * Test for the existance of decoded characters in our buffer
+ * of decoded data.
+ *
+ * @return True if we currently have buffered characters.
+ */
+ private boolean dataAvailable() {
+ return decodedCount != 0;
+ }
+
+ /**
+ * Decode a requested number of bytes of data into a buffer.
+ *
+ * @return true if we were able to obtain more data, false otherwise.
+ */
+ private boolean decodeStreamData() throws IOException {
+ decodedIndex = 0;
+
+ // fill up a data buffer with input data
+ int readCharacters = fillEncodedBuffer();
+
+ if (readCharacters > 0) {
+ try {
+ decodedChars = Base64Utility.decodeChunk(encodedChars, 0,
readCharacters);
+ } catch (Base64Exception e) {
+ throw new IOException(e);
+ }
+ decodedCount = decodedChars.length;
+ return true;
+ }
+ return false;
+ }
+
+
+ /**
+ * Retrieve a single byte from the decoded characters buffer.
+ *
+ * @return The decoded character or -1 if there was an EOF condition.
+ */
+ private int getByte() throws IOException {
+ if (!dataAvailable() && !decodeStreamData()) {
+ return -1;
+ }
+ decodedCount--;
+ // we need to ensure this doesn't get sign extended
+ return decodedChars[decodedIndex++] & 0xff;
+ }
+
+ private int getBytes(byte[] data, int offset, int length) throws
IOException {
+
+ int readCharacters = 0;
+ while (length > 0) {
+ // need data? Try to get some
+ if (!dataAvailable() && !decodeStreamData()) {
+ // if we can't get this, return a count of how much we did get
(which may be -1).
+ return readCharacters > 0 ? readCharacters : -1;
+ }
+
+ // now copy some of the data from the decoded buffer to the target
buffer
+ int copyCount = Math.min(decodedCount, length);
+ System.arraycopy(decodedChars, decodedIndex, data, offset,
copyCount);
+ decodedIndex += copyCount;
+ decodedCount -= copyCount;
+ offset += copyCount;
+ length -= copyCount;
+ readCharacters += copyCount;
+ }
+ return readCharacters;
+ }
+
+
+ /**
+ * Fill our buffer of input characters for decoding from the
+ * stream. This will attempt read a full buffer, but will
+ * terminate on an EOF or read error. This will filter out
+ * non-Base64 encoding chars and will only return a valid
+ * multiple of 4 number of bytes.
+ *
+ * @return The count of characters read.
+ */
+ private int fillEncodedBuffer() throws IOException {
+ int readCharacters = 0;
+
+ while (true) {
+ // get the next character from the stream
+ int ch = in.read();
+ // did we hit an EOF condition?
+ if (ch == -1) {
+ // now check to see if this is normal, or potentially an error
+ // if we didn't get characters as a multiple of 4, we may need
to complain about this.
+ if ((readCharacters % 4) != 0) {
+ throw new IOException("Base64 encoding error, data
truncated");
+ }
+ // return the count.
+ return readCharacters;
+ } else if (Base64Utility.isValidBase64(ch)) {
+ // if this character is valid in a Base64 stream, copy it to
the buffer.
+ encodedChars[readCharacters++] = (char)ch;
+ // if we've filled up the buffer, time to quit.
+ if (readCharacters >= encodedChars.length) {
+ return readCharacters;
+ }
+ }
+
+ // we're filtering out whitespace and CRLF characters, so just
ignore these
+ }
+ }
+
+
+ // in order to function as a filter, these streams need to override the
different
+ // read() signature.
+
+ public int read() throws IOException {
+ return getByte();
+ }
+
+
+ public int read(byte [] buffer, int offset, int length) throws IOException
{
+ return getBytes(buffer, offset, length);
+ }
+
+
+ public boolean markSupported() {
+ return false;
+ }
+
+
+ public int available() throws IOException {
+ return ((in.available() / 4) * 3) + decodedCount;
+ }
+}
Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/common/util/Base64Utility.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/common/util/Base64Utility.java?rev=1512125&r1=1512124&r2=1512125&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/common/util/Base64Utility.java
(original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/common/util/Base64Utility.java
Fri Aug 9 01:55:00 2013
@@ -353,6 +353,10 @@ public final class Base64Utility {
// We should never get here
throw new IllegalStateException();
}
+ }
+
+ public static boolean isValidBase64(int ch) {
+ return ch == PAD || BDT[ch] != Byte.MAX_VALUE;
}
}
Modified:
cxf/trunk/api/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java?rev=1512125&r1=1512124&r2=1512125&view=diff
==============================================================================
---
cxf/trunk/api/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
(original)
+++
cxf/trunk/api/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
Fri Aug 9 01:55:00 2013
@@ -145,8 +145,8 @@ public class AttachmentDeserializerTest
assertTrue(out.toString().startsWith("<env:Envelope"));
// try streaming a character off the wire
- assertTrue(attIs.read() == '/');
- assertTrue(attIs.read() == '9');
+ assertEquals(255, attIs.read());
+ assertEquals(216, (char)attIs.read());
// Attachment invalid = atts.get("INVALID");
// assertNull(invalid.getDataHandler().getInputStream());
@@ -189,8 +189,8 @@ public class AttachmentDeserializerTest
assertTrue(out.toString().startsWith("<env:Envelope"));
// try streaming a character off the wire
- assertTrue(attIs.read() == '/');
- assertTrue(attIs.read() == '9');
+ assertEquals(255, attIs.read());
+ assertEquals(216, attIs.read());
// Attachment invalid = atts.get("INVALID");
// assertNull(invalid.getDataHandler().getInputStream());
Modified: cxf/trunk/rt/core/pom.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/core/pom.xml?rev=1512125&r1=1512124&r2=1512125&view=diff
==============================================================================
--- cxf/trunk/rt/core/pom.xml (original)
+++ cxf/trunk/rt/core/pom.xml Fri Aug 9 01:55:00 2013
@@ -39,7 +39,6 @@
<cxf.osgi.import>
org.springframework*;resolution:=optional;version="${cxf.osgi.spring.version}",
javax.activation;version="${cxf.osgi.javax.activation.version}",
- javax.mail;version="${cxf.osgi.javax.mail.version}",
javax.annotation;version="${cxf.osgi.javax.annotation.version}",
javax.xml.bind*;version="${cxf.osgi.javax.bind.version}",
javax.xml.stream*;version="${cxf.osgi.javax.stream.version}",
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java?rev=1512125&r1=1512124&r2=1512125&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
Fri Aug 9 01:55:00 2013
@@ -28,7 +28,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import javax.mail.internet.InternetHeaders;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
@@ -264,9 +263,11 @@ public class MessageContextImpl implemen
List<Attachment> newAttachments = new LinkedList<Attachment>();
try {
+ Map<String, List<String>> headers
+ = CastUtils.cast((Map<?,
?>)inMessage.get(AttachmentDeserializer.ATTACHMENT_PART_HEADERS));
Attachment first = new Attachment(AttachmentUtil.createAttachment(
inMessage.getContent(InputStream.class),
-
(InternetHeaders)inMessage.get(InternetHeaders.class.getName())),
+ headers),
new ProvidersImpl(inMessage));
newAttachments.add(first);
} catch (IOException ex) {
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java?rev=1512125&r1=1512124&r2=1512125&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
Fri Aug 9 01:55:00 2013
@@ -40,7 +40,6 @@ import java.util.logging.Logger;
import javax.activation.DataHandler;
import javax.activation.DataSource;
-import javax.mail.internet.MimeUtility;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.Consumes;
import javax.ws.rs.InternalServerErrorException;
@@ -233,7 +232,6 @@ public class MultipartProvider extends A
mc.getProviders().getMessageBodyReader(c, t, anns,
multipart.getContentType());
if (r != null) {
InputStream is = multipart.getDataHandler().getInputStream();
- is = decodeIfNeeded(multipart, is);
return r.readFrom(c, t, anns, multipart.getContentType(),
multipart.getHeaders(),
is);
}
@@ -241,19 +239,6 @@ public class MultipartProvider extends A
return null;
}
-
- private InputStream decodeIfNeeded(Attachment multipart, InputStream is) {
- String value = multipart.getHeader("Content-Transfer-Encoding");
- if ("base64".equals(value) || "quoted-printable".equals(value)) {
- try {
- is = MimeUtility.decode(is, value);
- } catch (Exception ex) {
- LOG.warning("Problem with decoding an input stream, encoding :
" + value);
- }
- }
- return is;
- }
-
private boolean mediaTypeSupported(MediaType mt) {
return mt.getType().equals("multipart") &&
MULTIPART_SUBTYPES.contains(mt.getSubtype());
}
Modified:
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanTest.java?rev=1512125&r1=1512124&r2=1512125&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanTest.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanTest.java
Fri Aug 9 01:55:00 2013
@@ -76,7 +76,7 @@ public class JAXRSServerFactoryBeanTest
assertEquals("Get a wrong ResourceClasses size", 1,
sfb.getResourceClasses().size());
assertEquals("Get a wrong resource class",
BookStoreNoAnnotations.class,
sfb.getResourceClasses().get(0));
-
+ ctx.close();
}
private void verifyJaxbProvider(List<?> providers) throws Exception {
Modified:
cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java?rev=1512125&r1=1512124&r2=1512125&view=diff
==============================================================================
---
cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java
(original)
+++
cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java
Fri Aug 9 01:55:00 2013
@@ -167,7 +167,7 @@ public class MtomPolicyTest extends Abst
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(inAtt.getDataHandler().getInputStream(), out);
out.close();
- assertEquals(37448, out.size());
+ assertEquals(27364, out.size());
}
Modified:
cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java?rev=1512125&r1=1512124&r2=1512125&view=diff
==============================================================================
---
cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java
(original)
+++
cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java
Fri Aug 9 01:55:00 2013
@@ -124,7 +124,7 @@ public class MtomServerTest extends Abst
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(inAtt.getDataHandler().getInputStream(), out);
out.close();
- assertEquals(37448, out.size());
+ assertEquals(27364, out.size());
}
@Test