You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2011/11/27 19:42:23 UTC
svn commit: r1206801 - in /cxf/branches/2.4.x-fixes: ./
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/
systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Author: sergeyb
Date: Sun Nov 27 18:42:22 2011
New Revision: 1206801
URL: http://svn.apache.org/viewvc?rev=1206801&view=rev
Log:
Merged revisions 1205996-1205997 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1205996 | bimargulies | 2011-11-24 22:19:29 +0000 (Thu, 24 Nov 2011) | 1 line
Add parameter for mapping missing parts to null.
........
r1205997 | bimargulies | 2011-11-24 22:19:47 +0000 (Thu, 24 Nov 2011) | 1 line
Try to invent nullable multipart parameters. Test commented out because I can't figure it out.
........
Modified:
cxf/branches/2.4.x-fixes/ (props changed)
cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java
cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Nov 27 18:42:22 2011
@@ -1 +1 @@
-/cxf/trunk:1205786,1205830
+/cxf/trunk:1205786,1205830,1205996-1205997
Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java?rev=1206801&r1=1206800&r2=1206801&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java (original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java Sun Nov 27 18:42:22 2011
@@ -24,9 +24,27 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+/**
+ * Annotate a JAX-RS function parameter to receive data from a multipart 'part'.
+ **/
@Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface Multipart {
+ /**
+ * The name of the MIME part to map to this parameter. The default is
+ * the unnamed default part.
+ **/
String value() default "";
+ /**
+ * Select the part by MIME type. The default is to match any MIME type.
+ */
String type() default "*/*";
+ /**
+ * How to handle a missing part. By default, if no part matches,
+ * the {@link org.apache.cxf.jaxrs.provider.MultipartProvider}
+ * throws a {@link javax.ws.rs.WebApplicationException}
+ * with status 404. If this option is set to <strong>false</strong>,
+ * the parameter is set to <strong>null</strong>.
+ */
+ boolean errorIfMissing() default true;
}
Modified: cxf/branches/2.4.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.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java?rev=1206801&r1=1206800&r2=1206801&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java (original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java Sun Nov 27 18:42:22 2011
@@ -108,6 +108,12 @@ public final class AttachmentUtils {
return a;
}
}
+ if (!id.errorIfMissing()) {
+ /*
+ * If user asked for a null, give them a null.
+ */
+ return null;
+ }
org.apache.cxf.common.i18n.Message errorMsg =
new org.apache.cxf.common.i18n.Message("MULTTIPART_ID_NOT_FOUND",
BUNDLE,
Modified: cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1206801&r1=1206800&r2=1206801&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Sun Nov 27 18:42:22 2011
@@ -989,7 +989,7 @@ public class BookStore {
}
@XmlJavaTypeAdapter(BookInfoAdapter2.class)
- static interface BookInfoInterface {
+ interface BookInfoInterface {
String getName();
long getId();
Modified: cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java?rev=1206801&r1=1206800&r2=1206801&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java (original)
+++ cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java Sun Nov 27 18:42:22 2011
@@ -28,6 +28,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -36,6 +37,7 @@ import javax.imageio.ImageIO;
import javax.mail.util.ByteArrayDataSource;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
@@ -333,12 +335,25 @@ public class JAXRSMultipartTest extends
return ImageIO.read(getClass().getResource(name));
}
+ @org.junit.Ignore
+ @Test
+ public void testNullableParams() throws Exception {
+ String address = "http://localhost:" + PORT + "/books/testnullpart";
+ WebClient client = WebClient.create(address);
+ client.type("multipart/form-data").accept("text/plain");
+ List<Attachment> atts = new LinkedList<Attachment>();
+ atts.add(new Attachment("somepart", "text/plain", "hello there"));
+ Response r = client.postCollection(atts, Attachment.class);
+ assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
+ assertEquals("nobody home", r.getEntity());
+ }
+
@Test
public void testAddBookJaxbJsonImageWebClient() throws Exception {
String address = "http://localhost:" + PORT + "/bookstore/books/jaxbjsonimage";
WebClient client = WebClient.create(address);
client.type("multipart/mixed").accept("multipart/mixed");
-
+
Book jaxb = new Book("jaxb", 1L);
Book json = new Book("json", 2L);
InputStream is1 =
Modified: cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java?rev=1206801&r1=1206800&r2=1206801&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java (original)
+++ cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java Sun Nov 27 18:42:22 2011
@@ -144,6 +144,18 @@ public class MultipartStore {
}
@POST
+ @Path("/books/testnullpart")
+ @Consumes("multipart/form-data")
+ @Produces("text/plain")
+ public String testNullPart(@Multipart(value = "someid", errorIfMissing = false) String value) {
+ if (value != null) {
+ return value;
+ } else {
+ return "nobody home";
+ }
+ }
+
+ @POST
@Path("/books/jaxbjsonimage")
@Consumes("multipart/mixed")
@Produces("multipart/mixed")