cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1145684 - in /cxf/branches/2.4.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/
Date Tue, 12 Jul 2011 17:15:02 GMT
Author: sergeyb
Date: Tue Jul 12 17:15:02 2011
New Revision: 1145684

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

........
  r1145682 | sergeyb | 2011-07-12 18:12:55 +0100 (Tue, 12 Jul 2011) | 1 line
  
  [CXF-3631] Updating WADL generator to check parameter methods and fields
........

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/test/java/org/apache/cxf/jaxrs/model/wadl/BookStoreWithSingleSlash.java
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jul 12 17:15:02 2011
@@ -1 +1 @@
-/cxf/trunk:1144977
+/cxf/trunk:1144977,1145682

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=1145684&r1=1145683&r2=1145684&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
Tue Jul 12 17:15:02 2011
@@ -25,6 +25,7 @@ import java.io.InputStream;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
 import java.net.URI;
@@ -259,6 +260,8 @@ public class WadlGenerator implements Re
                                 Map<Class<?>, QName> clsMap, ClassResourceInfo
cri,
                                 Set<ClassResourceInfo> visitedResources) {
         visitedResources.add(cri);
+        Map<Parameter, Object> classParams = getClassParameters(cri);
+        
         List<OperationResourceInfo> sortedOps = sortOperationsByPath(
             cri.getMethodDispatcher().getOperationResourceInfos());
 
@@ -282,11 +285,24 @@ public class WadlGenerator implements Re
                 continue;
             }
             OperationResourceInfo nextOp = i + 1 < sortedOps.size() ? sortedOps.get(i
+ 1) : null;
-            resourceTagOpened = handleOperation(sb, jaxbTypes, qnameResolver, clsMap, ori,
nextOp,
-                                                resourceTagOpened, i);
+            resourceTagOpened = handleOperation(sb, jaxbTypes, qnameResolver, clsMap, ori,

+                                                classParams, nextOp, resourceTagOpened, i);
         }
     }
 
+    private Map<Parameter, Object> getClassParameters(ClassResourceInfo cri) {
+        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);
+        }
+        List<Field> fieldParams = cri.getParameterFields();
+        for (Field f : fieldParams) {
+            classParams.put(ResourceUtils.getParameter(0, f.getAnnotations()), f);
+        }
+        return classParams;
+    }
+    
     private void startResourceTag(StringBuilder sb, Class<?> serviceClass, String path)
{
         sb.append("<resource path=\"").append(getPath(path)).append("\"");
         if (addResourceAndMethodIds) {
@@ -325,11 +341,11 @@ public class WadlGenerator implements Re
                                  ElementQNameResolver qnameResolver,
                                  Map<Class<?>, QName> clsMap,
                                  OperationResourceInfo ori,
+                                 Map<Parameter, Object> classParams,
                                  OperationResourceInfo nextOp,
                                  boolean resourceTagOpened,
                                  int index) {
         Annotation[] anns = getMethod(ori).getAnnotations();
-        
     //CHECKSTYLE:ON
         boolean samePathOperationFollows = singleResourceMultipleMethods && compareOperations(ori,
nextOp);
 
@@ -345,19 +361,22 @@ public class WadlGenerator implements Re
             }
             sb.append("<resource path=\"").append(getPath(path)).append("\">");
             handleDocs(anns, sb, DocTarget.RESOURCE, false);
+            handlePathAndMatrixClassParams(sb, classParams);
             handlePathAndMatrixParams(sb, ori);
         } else if (index == 0) {
+            handlePathAndMatrixClassParams(sb, classParams);
             handlePathAndMatrixParams(sb, ori);
         }
 
         startMethodTag(sb, ori);
         handleDocs(anns, sb, DocTarget.METHOD, true);
-        if (getMethod(ori).getParameterTypes().length != 0) {
+        if (getMethod(ori).getParameterTypes().length != 0 || classParams.size() != 0) {
             sb.append("<request>");
             handleDocs(anns, sb, DocTarget.REQUEST, false);
             if (isFormRequest(ori)) {
                 handleFormRepresentation(sb, jaxbTypes, qnameResolver, clsMap, ori, getFormClass(ori));
             } else {
+                doHandleClassParams(sb, classParams, ParameterType.QUERY, ParameterType.HEADER);
                 for (Parameter p : ori.getParameters()) {
                     handleParameter(sb, jaxbTypes, qnameResolver, clsMap, ori, p);
                 }
@@ -438,6 +457,29 @@ public class WadlGenerator implements Re
         sb.append("</resource>");
     }
 
+    private void handlePathAndMatrixClassParams(StringBuilder sb, Map<Parameter, Object>
params) {
+        doHandleClassParams(sb, params, ParameterType.PATH);
+        doHandleClassParams(sb, params, ParameterType.MATRIX);
+    }
+    
+    private void doHandleClassParams(StringBuilder sb, Map<Parameter, Object> params,
+                                                  ParameterType... pType) {
+        Set<ParameterType> pTypes = new HashSet<ParameterType>(Arrays.asList(pType));
+        for (Map.Entry<Parameter, Object> entry : params.entrySet()) {
+            Parameter pm = entry.getKey();
+            Object obj = entry.getValue();
+            if (pTypes.contains(pm.getType())) {
+                Class<?> cls = obj instanceof Method 
+                    ? ((Method)obj).getParameterTypes()[0] : ((Field)obj).getType();
+                Type type = obj instanceof Method 
+                    ? ((Method)obj).getGenericParameterTypes()[0] : ((Field)obj).getGenericType();
   
+                Annotation[] ann = obj instanceof Method 
+                    ? ((Method)obj).getParameterAnnotations()[0] : ((Field)obj).getAnnotations();
+                doWriteParam(sb, pm, cls, type, pm.getName(), ann);        
+            }
+        }
+    }
+    
     private void handlePathAndMatrixParams(StringBuilder sb, OperationResourceInfo ori) {
         handleParams(sb, ori, ParameterType.PATH);
         handleParams(sb, ori, ParameterType.MATRIX);

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStoreWithSingleSlash.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStoreWithSingleSlash.java?rev=1145684&r1=1145683&r2=1145684&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStoreWithSingleSlash.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStoreWithSingleSlash.java
Tue Jul 12 17:15:02 2011
@@ -20,19 +20,29 @@ package org.apache.cxf.jaxrs.model.wadl;
 
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Response;
 
 import org.apache.cxf.jaxrs.model.wadl.jaxb.Book;
 
 @Path("/")
 public class BookStoreWithSingleSlash {
-
+    
+    @QueryParam("name")
+    private String name;
+    
+    @PathParam("id")
+    public void setId(int id) {
+    }
+    
+    
     @GET
     @Path("book")
     @ElementClass(response = Book.class)
     @Produces("application/xml")
     public Response getBookName() {
-        return null;
+        return Response.ok().entity(name).build();
     }
 }

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java?rev=1145684&r1=1145683&r2=1145684&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Tue Jul 12 17:15:02 2011
@@ -227,6 +227,9 @@ public class WadlGeneratorTest extends A
                                                                  WadlGenerator.WADL_NS, "resource");
         assertEquals(1, resourceEls.size());        
         assertEquals("book", resourceEls.get(0).getAttribute("path"));
+        
+        verifyParameters(resourceEls.get(0), 1, new Param("id", "template", "xs:int"));
+        
         checkGrammars(doc.getDocumentElement(), "thebook", null, "thechapter");
     }
     



Mime
View raw message