cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1221709 - in /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs: model/wadl/WadlGenerator.java utils/ResourceUtils.java
Date Wed, 21 Dec 2011 13:11:18 GMT
Author: sergeyb
Date: Wed Dec 21 13:11:18 2011
New Revision: 1221709

URL: http://svn.apache.org/viewvc?rev=1221709&view=rev
Log:
[CXF-3903] Fixing a regression to do with converting Multipart params to FormParams too early
for the benefit of WADLGenerator

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/ResourceUtils.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=1221709&r1=1221708&r2=1221709&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
Wed Dec 21 13:11:18 2011
@@ -85,6 +85,7 @@ import org.apache.cxf.jaxb.JAXBUtils;
 import org.apache.cxf.jaxrs.JAXRSServiceImpl;
 import org.apache.cxf.jaxrs.ext.Oneway;
 import org.apache.cxf.jaxrs.ext.RequestHandler;
+import org.apache.cxf.jaxrs.ext.multipart.Multipart;
 import org.apache.cxf.jaxrs.ext.xml.XMLSource;
 import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
 import org.apache.cxf.jaxrs.impl.UriInfoImpl;
@@ -590,11 +591,19 @@ public class WadlGenerator implements Re
 
     protected void doWriteParam(StringBuilder sb, Parameter pm, Class<?> type, 
                                 Type genericType, String paramName, Annotation[] anns, boolean
isJson) {
+        ParameterType pType = pm.getType();
+        boolean isForm = isFormParameter(pm, type, anns);
+        if (paramName == null && isForm) {
+            Multipart m = AnnotationUtils.getAnnotation(anns, Multipart.class);
+            if (m != null) {
+                paramName = m.value();
+            }
+        }
         sb.append("<param name=\"").append(paramName).append("\" ");
-        String style = ParameterType.PATH == pm.getType() ? "template"
-                       : ParameterType.FORM == pm.getType() ? "query"
-                       : ParameterType.REQUEST_BODY == pm.getType() ? "plain"    
-                       : pm.getType().toString().toLowerCase();
+        String style = ParameterType.PATH == pType ? "template"
+                       : isForm ? "query"
+                       : ParameterType.REQUEST_BODY == pType ? "plain"    
+                       : pType.toString().toLowerCase();
         sb.append("style=\"").append(style).append("\"");
         if (pm.getDefaultValue() != null) {
             sb.append(" default=\"").append(pm.getDefaultValue()).append("\"");
@@ -748,9 +757,12 @@ public class WadlGenerator implements Re
                 sb.append("/>");
             } else {
                 sb.append(">");
-                for (Parameter pm : ori.getParameters()) {
-                    if (pm.getType() == ParameterType.FORM) {
-                        writeParam(sb, pm, ori, false);
+                List<Parameter> params = ori.getParameters();
+                for (int i = 0; i < params.size(); i++) {
+                    if (isFormParameter(params.get(i), 
+                                        getMethod(ori).getParameterTypes()[i],
+                                        getMethod(ori).getParameterAnnotations()[i])) {
+                        writeParam(sb, params.get(i), ori, false);
                     }
                 }
                 sb.append("</representation>");
@@ -967,7 +979,9 @@ public class WadlGenerator implements Re
         for (Parameter p : ori.getParameters()) {
             if (p.getType() == ParameterType.FORM
                 || p.getType() == ParameterType.REQUEST_BODY 
-                && getMethod(ori).getParameterTypes()[p.getIndex()] == MultivaluedMap.class)
{
+                && (getMethod(ori).getParameterTypes()[p.getIndex()] == MultivaluedMap.class

+                    || AnnotationUtils.getAnnotation(getMethod(ori).getParameterAnnotations()[p.getIndex()],
+                                                     Multipart.class) != null)) {
                 return true;
             }
         }
@@ -975,14 +989,23 @@ public class WadlGenerator implements Re
     }
     
     private Class<?> getFormClass(OperationResourceInfo ori) {
-        for (Parameter p : ori.getParameters()) {
-            if (p.getType() == ParameterType.FORM) {
+        List<Parameter> params = ori.getParameters();
+        for (int i = 0; i < params.size(); i++) {
+            if (isFormParameter(params.get(i), 
+                                getMethod(ori).getParameterTypes()[i],
+                                getMethod(ori).getParameterAnnotations()[i])) {
                 return null;
             }
         } 
         return MultivaluedMap.class;
     }
 
+    private boolean isFormParameter(Parameter pm, Class<?> type, Annotation[] anns)
{
+        return ParameterType.FORM == pm.getType() || ParameterType.REQUEST_BODY == pm.getType()
+            && AnnotationUtils.getAnnotation(anns, Multipart.class) != null 
+            && InjectionUtils.isPrimitive(type);
+    }
+    
     // TODO : can we reuse this block with JAXBBinding somehow ?
     public boolean addSchemaDocument(SchemaCollection col,
                                      Document d,

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=1221709&r1=1221708&r2=1221709&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
Wed Dec 21 13:11:18 2011
@@ -73,7 +73,6 @@ 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;
@@ -318,18 +317,9 @@ 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) {
-            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;
+            return new Parameter(ParameterType.FORM, index, f.value(), isEncoded, dValue);
         }
         
         HeaderParam h = AnnotationUtils.getAnnotation(anns, HeaderParam.class);



Mime
View raw message