Author: sergeyb
Date: Thu Jan 29 12:03:40 2009
New Revision: 738830
URL: http://svn.apache.org/viewvc?rev=738830&view=rev
Log:
Merged revisions 738583 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r738583 | sergeyb | 2009-01-28 18:54:21 +0000 (Wed, 28 Jan 2009) | 1 line
JAXRS : improving the support for multiparts
........
Added:
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/
- copied from r738583,
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java
- copied unchanged from r738583,
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/ContentDisposition.java
- copied unchanged from r738583,
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/ContentDisposition.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/InputStreamDataSource.java
- copied unchanged from r738583,
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/InputStreamDataSource.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java
- copied unchanged from r738583,
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/MultipartBody.java
- copied unchanged from r738583,
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/MultipartBody.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/AttachmentInputInterceptor.java
- copied unchanged from r738583,
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/AttachmentInputInterceptor.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/multipart/
- copied from r738583,
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/multipart/
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/multipart/AttachmentTest.java
- copied unchanged from r738583,
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/multipart/AttachmentTest.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/multipart/ContentDispositionTest.java
- copied unchanged from r738583,
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/multipart/ContentDispositionTest.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/multipart/MultipartBodyTest.java
- copied unchanged from r738583,
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/multipart/MultipartBodyTest.java
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/attachmentData3
- copied unchanged from r738583,
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/attachmentData3
Removed:
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MultipartID.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/MultipartInfo.java
Modified:
cxf/branches/2.1.x-fixes/ (props changed)
cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AttachmentInInterceptor.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSBindingFactory.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContext.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ActivationProvider.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/MultipartServer.java
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jan 29 12:03:40 2009
@@ -1 +1 @@
-/cxf/trunk:686333-686363,686764,686820,687096,687194,687363,687387,687463,687543,687722,687798,687814,687817,687891,687910,687914,688086,688102,688133,688596,688735,688870,689572,689596,689855,689924,690067,690289,691246,691271,691295,691338,691355,691488,691602,691646,691706,691728,692116,692157,692310,692466,692499,693653,693819,694179,694263,694417,694716,694744,694747,694795,694869,694981,694987,694993,695041,695096,695396,695484,695537,695552,695561,695619,695684,695835,695840,695868,695935,695977,696016,696094,696433,696720,697085,697868,698128,699289,700261,700507,700602,700981,701316,701783,701830,701862,702187,702205-702248,702267,702547,702561,702580,702602,702609,702616,702653,702656,702957,703191,703239,703309,703501,703513,703548,704584,704937,704997,705150,705235,705274,705340,705446,705548,705614,705692,705708,706482,706631,706675,706900,706909,707034,707089,707100,707902,708035,708044,708074,708410,708417,708550,708554,709353-709354,709425,710076,710150,71015
4,711193,711388,711410,711490,711635,711949,711975,712194,712198,712238,712272,712299,712312,712670,712893,713082,713095-713096,713099,713584,713597,713737,713804,713899,714167-714168,714245,714255,717937-717961,718281-718448,718565,718620,718640,718665,718970,719017,719210,719215-719218,719222-719273,719305,719327-719680,720053,720119-720218,720238,720293-720316,720497,721221,721241,721501,722117,722129,722412,722988,723024,723338,723378,723716-723791,724333-724372,724433-724438,724449,724481,724485,724668,724780,724782,724785,724793,724795,724940,725071,725316,725332,725335,725348,725364,725418,725425-725426,725455,725506,725554,725562,725651,725671,725688,725754,725773,725799,725839,726342,726524,726631,726634,726637,726639,726692,726724,726769,726992,727096,727445,727521,727568,727692,727754,727781,727792,728070,728087,728696,728897,729051,729430,729449,729460,729863,730082,730139,730889,730891,731598,731604,731615,731631,731635,732036,732050,732320,732363,732411,732450,
732710,732773,732827,732829,733512,733582,733901,734367,734462,734666,734762,734772,734812,734836,734965,735113,735252,735722-735723,735729,735734,735751,735782,735787,735987,736332,736343,736352,736358-736362,736408,736423,736448,736491,736621,736726,736736,736738-736739,736766,736825,736852,737032,737046,737061,737069,737124,737237,737246,737299,737356,737494,737498,737761,737817,737849,737855,737994,738166,738178,738201,738210,738242,738244,738265,738516
+/cxf/trunk:686333-686363,686764,686820,687096,687194,687363,687387,687463,687543,687722,687798,687814,687817,687891,687910,687914,688086,688102,688133,688596,688735,688870,689572,689596,689855,689924,690067,690289,691246,691271,691295,691338,691355,691488,691602,691646,691706,691728,692116,692157,692310,692466,692499,693653,693819,694179,694263,694417,694716,694744,694747,694795,694869,694981,694987,694993,695041,695096,695396,695484,695537,695552,695561,695619,695684,695835,695840,695868,695935,695977,696016,696094,696433,696720,697085,697868,698128,699289,700261,700507,700602,700981,701316,701783,701830,701862,702187,702205-702248,702267,702547,702561,702580,702602,702609,702616,702653,702656,702957,703191,703239,703309,703501,703513,703548,704584,704937,704997,705150,705235,705274,705340,705446,705548,705614,705692,705708,706482,706631,706675,706900,706909,707034,707089,707100,707902,708035,708044,708074,708410,708417,708550,708554,709353-709354,709425,710076,710150,71015
4,711193,711388,711410,711490,711635,711949,711975,712194,712198,712238,712272,712299,712312,712670,712893,713082,713095-713096,713099,713584,713597,713737,713804,713899,714167-714168,714245,714255,717937-717961,718281-718448,718565,718620,718640,718665,718970,719017,719210,719215-719218,719222-719273,719305,719327-719680,720053,720119-720218,720238,720293-720316,720497,721221,721241,721501,722117,722129,722412,722988,723024,723338,723378,723716-723791,724333-724372,724433-724438,724449,724481,724485,724668,724780,724782,724785,724793,724795,724940,725071,725316,725332,725335,725348,725364,725418,725425-725426,725455,725506,725554,725562,725651,725671,725688,725754,725773,725799,725839,726342,726524,726631,726634,726637,726639,726692,726724,726769,726992,727096,727445,727521,727568,727692,727754,727781,727792,728070,728087,728696,728897,729051,729430,729449,729460,729863,730082,730139,730889,730891,731598,731604,731615,731631,731635,732036,732050,732320,732363,732411,732450,
732710,732773,732827,732829,733512,733582,733901,734367,734462,734666,734762,734772,734812,734836,734965,735113,735252,735722-735723,735729,735734,735751,735782,735787,735987,736332,736343,736352,736358-736362,736408,736423,736448,736491,736621,736726,736736,736738-736739,736766,736825,736852,737032,737046,737061,737069,737124,737237,737246,737299,737356,737494,737498,737761,737817,737849,737855,737994,738166,738178,738201,738210,738242,738244,738265,738516,738583
Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java?rev=738830&r1=738829&r2=738830&view=diff
==============================================================================
---
cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
(original)
+++
cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
Thu Jan 29 12:03:40 2009
@@ -23,16 +23,14 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
-import java.net.URLDecoder;
-import java.util.Enumeration;
+import java.util.Collections;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import javax.activation.DataHandler;
import javax.activation.DataSource;
-import javax.mail.Header;
import javax.mail.MessagingException;
import javax.mail.internet.InternetHeaders;
@@ -72,11 +70,17 @@
private InputStream body;
private Set<DelegatingInputStream> loaded = new
HashSet<DelegatingInputStream>();
+ private List<String> supportedTypes;
public AttachmentDeserializer(Message message) {
- this.message = message;
+ this(message, Collections.singletonList("multipart/related"));
}
+ public AttachmentDeserializer(Message message, List<String>
supportedTypes) {
+ this.message = message;
+ this.supportedTypes = supportedTypes;
+ }
+
public void initializeAttachments() throws IOException {
initializeRootMessage();
@@ -95,7 +99,7 @@
throw new IllegalStateException("An InputStream must be
provided!");
}
- if (contentType.toLowerCase().indexOf("multipart/related") != -1) {
+ if (AttachmentUtil.isTypeSupported(contentType.toLowerCase(),
supportedTypes)) {
String boundaryString = findBoundaryFromContentType(contentType);
if (null == boundaryString) {
boundaryString = findBoundaryFromInputStream();
@@ -113,8 +117,7 @@
}
try {
- // TODO: Do we need to copy these headers somewhere?
- new InternetHeaders(stream);
+ message.put(InternetHeaders.class.getName(), new
InternetHeaders(stream));
} catch (MessagingException e) {
throw new RuntimeException(e);
}
@@ -188,19 +191,7 @@
throw new RuntimeException(e);
}
- String id = headers.getHeader("Content-ID", null);
- if (id != null && id.startsWith("<")) {
- id = id.substring(1, id.length() - 1);
- } else {
- //no Content-ID, set cxf default ID
- id = "Content-ID: <[email protected]";
- }
-
- id = URLDecoder.decode(id.startsWith("cid:") ? id.substring(4) : id,
"UTF-8");
-
- AttachmentImpl att = new AttachmentImpl(id);
- setupAttachment(att, headers);
- return att;
+ return (AttachmentImpl)createAttachment(headers);
}
private void cacheStreamedAttachments() throws IOException {
@@ -286,33 +277,10 @@
* @return
* @throws IOException
*/
- private void setupAttachment(AttachmentImpl att, InternetHeaders headers)
throws IOException {
- MimeBodyPartInputStream partStream = new
MimeBodyPartInputStream(stream, boundary, pbAmount);
-
- final String ct = headers.getHeader("Content-Type", null);
-
- boolean quotedPrintable = false;
-
- for (Enumeration<?> e = headers.getAllHeaders(); e.hasMoreElements();)
{
- Header header = (Header) e.nextElement();
- if
(header.getName().equalsIgnoreCase("Content-Transfer-Encoding")) {
- if (header.getValue().equalsIgnoreCase("binary")) {
- att.setXOP(true);
- } else if
(header.getValue().equalsIgnoreCase("quoted-printable")) {
- quotedPrintable = true;
- }
- }
- att.setHeader(header.getName(), header.getValue());
- }
-
- DelegatingInputStream is = new DelegatingInputStream(partStream);
- if (quotedPrintable) {
- DataSource source = new AttachmentDataSource(ct, new
QuotedPrintableDecoderStream(is));
- att.setDataHandler(new DataHandler(source));
- } else {
- DataSource source = new AttachmentDataSource(ct, is);
- att.setDataHandler(new DataHandler(source));
- }
+ private Attachment createAttachment(InternetHeaders headers) throws
IOException {
+ InputStream partStream =
+ new DelegatingInputStream(new MimeBodyPartInputStream(stream,
boundary, pbAmount));
+ return AttachmentUtil.createAttachment(partStream, headers);
}
public boolean isLazyLoading() {
Modified:
cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java?rev=738830&r1=738829&r2=738830&view=diff
==============================================================================
---
cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
(original)
+++
cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
Thu Jan 29 12:03:40 2009
@@ -19,17 +19,25 @@
package org.apache.cxf.attachment;
+import java.io.IOException;
+import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Collection;
+import java.util.Enumeration;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.mail.Header;
+import javax.mail.internet.InternetHeaders;
import org.apache.cxf.helpers.HttpHeaderHelper;
import org.apache.cxf.message.Attachment;
@@ -99,4 +107,59 @@
}
return dataHandlers == null ? new LinkedHashMap<String, DataHandler>()
: dataHandlers;
}
+
+ public static Attachment createAttachment(InputStream stream,
InternetHeaders headers)
+ throws IOException {
+
+ String id = headers.getHeader("Content-ID", null);
+ if (id != null && id.startsWith("<")) {
+ id = id.substring(1, id.length() - 1);
+ } else {
+ //no Content-ID, set cxf default ID
+ id = "Content-ID: <[email protected]";
+ }
+
+ id = URLDecoder.decode(id.startsWith("cid:") ? id.substring(4) : id,
"UTF-8");
+
+ AttachmentImpl att = new AttachmentImpl(id);
+
+ final String ct = headers.getHeader("Content-Type", null);
+
+ boolean quotedPrintable = false;
+
+ for (Enumeration<?> e = headers.getAllHeaders(); e.hasMoreElements();)
{
+ Header header = (Header) e.nextElement();
+ if
(header.getName().equalsIgnoreCase("Content-Transfer-Encoding")) {
+ if (header.getValue().equalsIgnoreCase("binary")) {
+ att.setXOP(true);
+ } else if
(header.getValue().equalsIgnoreCase("quoted-printable")) {
+ quotedPrintable = true;
+ }
+ }
+ att.setHeader(header.getName(), header.getValue());
+ }
+
+ if (quotedPrintable) {
+ DataSource source = new AttachmentDataSource(ct, new
QuotedPrintableDecoderStream(stream));
+ att.setDataHandler(new DataHandler(source));
+ } else {
+ DataSource source = new AttachmentDataSource(ct, stream);
+ att.setDataHandler(new DataHandler(source));
+ }
+
+ return att;
+ }
+
+ public static boolean isTypeSupported(String contentType, List<String>
types) {
+ if (contentType == null) {
+ return false;
+ }
+ for (String s : types) {
+ if (contentType.indexOf(s) != -1) {
+ return true;
+ }
+ }
+ return false;
+ }
+
}
Modified:
cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AttachmentInInterceptor.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AttachmentInInterceptor.java?rev=738830&r1=738829&r2=738830&view=diff
==============================================================================
---
cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AttachmentInInterceptor.java
(original)
+++
cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AttachmentInInterceptor.java
Thu Jan 29 12:03:40 2009
@@ -20,9 +20,12 @@
package org.apache.cxf.interceptor;
import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
import java.util.logging.Logger;
import org.apache.cxf.attachment.AttachmentDeserializer;
+import org.apache.cxf.attachment.AttachmentUtil;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
@@ -32,6 +35,8 @@
private static final Logger LOG =
LogUtils.getL7dLogger(AttachmentInInterceptor.class);
+ private static final List<String> TYPES =
Collections.singletonList("multipart/related");
+
/**
* contruct the soap message with attachments from mime input stream
*
@@ -49,8 +54,8 @@
}
String contentType = (String) message.get(Message.CONTENT_TYPE);
- if (contentType != null &&
contentType.toLowerCase().indexOf("multipart/related") != -1) {
- AttachmentDeserializer ad = new AttachmentDeserializer(message);
+ if (AttachmentUtil.isTypeSupported(contentType, getSupportedTypes())) {
+ AttachmentDeserializer ad = new AttachmentDeserializer(message,
getSupportedTypes());
try {
ad.initializeAttachments();
} catch (IOException e) {
@@ -62,4 +67,7 @@
public void handleFault(Message messageParam) {
}
+ protected List<String> getSupportedTypes() {
+ return TYPES;
+ }
}
Modified:
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSBindingFactory.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSBindingFactory.java?rev=738830&r1=738829&r2=738830&view=diff
==============================================================================
---
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSBindingFactory.java
(original)
+++
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSBindingFactory.java
Thu Jan 29 12:03:40 2009
@@ -23,7 +23,6 @@
import org.apache.cxf.binding.Binding;
import org.apache.cxf.binding.xml.XMLBinding;
import org.apache.cxf.binding.xml.interceptor.XMLFaultOutInterceptor;
-import org.apache.cxf.interceptor.AttachmentInInterceptor;
import org.apache.cxf.interceptor.StaxOutInterceptor;
import org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor;
import org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor;
@@ -40,8 +39,6 @@
public Binding createBinding(BindingInfo bi) {
XMLBinding binding = new XMLBinding(bi);
-
- binding.getInInterceptors().add(new AttachmentInInterceptor());
binding.getInInterceptors().add(new JAXRSInInterceptor());
binding.getOutInterceptors().add(new JAXRSOutInterceptor());
Modified:
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContext.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContext.java?rev=738830&r1=738829&r2=738830&view=diff
==============================================================================
---
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContext.java
(original)
+++
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContext.java
Thu Jan 29 12:03:40 2009
@@ -35,9 +35,6 @@
*/
public interface MessageContext {
- String INBOUND_MESSAGE_ATTACHMENTS =
"org.apache.cxf.jaxrs.attachments.inbound";
- String OUTBOUND_MESSAGE_ATTACHMENTS =
"org.apache.cxf.jaxrs.attachments.outbound";
-
Object get(Object key);
void put(Object key, Object value);
Modified:
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java?rev=738830&r1=738829&r2=738830&view=diff
==============================================================================
---
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
(original)
+++
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
Thu Jan 29 12:03:40 2009
@@ -18,16 +18,20 @@
*/
package org.apache.cxf.jaxrs.ext;
+import java.io.IOException;
+import java.io.InputStream;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Collections;
-import java.util.Map;
+import java.util.LinkedList;
+import java.util.List;
-import javax.activation.DataHandler;
+import javax.mail.internet.InternetHeaders;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.SecurityContext;
@@ -36,9 +40,10 @@
import javax.ws.rs.ext.MessageBodyWorkers;
import org.apache.cxf.attachment.AttachmentUtil;
-import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.jaxrs.ext.multipart.Attachment;
+import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
+import org.apache.cxf.jaxrs.interceptor.AttachmentInputInterceptor;
import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.apache.cxf.message.Attachment;
import org.apache.cxf.message.Message;
public class MessageContextImpl implements MessageContext {
@@ -50,8 +55,8 @@
}
public Object get(Object key) {
- if (MessageContext.INBOUND_MESSAGE_ATTACHMENTS.equals(key.toString()))
{
- return
createAttachments(MessageContext.INBOUND_MESSAGE_ATTACHMENTS);
+ if (MultipartBody.INBOUND_MESSAGE_ATTACHMENTS.equals(key.toString())) {
+ return
createAttachments(MultipartBody.INBOUND_MESSAGE_ATTACHMENTS);
}
return m.get(key);
}
@@ -111,19 +116,34 @@
throw new UnsupportedOperationException("MessageContext.put() is not
supported yet");
}
- private Map<String, DataHandler> createAttachments(String propertyName) {
+ private MultipartBody createAttachments(String propertyName) {
Object o = m.get(propertyName);
if (o != null) {
- return CastUtils.cast((Map)o);
+ return (MultipartBody)o;
}
- Collection<Attachment> attachments = m.getAttachments();
- if (attachments == null) {
- return Collections.emptyMap();
- }
- attachments.size();
- Map<String, DataHandler> dataHandlers =
AttachmentUtil.getDHMap(attachments);
- m.put(propertyName, dataHandlers);
- return dataHandlers;
+ new AttachmentInputInterceptor().handleMessage(m);
+
+ List<Attachment> newAttachments = new LinkedList<Attachment>();
+ try {
+ Attachment first = new Attachment(AttachmentUtil.createAttachment(
+ m.getContent(InputStream.class),
+
(InternetHeaders)m.get(InternetHeaders.class.getName())));
+ newAttachments.add(first);
+ } catch (IOException ex) {
+ throw new WebApplicationException(500);
+ }
+
+ Collection<org.apache.cxf.message.Attachment> childAttachments =
m.getAttachments();
+ if (childAttachments == null) {
+ childAttachments = Collections.emptyList();
+ }
+ childAttachments.size();
+ for (org.apache.cxf.message.Attachment a : childAttachments) {
+ newAttachments.add(new Attachment(a));
+ }
+ MultipartBody body = new MultipartBody(newAttachments,
getHttpHeaders().getMediaType(), false);
+ m.put(propertyName, body);
+ return body;
}
}
Modified:
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ActivationProvider.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ActivationProvider.java?rev=738830&r1=738829&r2=738830&view=diff
==============================================================================
---
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ActivationProvider.java
(original)
+++
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ActivationProvider.java
Thu Jan 29 12:03:40 2009
@@ -23,6 +23,8 @@
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
import javax.activation.DataHandler;
import javax.activation.DataSource;
@@ -35,11 +37,12 @@
import javax.ws.rs.ext.Provider;
import org.apache.cxf.jaxrs.ext.MessageContext;
+import org.apache.cxf.jaxrs.ext.multipart.Attachment;
+import org.apache.cxf.jaxrs.utils.InjectionUtils;
import org.apache.cxf.jaxrs.utils.multipart.AttachmentUtils;
-import org.apache.cxf.jaxrs.utils.multipart.MultipartInfo;
@Provider
-...@consumemime("multipart/related")
+...@consumemime({"multipart/related", "multipart/mixed" })
public class ActivationProvider implements MessageBodyReader<Object> {
@Context
@@ -47,14 +50,16 @@
public boolean isReadable(Class<?> type, Type genericType, Annotation[]
annotations) {
- if (DataHandler.class.isAssignableFrom(type) ||
DataSource.class.isAssignableFrom(type)) {
+ if (DataHandler.class.isAssignableFrom(type) ||
DataSource.class.isAssignableFrom(type)
+ || Attachment.class.isAssignableFrom(type)) {
return true;
}
if (mc == null) {
return false;
}
MediaType mt = mc.getHttpHeaders().getMediaType();
- if (mt.getType().equals("multipart") &&
mt.getSubtype().equals("related")) {
+ if (mt.getType().equals("multipart")
+ && (mt.getSubtype().equals("related") ||
mt.getSubtype().equals("mixed"))) {
return true;
}
@@ -64,21 +69,44 @@
public Object readFrom(Class<Object> c, Type t, Annotation[] anns,
MediaType mt,
MultivaluedMap<String, String> headers, InputStream
is)
throws IOException, WebApplicationException {
- MultipartInfo multipart = AttachmentUtils.getMultipart(c, anns, mt,
mc, is);
- if (multipart != null) {
- if
(InputStream.class.isAssignableFrom(multipart.getPart().getClass())) {
- MessageBodyReader<Object> r =
- mc.getProviders().getMessageBodyReader(c, t, anns,
multipart.getType());
- if (r != null) {
- return r.readFrom(c, t, anns, multipart.getType(),
headers,
- (InputStream)multipart.getPart());
- }
- } else {
- // it's either DataSource or DataHandler
- return multipart.getPart();
+
+ if (List.class.isAssignableFrom(c)) {
+ Class<?> actual = InjectionUtils.getActualType(t);
+ List<Attachment> infos = AttachmentUtils.getAttachments(mc);
+ if (actual.isAssignableFrom(Attachment.class)) {
+ return infos;
+ }
+ List<Object> objects = new ArrayList<Object>();
+ for (Attachment a : infos) {
+ objects.add(fromAttachment(a, actual, actual, anns));
}
+ return objects;
+ }
+
+ Attachment multipart = AttachmentUtils.getMultipart(c, anns, mt, mc);
+ if (multipart != null) {
+ return fromAttachment(multipart, c, t, anns);
}
throw new WebApplicationException(404);
}
+ @SuppressWarnings("unchecked")
+ private Object fromAttachment(Attachment multipart, Class<?> c, Type t,
Annotation anns[])
+ throws IOException {
+ if (DataHandler.class.isAssignableFrom(c)) {
+ return multipart.getDataHandler();
+ } else if (DataSource.class.isAssignableFrom(c)) {
+ return multipart.getDataHandler().getDataSource();
+ } else if (Attachment.class.isAssignableFrom(c)) {
+ return multipart;
+ } else {
+ MessageBodyReader<Object> r =
+ mc.getProviders().getMessageBodyReader((Class)c, t, anns,
multipart.getContentType());
+ if (r != null) {
+ return r.readFrom((Class)c, t, anns,
multipart.getContentType(), multipart.getHeaders(),
+ multipart.getDataHandler().getInputStream());
+ }
+ }
+ return null;
+ }
}
Modified:
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java?rev=738830&r1=738829&r2=738830&view=diff
==============================================================================
---
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
(original)
+++
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
Thu Jan 29 12:03:40 2009
@@ -20,23 +20,22 @@
package org.apache.cxf.jaxrs.utils.multipart;
import java.io.IOException;
-import java.io.InputStream;
import java.lang.annotation.Annotation;
+import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.logging.Logger;
-import javax.activation.DataHandler;
-import javax.activation.DataSource;
-import javax.mail.util.ByteArrayDataSource;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import org.apache.cxf.common.i18n.BundleUtils;
import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.jaxrs.ext.MessageContext;
-import org.apache.cxf.jaxrs.ext.MultipartID;
+import org.apache.cxf.jaxrs.ext.multipart.Attachment;
+import org.apache.cxf.jaxrs.ext.multipart.Multipart;
+import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
import org.apache.cxf.jaxrs.utils.AnnotationUtils;
import org.apache.cxf.jaxrs.utils.JAXRSUtils;
@@ -48,67 +47,51 @@
private AttachmentUtils() {
}
- public static Map<String, DataHandler> getAttachments(MessageContext mc) {
- return
CastUtils.cast((Map)mc.get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS));
+ public static Map<String, Attachment>
getChildAttachmentsMap(MessageContext mc) {
+ return fromListToMap(getChildAttachments(mc));
}
- // TODO : refactor this 'piece'
- public static MultipartInfo getMultipart(Class<Object> c, Annotation[]
anns,
- MediaType mt, MessageContext mc, InputStream is) throws IOException {
- InputStream stream = null;
- MultipartID id = AnnotationUtils.getAnnotation(anns,
MultipartID.class);
+ public static List<Attachment> getChildAttachments(MessageContext mc) {
+ return
((MultipartBody)mc.get(MultipartBody.INBOUND_MESSAGE_ATTACHMENTS)).getChildAttachments();
+ }
+
+ public static Map<String, Attachment> getAttachmentsMap(MessageContext mc)
{
+ return fromListToMap(getAttachments(mc));
+ }
+
+ public static List<Attachment> getAttachments(MessageContext mc) {
+ return
((MultipartBody)mc.get(MultipartBody.INBOUND_MESSAGE_ATTACHMENTS)).getAllAttachments();
+ }
+
+ public static Attachment getMultipart(Class<Object> c, Annotation[] anns,
+ MediaType mt, MessageContext mc) throws IOException {
+ List<Attachment> infos = AttachmentUtils.getAttachments(mc);
+ Multipart id = AnnotationUtils.getAnnotation(anns, Multipart.class);
if (id != null) {
- String contentId = id.value();
- String rootId = mt.getParameters().get("start");
- if (rootId != null) {
- rootId = rootId.replace("\"", "").replace("'", "");
- if (rootId.equalsIgnoreCase(contentId)) {
- stream = is;
+ for (Attachment a : getAttachments(mc)) {
+ if (a.getContentId().equals(id.value())) {
+ checkMediaTypes(a.getContentType(), id.type());
+ return a;
}
}
- if (stream == null) {
- // TODO: looks like the lazy attachments collection can only
be accessed this way
- for (Map.Entry<String, DataHandler> entry :
getAttachments(mc).entrySet()) {
- if (entry.getKey().equals(contentId)) {
- DataHandler dh = entry.getValue();
- MediaType handlerType = dh.getContentType() == null
- ? WILDCARD_TYPE :
MediaType.valueOf(dh.getContentType());
- checkMediaTypes(handlerType, id.type());
- Object o = DataHandler.class.isAssignableFrom(c) ? dh
- : DataSource.class.isAssignableFrom(c) ?
dh.getDataSource()
- : dh.getInputStream();
- return new MultipartInfo(o, handlerType);
- }
- }
- org.apache.cxf.common.i18n.Message errorMsg =
- new
org.apache.cxf.common.i18n.Message("MULTTIPART_ID_NOT_FOUND",
- BUNDLE,
- contentId,
- mt.toString());
- LOG.warning(errorMsg.toString());
- }
- } else {
- stream = is;
+ org.apache.cxf.common.i18n.Message errorMsg =
+ new
org.apache.cxf.common.i18n.Message("MULTTIPART_ID_NOT_FOUND",
+ BUNDLE,
+ id.value(),
+ mt.toString());
+ LOG.warning(errorMsg.toString());
+
}
- if (stream != null) {
- MediaType partType = WILDCARD_TYPE;
- String ct = mt.getParameters().get("type");
- if (ct != null) {
- partType = MediaType.valueOf(ct.replace("\"", "").replace("'",
""));
- }
- if (id != null) {
- checkMediaTypes(partType, id.type());
- }
- if (DataSource.class.isAssignableFrom(c)) {
- return new MultipartInfo(new ByteArrayDataSource(stream,
mt.toString()), partType);
- } else if (DataHandler.class.isAssignableFrom(c)) {
- return new MultipartInfo(new DataHandler(new
ByteArrayDataSource(stream, mt.toString())),
- partType);
- } else {
- return new MultipartInfo(stream, partType);
- }
+
+ return infos.size() > 0 ? infos.get(0) : null;
+ }
+
+ private static Map<String, Attachment> fromListToMap(List<Attachment>
atts) {
+ Map<String, Attachment> map = new LinkedHashMap<String, Attachment>();
+ for (Attachment a : atts) {
+ map.put(a.getContentId(), a);
}
- return null;
+ return map;
}
private static void checkMediaTypes(MediaType mt1, String mt2) {
Modified:
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java?rev=738830&r1=738829&r2=738830&view=diff
==============================================================================
---
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
(original)
+++
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
Thu Jan 29 12:03:40 2009
@@ -42,74 +42,114 @@
@Test
public void testBookAsRootAttachmentStreamSource() throws Exception {
- String address = "http://localhost:9080/bookstore/books/stream";
+ String address = "http://localhost:9085/bookstore/books/stream";
doAddBook(address, "attachmentData", 200);
}
@Test
+ public void testBookAsRootAttachmentStreamSourceNoContentId() throws
Exception {
+ String address = "http://localhost:9085/bookstore/books/stream";
+ doAddBook(address, "attachmentData3", 200);
+ }
+
+ @Test
public void testBookAsRootAttachmentInputStream() throws Exception {
- String address = "http://localhost:9080/bookstore/books/istream";
+ String address = "http://localhost:9085/bookstore/books/istream";
doAddBook(address, "attachmentData", 200);
}
@Test
public void testBookAsMessageContextDataHandler() throws Exception {
- String address = "http://localhost:9080/bookstore/books/mchandlers";
+ String address = "http://localhost:9085/bookstore/books/mchandlers";
+ doAddBook(address, "attachmentData", 200);
+ }
+
+ @Test
+ public void testBookAsMessageContextAttachments() throws Exception {
+ String address = "http://localhost:9085/bookstore/books/attachments";
+ doAddBook(address, "attachmentData", 200);
+ }
+
+ @Test
+ public void testBookAsMessageContextAttachment() throws Exception {
+ String address = "http://localhost:9085/bookstore/books/attachment";
doAddBook(address, "attachmentData", 200);
}
@Test
public void testAddBookAsRootAttachmentJAXB() throws Exception {
- String address = "http://localhost:9080/bookstore/books/jaxb";
+ String address = "http://localhost:9085/bookstore/books/jaxb";
doAddBook(address, "attachmentData", 200);
}
@Test
public void testAddBookAsDataSource() throws Exception {
- String address = "http://localhost:9080/bookstore/books/dsource";
+ String address = "http://localhost:9085/bookstore/books/dsource";
doAddBook(address, "attachmentData", 200);
}
@Test
public void testAddBookAsDataSource2() throws Exception {
- String address = "http://localhost:9080/bookstore/books/dsource2";
+ String address = "http://localhost:9085/bookstore/books/dsource2";
doAddBook(address, "attachmentData", 200);
}
@Test
public void testAddBookAsJAXB2() throws Exception {
- String address = "http://localhost:9080/bookstore/books/jaxb2";
+ String address = "http://localhost:9085/bookstore/books/jaxb2";
+ doAddBook(address, "attachmentData", 200);
+ }
+
+ @Test
+ public void testAddBookAsListOfAttachments() throws Exception {
+ String address =
"http://localhost:9085/bookstore/books/listattachments";
+ doAddBook(address, "attachmentData", 200);
+ }
+
+ @Test
+ public void testAddBookAsListOfStreams() throws Exception {
+ String address = "http://localhost:9085/bookstore/books/lististreams";
doAddBook(address, "attachmentData", 200);
}
@Test
public void testAddBookAsJAXBJSON() throws Exception {
- String address = "http://localhost:9080/bookstore/books/jaxbjson";
+ String address = "http://localhost:9085/bookstore/books/jaxbjson";
doAddBook(address, "attachmentData2", 200);
}
@Test
+ public void testAddBookAsJAXBJSONMixed() throws Exception {
+ String address = "http://localhost:9085/bookstore/books/jaxbjson";
+ doAddBook("multipart/mixed", address, "attachmentData2", 200);
+ }
+
+ @Test
public void testConsumesMismatch() throws Exception {
- String address = "http://localhost:9080/bookstore/books/mismatch1";
+ String address = "http://localhost:9085/bookstore/books/mismatch1";
doAddBook(address, "attachmentData2", 415);
}
@Test
public void testConsumesMismatch2() throws Exception {
- String address = "http://localhost:9080/bookstore/books/mismatch2";
+ String address = "http://localhost:9085/bookstore/books/mismatch2";
doAddBook(address, "attachmentData2", 415);
}
@Test
public void testAddBookAsDataHandler() throws Exception {
- String address = "http://localhost:9080/bookstore/books/dhandler";
+ String address = "http://localhost:9085/bookstore/books/dhandler";
doAddBook(address, "attachmentData", 200);
}
private void doAddBook(String address, String resourceName, int status)
throws Exception {
+ doAddBook("multipart/related", address, resourceName, status);
+ }
+
+ private void doAddBook(String type, String address, String resourceName,
int status) throws Exception {
PostMethod post = new PostMethod(address);
- String ct = "multipart/related; type=\"text/xml\"; " +
"start=\"rootPart\"; "
+ String ct = type + "; type=\"text/xml\"; " + "start=\"rootPart\"; "
+ "boundary=\"----=_Part_4_701508.1145579811786\"";
post.setRequestHeader("Content-Type", ct);
InputStream is =
Modified:
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/MultipartServer.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/MultipartServer.java?rev=738830&r1=738829&r2=738830&view=diff
==============================================================================
---
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/MultipartServer.java
(original)
+++
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/MultipartServer.java
Thu Jan 29 12:03:40 2009
@@ -31,7 +31,7 @@
//default lifecycle is per-request, change it to singleton
sf.setResourceProvider(MultipartStore.class,
new SingletonResourceProvider(new
MultipartStore()));
- sf.setAddress("http://localhost:9080/");
+ sf.setAddress("http://localhost:9085/");
sf.create();
}
Modified:
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java?rev=738830&r1=738829&r2=738830&view=diff
==============================================================================
---
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
(original)
+++
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
Thu Jan 29 12:03:40 2009
@@ -21,6 +21,8 @@
import java.io.InputStream;
+import java.util.Collection;
+import java.util.List;
import java.util.Map;
import javax.activation.DataHandler;
@@ -37,7 +39,8 @@
import javax.xml.transform.stream.StreamSource;
import org.apache.cxf.jaxrs.ext.MessageContext;
-import org.apache.cxf.jaxrs.ext.MultipartID;
+import org.apache.cxf.jaxrs.ext.multipart.Attachment;
+import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.apache.cxf.jaxrs.utils.multipart.AttachmentUtils;
@Path("/bookstore")
@@ -78,8 +81,8 @@
@Path("/books/jaxb2")
@ConsumeMime("multipart/related;type=\"text/xml\"")
@ProduceMime("text/xml")
- public Response addBookParts(@MultipartID("rootPart") Book b1,
- @MultipartID("book2") Book b2)
+ public Response addBookParts(@Multipart("rootPart") Book b1,
+ @Multipart("book2") Book b2)
throws Exception {
if (b1.equals(b2)) {
throw new WebApplicationException();
@@ -95,8 +98,8 @@
@Path("/books/jaxbjson")
@ProduceMime("text/xml")
public Response addBookJaxbJson(
- @MultipartID(value = "rootPart", type = "text/xml") Book2 b1,
- @MultipartID(value = "book2", type = "application/json") Book b2)
+ @Multipart(value = "rootPart", type = "text/xml") Book2 b1,
+ @Multipart(value = "book2", type = "application/json") Book b2)
throws Exception {
if (!"CXF in Action".equals(b1.getName())
|| !"CXF in Action - 2".equals(b2.getName())) {
@@ -109,8 +112,8 @@
@POST
@Path("/books/dsource2")
@ProduceMime("text/xml")
- public Response addBookFromDataSource2(@MultipartID("rootPart") DataSource
ds1,
- @MultipartID("book2") DataSource
ds2)
+ public Response addBookFromDataSource2(@Multipart("rootPart") DataSource
ds1,
+ @Multipart("book2") DataSource ds2)
throws Exception {
Response r1 = readBookFromInputStream(ds1.getInputStream());
Response r2 = readBookFromInputStream(ds2.getInputStream());
@@ -126,6 +129,42 @@
}
@POST
+ @Path("/books/listattachments")
+ @ProduceMime("text/xml")
+ public Response addBookFromListOfAttachments(List<Attachment> atts)
+ throws Exception {
+ Response r1 =
readBookFromInputStream(atts.get(0).getDataHandler().getInputStream());
+ Response r2 =
readBookFromInputStream(atts.get(2).getDataHandler().getInputStream());
+ Book b1 = (Book)r1.getEntity();
+ Book b2 = (Book)r2.getEntity();
+ if (b1.equals(b2)) {
+ throw new WebApplicationException();
+ }
+ if (!b1.getName().equals(b2.getName())) {
+ throw new WebApplicationException();
+ }
+ return r1;
+ }
+
+ @POST
+ @Path("/books/lististreams")
+ @ProduceMime("text/xml")
+ public Response addBookFromListOfStreams(List<InputStream> atts)
+ throws Exception {
+ Response r1 = readBookFromInputStream(atts.get(0));
+ Response r2 = readBookFromInputStream(atts.get(2));
+ Book b1 = (Book)r1.getEntity();
+ Book b2 = (Book)r2.getEntity();
+ if (b1.equals(b2)) {
+ throw new WebApplicationException();
+ }
+ if (!b1.getName().equals(b2.getName())) {
+ throw new WebApplicationException();
+ }
+ return r1;
+ }
+
+ @POST
@Path("/books/dhandler")
@ProduceMime("text/xml")
public Response addBookFromDataHandler(DataHandler dh) throws Exception {
@@ -133,13 +172,33 @@
}
@POST
+ @Path("/books/attachment")
+ @ProduceMime("text/xml")
+ public Response addBookFromAttachment(Attachment a) throws Exception {
+ return readBookFromInputStream(a.getDataHandler().getInputStream());
+ }
+
+ @POST
@Path("/books/mchandlers")
@ProduceMime("text/xml")
public Response addBookFromMessageContext() throws Exception {
- Map<String, DataHandler> handlers =
AttachmentUtils.getAttachments(context);
- for (Map.Entry<String, DataHandler> entry : handlers.entrySet()) {
+ Map<String, Attachment> handlers =
AttachmentUtils.getAttachmentsMap(context);
+ for (Map.Entry<String, Attachment> entry : handlers.entrySet()) {
if (entry.getKey().equals("book2")) {
- return
readBookFromInputStream(entry.getValue().getInputStream());
+ return
readBookFromInputStream(entry.getValue().getDataHandler().getInputStream());
+ }
+ }
+ throw new WebApplicationException(500);
+ }
+
+ @POST
+ @Path("/books/attachments")
+ @ProduceMime("text/xml")
+ public Response addBookFromAttachments() throws Exception {
+ Collection<Attachment> handlers =
AttachmentUtils.getChildAttachments(context);
+ for (Attachment a : handlers) {
+ if (a.getContentId().equals("book2")) {
+ return
readBookFromInputStream(a.getDataHandler().getInputStream());
}
}
throw new WebApplicationException(500);
@@ -164,7 +223,7 @@
@POST
@Path("/books/mismatch2")
@ProduceMime("text/xml")
- public Response addBookMismatched2(@MultipartID(value = "rootPart", type =
"f/b") Book b) {
+ public Response addBookMismatched2(@Multipart(value = "rootPart", type =
"f/b") Book b) {
throw new WebApplicationException();
}