cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1221723 - in /cxf/branches/2.4.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
Date Wed, 21 Dec 2011 13:38:02 GMT
Author: sergeyb
Date: Wed Dec 21 13:38:02 2011
New Revision: 1221723

URL: http://svn.apache.org/viewvc?rev=1221723&view=rev
Log:
Merged revisions 1221709 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1221709 | sergeyb | 2011-12-21 13:11:18 +0000 (Wed, 21 Dec 2011) | 1 line
  
  [CXF-3903] Fixing a regression to do with converting Multipart params to FormParams too
early for the benefit of WADLGenerator
........

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/model/wadl/WadlGenerator.java
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Dec 21 13:38:02 2011
@@ -1 +1 @@
-/cxf/trunk:1221204,1221208,1221221,1221226,1221511,1221519
+/cxf/trunk:1221204,1221208,1221221,1221226,1221511,1221519,1221709

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/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=1221723&r1=1221722&r2=1221723&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
Wed Dec 21 13:38:02 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;
@@ -561,11 +562,19 @@ public class WadlGenerator implements Re
 
     protected void doWriteParam(StringBuilder sb, Parameter pm, Class<?> type, 
                                 Type genericType, String paramName, Annotation[] anns) {
+        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("\"");
@@ -698,12 +707,17 @@ public class WadlGenerator implements Re
             MediaType formType = isWildcard(types) ? MediaType.APPLICATION_FORM_URLENCODED_TYPE

                 : types.get(0); 
             sb.append("<representation");
-            sb.append(" mediaType=\"").append(formType).append("\">");
-            for (Parameter pm : ori.getParameters()) {
-                if (pm.getType() == ParameterType.FORM) {
-                    writeParam(sb, pm, ori);
+            sb.append(" mediaType=\"").append(formType).append("\"");
+            sb.append(">");
+            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);
                 }
             }
+            
             sb.append("</representation>");
         }
     }
@@ -917,7 +931,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;
             }
         }
@@ -925,14 +941,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/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java?rev=1221723&r1=1221722&r2=1221723&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
Wed Dec 21 13:38:02 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