cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1201708 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/model/wadl/ main/java/org/apache/cxf/jaxrs/utils/ test/java/org/apache/cxf/jaxrs/model/wadl/ test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/
Date Mon, 14 Nov 2011 13:56:57 GMT
Author: sergeyb
Date: Mon Nov 14 13:56:57 2011
New Revision: 1201708

URL: http://svn.apache.org/viewvc?rev=1201708&view=rev
Log:
[CXF-3903] Support for primitive multipart/form-data parameters

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.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/ResourceUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/FormInterface.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Book.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=1201708&r1=1201707&r2=1201708&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
Mon Nov 14 13:56:57 2011
@@ -317,11 +317,13 @@ public class WadlGenerator implements Re
         Map<Parameter, Object> classParams = new HashMap<Parameter, Object>();
         List<Method> paramMethods = cri.getParameterMethods();
         for (Method m : paramMethods) {
-            classParams.put(ResourceUtils.getParameter(0, m.getAnnotations()), m);
+            classParams.put(ResourceUtils.getParameter(0, m.getAnnotations(),
+                                                       m.getParameterTypes()[0]), m);
         }
         List<Field> fieldParams = cri.getParameterFields();
         for (Field f : fieldParams) {
-            classParams.put(ResourceUtils.getParameter(0, f.getAnnotations()), f);
+            classParams.put(ResourceUtils.getParameter(0, f.getAnnotations(),
+                                                       f.getType()), f);
         }
         return classParams;
     }

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=1201708&r1=1201707&r2=1201708&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 Mon
Nov 14 13:56:57 2011
@@ -200,7 +200,8 @@ public final class JAXRSUtils {
         MultivaluedMap<String, String> values = 
             (MultivaluedMap<String, String>)message.get(URITemplate.TEMPLATE_PARAMETERS);
         for (Method m : cri.getParameterMethods()) {
-            Parameter p = ResourceUtils.getParameter(0, m.getAnnotations());
+            Parameter p = ResourceUtils.getParameter(0, m.getAnnotations(), 
+                                                     m.getParameterTypes()[0]);
             Object o = createHttpParameterValue(p, 
                                                 m.getParameterTypes()[0],
                                                 m.getGenericParameterTypes()[0],
@@ -212,7 +213,8 @@ public final class JAXRSUtils {
         }
         // Param fields
         for (Field f : cri.getParameterFields()) {
-            Parameter p = ResourceUtils.getParameter(0, f.getAnnotations());
+            Parameter p = ResourceUtils.getParameter(0, f.getAnnotations(), 
+                                                     f.getType());
             Object o = createHttpParameterValue(p, 
                                                 f.getType(),
                                                 f.getGenericType(),

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java?rev=1201708&r1=1201707&r2=1201708&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
Mon Nov 14 13:56:57 2011
@@ -73,6 +73,7 @@ import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.jaxb.JAXBUtils;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.ext.multipart.Multipart;
 import org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider;
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
@@ -277,15 +278,16 @@ public final class ResourceUtils {
         if (paramAnns.length == 0) {
             return CastUtils.cast(Collections.emptyList(), Parameter.class);
         }
+        Class<?>[] types = resourceMethod.getParameterTypes();
         List<Parameter> params = new ArrayList<Parameter>(paramAnns.length);
         for (int i = 0; i < paramAnns.length; i++) {
-            Parameter p = getParameter(i, paramAnns[i]);
+            Parameter p = getParameter(i, paramAnns[i], types[i]);
             params.add(p);
         }
         return params;
     }
     
-    public static Parameter getParameter(int index, Annotation[] anns) {
+    public static Parameter getParameter(int index, Annotation[] anns, Class<?> type)
{
         
         Context ctx = AnnotationUtils.getAnnotation(anns, Context.class);
         if (ctx != null) {
@@ -316,10 +318,19 @@ public final class ResourceUtils {
             return new Parameter(ParameterType.MATRIX, index, m.value(), isEncoded, dValue);
         }  
     
+        Parameter formParam = null;
         FormParam f = AnnotationUtils.getAnnotation(anns, FormParam.class);
         if (f != null) {
-            return new Parameter(ParameterType.FORM, index, f.value(), isEncoded, dValue);
-        }  
+            formParam = new Parameter(ParameterType.FORM, index, f.value(), isEncoded, dValue);
+        } else {    
+            Multipart multipart = AnnotationUtils.getAnnotation(anns, Multipart.class);
+            if (multipart != null && InjectionUtils.isPrimitive(type)) {
+                formParam = new Parameter(ParameterType.FORM, index, multipart.value(), isEncoded,
dValue);
+            }
+        }
+        if (formParam != null) {
+            return formParam;
+        }
         
         HeaderParam h = AnnotationUtils.getAnnotation(anns, HeaderParam.class);
         if (h != null) {
@@ -564,7 +575,7 @@ public final class ResourceUtils {
             if (AnnotationUtils.isContextClass(params[i])) {
                 values[i] = JAXRSUtils.createContextValue(m, genericTypes[i], params[i]);
             } else {
-                Parameter p = ResourceUtils.getParameter(i, anns[i]);
+                Parameter p = ResourceUtils.getParameter(i, anns[i], params[i]);
                 values[i] = JAXRSUtils.createHttpParameterValue(
                                 p, params[i], genericTypes[i], anns[i], m, templateValues,
null);
             }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/FormInterface.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/FormInterface.java?rev=1201708&r1=1201707&r2=1201708&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/FormInterface.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/FormInterface.java
Mon Nov 14 13:56:57 2011
@@ -27,6 +27,8 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 
+import org.apache.cxf.jaxrs.ext.multipart.Multipart;
+
 public interface FormInterface {
     @Path("/form1")
     @POST
@@ -44,4 +46,11 @@ public interface FormInterface {
     @Produces(MediaType.TEXT_PLAIN)
     String form3(@PathParam("id") String id, 
                  @FormParam("field1") String f1, @FormParam("field2") String f2);
+    
+    @Path("/form4/{id}")
+    @POST
+    @Consumes("multipart/form-data")
+    @Produces(MediaType.TEXT_PLAIN)
+    String form4(@PathParam("id") String id, 
+                 @Multipart("field1") String f1, @Multipart("field2") String f2);
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java?rev=1201708&r1=1201707&r2=1201708&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Mon Nov 14 13:56:57 2011
@@ -483,14 +483,15 @@ public class WadlGeneratorTest extends A
                          new Param("mid", "matrix", "xs:int"));
         checkDocs(resourceEls.get(5), "", "Book subresource", ""); 
         // should have 4 child resources
-        List<Element> subResourceEls = getElements(resourceEls.get(5), "resource",
5);
+        List<Element> subResourceEls = getElements(resourceEls.get(5), "resource",
6);
 
         assertEquals("/book", subResourceEls.get(0).getAttribute("path"));
         assertEquals("/form1", subResourceEls.get(1).getAttribute("path"));
         assertEquals("/form2", subResourceEls.get(2).getAttribute("path"));
         assertEquals("/form3/{id}", subResourceEls.get(3).getAttribute("path"));
-        assertEquals("/chapter/{cid}", subResourceEls.get(4).getAttribute("path"));
-        checkDocs(subResourceEls.get(4), "", "Chapter subresource", "");
+        assertEquals("/form4/{id}", subResourceEls.get(4).getAttribute("path"));
+        assertEquals("/chapter/{cid}", subResourceEls.get(5).getAttribute("path"));
+        checkDocs(subResourceEls.get(5), "", "Chapter subresource", "");
         // verify book-subresource /book resource
         // GET 
         verifyGetResourceMethod(subResourceEls.get(0), bookEl, null);
@@ -515,9 +516,9 @@ public class WadlGeneratorTest extends A
         
         
         // verify subresource /chapter/{id}
-        List<Element> chapterMethodEls = getElements(subResourceEls.get(4), "resource",
1);
+        List<Element> chapterMethodEls = getElements(subResourceEls.get(5), "resource",
1);
         assertEquals("/id", chapterMethodEls.get(0).getAttribute("path"));
-        verifyParameters(subResourceEls.get(4), 1, 
+        verifyParameters(subResourceEls.get(5), 1, 
                          new Param("cid", "template", "xs:int"));
         // GET
         verifyGetResourceMethod(chapterMethodEls.get(0), chapterEl, "Get the chapter");

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Book.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Book.java?rev=1201708&r1=1201707&r2=1201708&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Book.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/jaxb/Book.java
Mon Nov 14 13:56:57 2011
@@ -79,5 +79,9 @@ public class Book implements FormInterfa
     public String form3(String identificator, String f1, String f2) {
         return "";
     }
+
+    public String form4(String theid, String f1, String f2) {
+        return "";
+    }
     
 }



Mime
View raw message