cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1099611 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Date Wed, 04 May 2011 21:28:19 GMT
Author: sergeyb
Date: Wed May  4 21:28:18 2011
New Revision: 1099611

URL: http://svn.apache.org/viewvc?rev=1099611&view=rev
Log:
[CXF-3490] Updating WADL Generator to handle repeating parameters correctly

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.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=1099611&r1=1099610&r2=1099611&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 May  4 21:28:18 2011
@@ -26,6 +26,7 @@ import java.io.StringReader;
 import java.io.StringWriter;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
+import java.lang.reflect.Type;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -459,7 +460,8 @@ public class WadlGenerator implements Re
         Method method = getMethod(ori);
         Class<?> type = method.getParameterTypes()[pm.getIndex()];
         if (!"".equals(pm.getName())) {
-            doWriteParam(sb, pm, type, pm.getName(), method.getParameterAnnotations()[pm.getIndex()]);
+            doWriteParam(sb, pm, type, method.getGenericParameterTypes()[pm.getIndex()],
+                         pm.getName(), method.getParameterAnnotations()[pm.getIndex()]);
         } else {
             doWriteBeanParam(sb, type, pm, null);
         }
@@ -472,16 +474,18 @@ public class WadlGenerator implements Re
             if (parentName != null) {
                 name = parentName + "." + name;
             }
-            if (InjectionUtils.isPrimitive(entry.getValue())) {
-                doWriteParam(sb, entry.getKey(), entry.getValue(), name, new Annotation[]{});
+            Class<?> paramCls = entry.getValue();
+            boolean isPrimitive = InjectionUtils.isPrimitive(paramCls);
+            if (isPrimitive || InjectionUtils.isSupportedCollectionOrArray(paramCls)) {
+                doWriteParam(sb, entry.getKey(), paramCls, paramCls, name, new Annotation[]{});
             } else {
-                doWriteBeanParam(sb, entry.getValue(), entry.getKey(), name);
+                doWriteBeanParam(sb, paramCls, entry.getKey(), name);
             }
         }
     }
 
-    protected void doWriteParam(StringBuilder sb, Parameter pm, Class<?> type, String
paramName,
-                                Annotation[] anns) {
+    protected void doWriteParam(StringBuilder sb, Parameter pm, Class<?> type, 
+                                Type genericType, String paramName, Annotation[] anns) {
         sb.append("<param name=\"").append(paramName).append("\" ");
         String style = ParameterType.PATH == pm.getType() ? "template"
                        : ParameterType.FORM == pm.getType() ? "query"
@@ -491,6 +495,10 @@ public class WadlGenerator implements Re
         if (pm.getDefaultValue() != null) {
             sb.append(" default=\"").append(pm.getDefaultValue()).append("\"");
         }
+        if (InjectionUtils.isSupportedCollectionOrArray(type)) {
+            type = InjectionUtils.getActualType(genericType);
+            sb.append(" repeating=\"true\"");
+        }
         String value = XmlSchemaPrimitiveUtils.getSchemaRepresentation(type);
         if (value != null) {
             sb.append(" type=\"").append(value).append("\"");
@@ -548,7 +556,7 @@ public class WadlGenerator implements Re
                 sb.append(">");    
                 Parameter p = inbound ? getRequestBodyParam(ori) 
                     : new Parameter(ParameterType.REQUEST_BODY, 0, "result"); 
-                doWriteParam(sb, p, type, p.getName() == null ? "request" : p.getName(),
anns);
+                doWriteParam(sb, p, type, type, p.getName() == null ? "request" : p.getName(),
anns);
                 sb.append("</representation>");
             } else  { 
                 type = getActualJaxbType(type, opMethod, inbound);

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java?rev=1099611&r1=1099610&r2=1099611&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
Wed May  4 21:28:18 2011
@@ -18,6 +18,8 @@
  */
 package org.apache.cxf.jaxrs.model.wadl;
 
+import java.util.List;
+
 import javax.ws.rs.Consumes;
 import javax.ws.rs.CookieParam;
 import javax.ws.rs.GET;
@@ -83,6 +85,7 @@ public class BookStore {
                         @HeaderParam("hid") int headerId,
                         @CookieParam("cid") int cookieId,
                         @QueryParam("provider.bar") int queryParam,
+                        @QueryParam("a") List<String> queryList,
                         @Context HttpHeaders headers,
                         @Description("InputBook")      
                         @XMLName(value = "{http://books}thesuperbook2")
@@ -108,14 +111,14 @@ public class BookStore {
     
     @GET
     @Path("chapter")
-    public Chapter getChaper() {
+    public Chapter getChapter() {
         return new Chapter(1);
     }
     
     @GET
     @Path("chapter2")
     @ElementClass(response = Chapter.class)
-    public Response getChaper2() {
+    public Response getChapter2() {
         return Response.ok().entity(new Chapter(1)).build();
     }
     

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=1099611&r1=1099610&r2=1099611&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
Wed May  4 21:28:18 2011
@@ -392,9 +392,10 @@ public class WadlGeneratorTest extends A
         
         checkDocs(requestEls.get(0), "", "Request", "");
         
-        verifyParameters(requestEls.get(0), 2, 
+        verifyParameters(requestEls.get(0), 3, 
                          new Param("hid", "header", "xs:int"),
-                         new Param("provider.bar", "query", "xs:int"));
+                         new Param("provider.bar", "query", "xs:int"),
+                         new Param("a", "query", "xs:string", true));
         
         verifyXmlJsonRepresentations(requestEls.get(0), book2El, "InputBook");
         List<Element> responseEls = getElements(methodEls.get(0), "response", 1);
@@ -550,6 +551,7 @@ public class WadlGeneratorTest extends A
         assertEquals(p.getName(), paramEl.getAttribute("name"));
         assertEquals(p.getType(), paramEl.getAttribute("style"));
         assertEquals(p.getSchemaType(), paramEl.getAttribute("type"));
+        assertEquals(p.isRepeating(), Boolean.valueOf(paramEl.getAttribute("repeating")));
         String docs = p.getDocs();
         if (docs != null) {
             checkDocs(paramEl, "", docs, "");
@@ -599,15 +601,26 @@ public class WadlGeneratorTest extends A
         private String type;
         private String schemaType;
         private String docs;
+        private boolean repeating;
         public Param(String name, String type, String schemaType) {
-            this(name, type, schemaType, null);
+            this(name, type, schemaType, false);
+        }
+        
+        public Param(String name, String type, String schemaType, boolean repeating) {
+            this(name, type, schemaType, repeating, null);
         }
         
         public Param(String name, String type, String schemaType, String docs) {
+            this(name, type, schemaType, false, null);
+        }
+        
+        
+        public Param(String name, String type, String schemaType, boolean repeating, String
docs) {
             this.name = name;
             this.type = type;
             this.schemaType = schemaType;
             this.docs = docs;
+            this.repeating = repeating;
         }
         
         public String getName() {
@@ -625,5 +638,9 @@ public class WadlGeneratorTest extends A
         public String getDocs() {
             return docs;
         }
+        
+        public boolean isRepeating() {
+            return repeating;
+        }
     }
 }



Mime
View raw message