cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1206800 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/m...
Date Sun, 27 Nov 2011 18:39:45 GMT
Author: sergeyb
Date: Sun Nov 27 18:39:42 2011
New Revision: 1206800

URL: http://svn.apache.org/viewvc?rev=1206800&view=rev
Log:
[CXF-3936] Renabling the test Benson added, thanks

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java?rev=1206800&r1=1206799&r2=1206800&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Multipart.java
Sun Nov 27 18:39:42 2011
@@ -43,7 +43,7 @@ public @interface Multipart {
      * 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>,
+     * with status 400. If this option is set to <strong>false</strong>,
      * the parameter is set to <strong>null</strong>.
      */
     boolean errorIfMissing() default true; 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java?rev=1206800&r1=1206799&r2=1206800&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
Sun Nov 27 18:39:42 2011
@@ -105,7 +105,7 @@ public class FormEncodingProvider implem
             }
             
             MultivaluedMap<String, String> params = createMap(clazz);
-            populateMap(params, is, mt, !keepEncoded(annotations));
+            populateMap(params, annotations, is, mt, !keepEncoded(annotations));
             validateMap(params);
             
             persistParamsOnMessage(params);
@@ -150,11 +150,14 @@ public class FormEncodingProvider implem
      * @return a Map of parameters.
      */
     protected void populateMap(MultivaluedMap<String, String> params, 
-                               InputStream is, MediaType mt, boolean decode) {
+                               Annotation[] anns,
+                               InputStream is, 
+                               MediaType mt, 
+                               boolean decode) {
         if (mt.isCompatible(MediaType.MULTIPART_FORM_DATA_TYPE)) {
             MultipartBody body = 
                 AttachmentUtils.getMultipartBody(mc, attachmentDir, attachmentThreshold,
attachmentMaxSize);
-            FormUtils.populateMapFromMultipart(params, body, decode);
+            FormUtils.populateMapFromMultipart(params, anns, body, decode);
         } else {
             String enc = HttpUtils.getEncoding(mt, "UTF-8");
             FormUtils.populateMapFromString(params, 

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=1206800&r1=1206799&r2=1206800&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
Sun Nov 27 18:39:42 2011
@@ -163,11 +163,19 @@ public class MultipartProvider extends A
             return new MultipartBody(infos);
         }
         
-        Attachment multipart = AttachmentUtils.getMultipart(c, anns, mt, infos);
+        Multipart id = AnnotationUtils.getAnnotation(anns, Multipart.class);
+        Attachment multipart = AttachmentUtils.getMultipart(c, id, mt, infos);
         if (multipart != null) {
             return fromAttachment(multipart, c, t, anns);
+        } else if (id != null && !id.errorIfMissing()) {
+            /*
+             * If user asked for a null, give them a null. 
+             */
+            return null;
         }
+        
         throw new WebApplicationException(400);
+        
     }
     
     private Class<?> getActualType(Type type, int pos) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java?rev=1206800&r1=1206799&r2=1206800&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java Sun
Nov 27 18:39:42 2011
@@ -23,6 +23,7 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.lang.annotation.Annotation;
 import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.Iterator;
@@ -40,6 +41,7 @@ import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.interceptor.LoggingInInterceptor;
 import org.apache.cxf.jaxrs.ext.multipart.Attachment;
 import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition;
+import org.apache.cxf.jaxrs.ext.multipart.Multipart;
 import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
 import org.apache.cxf.phase.PhaseInterceptorChain;
 
@@ -145,6 +147,7 @@ public final class FormUtils {
     }
     
     public static void populateMapFromMultipart(MultivaluedMap<String, String> params,
+                                                Annotation[] anns,
                                                 MultipartBody body, 
                                                 boolean decode) {
         List<Attachment> atts = body.getAllAttachments();
@@ -152,7 +155,13 @@ public final class FormUtils {
             ContentDisposition cd = a.getContentDisposition();
             if (cd == null || !MULTIPART_FORM_DATA_TYPE.equalsIgnoreCase(cd.getType())
                 || cd.getParameter("name") == null) {
-                throw new WebApplicationException(415);
+                Multipart id = AnnotationUtils.getAnnotation(anns, Multipart.class);
+                
+                if (id == null || id.errorIfMissing()) {
+                    throw new WebApplicationException(400);
+                } else {
+                    return;
+                }
             }
             String name = cd.getParameter("name").replace("\"", "").replace("'", "");
             try {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1206800&r1=1206799&r2=1206800&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Sun
Nov 27 18:39:42 2011
@@ -745,7 +745,7 @@ public final class JAXRSUtils {
                 if (mt != null && "multipart".equalsIgnoreCase(mt.getType()) 
                     && MediaType.MULTIPART_FORM_DATA_TYPE.isCompatible(mt)) {
                     MultipartBody body = AttachmentUtils.getMultipartBody(mc);
-                    FormUtils.populateMapFromMultipart(params, body, decode);
+                    FormUtils.populateMapFromMultipart(params, paramAnns, body, decode);
                 } else {
                     org.apache.cxf.common.i18n.Message errorMsg = 
                         new org.apache.cxf.common.i18n.Message("WRONG_FORM_MEDIA_TYPE", 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java?rev=1206800&r1=1206799&r2=1206800&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
Sun Nov 27 18:39:42 2011
@@ -40,7 +40,6 @@ import org.apache.cxf.jaxrs.ext.multipar
 import org.apache.cxf.jaxrs.ext.multipart.Multipart;
 import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
-import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.FormUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 
@@ -98,9 +97,11 @@ public final class AttachmentUtils {
                                 attachmentMaxSize).getAllAttachments();
     }
     
-    public static Attachment getMultipart(Class<Object> c, Annotation[] anns, 
-        MediaType mt, List<Attachment> infos) throws IOException {
-        Multipart id = AnnotationUtils.getAnnotation(anns, Multipart.class);
+    public static Attachment getMultipart(Class<Object> c, 
+                                          Multipart id, 
+                                          MediaType mt, 
+                                          List<Attachment> infos) throws IOException
{
+        
         if (id != null) {
             for (Attachment a : infos) {
                 if (matchAttachmentId(a, id, mt)) {
@@ -108,20 +109,16 @@ public final class AttachmentUtils {
                     return a;    
                 }
             }
-            if (!id.errorIfMissing()) {
-                /*
-                 * If user asked for a null, give them a null. 
-                 */
-                return null;
+            if (id.errorIfMissing()) {
+                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());
+                throw new WebApplicationException(
+                          new MultipartReadException(id.value(), id.type(), errorMsg.toString()));
             }
-            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());
-            throw new WebApplicationException(
-                      new MultipartReadException(id.value(), id.type(), errorMsg.toString()));
         }
         
         return infos.size() > 0 ? infos.get(0) : null; 
@@ -139,15 +136,19 @@ public final class AttachmentUtils {
     }
 
     @SuppressWarnings("unchecked")
-    public static <T> MultivaluedMap<String, T> populateFormMap(MessageContext
mc, Class<T> cls) {
+    public static <T> MultivaluedMap<String, T> populateFormMap(MessageContext
mc, 
+                                                                Class<T> cls,
+                                                                boolean errorIfMissing) {
         MultivaluedMap<String, T> data = new MetadataMap<String, T>();
-        FormUtils.populateMapFromMultipart((MultivaluedMap)data, 
-                                           AttachmentUtils.getMultipartBody(mc), true);
+        FormUtils.populateMapFromMultipart((MultivaluedMap)data,
+                                           new Annotation[]{},
+                                           AttachmentUtils.getMultipartBody(mc), 
+                                           true);
         return data;
     }
     
     public static MultivaluedMap<String, String> populateFormMap(MessageContext mc)
{
-        return populateFormMap(mc, String.class);
+        return populateFormMap(mc, String.class, true);
     }
     
     private static Map<String, Attachment> fromListToMap(List<Attachment> atts)
{

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java?rev=1206800&r1=1206799&r2=1206800&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
Sun Nov 27 18:39:42 2011
@@ -335,17 +335,17 @@ 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";
+        String address = "http://localhost:" + PORT + "/bookstore/books/testnullpart";
         WebClient client = WebClient.create(address);
+        WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(10000000);
         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());
+        assertEquals("nobody home", IOUtils.readStringFromStream((InputStream)r.getEntity()));
     }
     
     @Test



Mime
View raw message