cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6371] Getting WADLGenerator recognize generic types better
Date Fri, 24 Apr 2015 14:51:05 GMT
Repository: cxf
Updated Branches:
  refs/heads/master b19f59d36 -> 300ace67c


[CXF-6371] Getting WADLGenerator recognize generic types better


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/300ace67
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/300ace67
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/300ace67

Branch: refs/heads/master
Commit: 300ace67c507c551b37ba4d99e6863b67bf871f8
Parents: b19f59d
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Fri Apr 24 15:50:49 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Fri Apr 24 15:50:49 2015 +0100

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/utils/ResourceUtils.java   | 13 ++++++--
 .../cxf/jaxrs/model/wadl/WadlGenerator.java     | 11 +++++--
 .../cxf/jaxrs/model/wadl/AbstractStore.java     | 33 ++++++++++++++++++++
 .../apache/cxf/jaxrs/model/wadl/BookStore.java  |  2 +-
 .../cxf/jaxrs/model/wadl/WadlGeneratorTest.java | 19 ++++++-----
 5 files changed, 64 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/300ace67/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
index f524f10..314caaf 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
@@ -589,7 +589,7 @@ public final class ResourceUtils {
             }
             Type type = method.getGenericReturnType();
             if (jaxbOnly) {
-                checkJaxbType(cls, realReturnType == Response.class ? cls : type, types,

+                checkJaxbType(resource.getServiceClass(), cls, realReturnType == Response.class
? cls : type, types, 
                     method.getAnnotations(), jaxbWriter);
             } else {
                 types.getAllTypes().put(cls, type);
@@ -600,7 +600,7 @@ public final class ResourceUtils {
                     Class<?> inType = method.getParameterTypes()[pm.getIndex()];
                     Type paramType = method.getGenericParameterTypes()[pm.getIndex()];
                     if (jaxbOnly) {
-                        checkJaxbType(inType, paramType, types, 
+                        checkJaxbType(resource.getServiceClass(), inType, paramType, types,

                                       method.getParameterAnnotations()[pm.getIndex()], jaxbWriter);
                     } else {
                         types.getAllTypes().put(inType, paramType);
@@ -628,7 +628,8 @@ public final class ResourceUtils {
         return isRecursiveSubResource(parent.getParent(), sub);
     }
     
-    private static void checkJaxbType(Class<?> type, 
+    private static void checkJaxbType(Class<?> serviceClass,
+                                      Class<?> type, 
                                       Type genericType, 
                                       ResourceTypes types,
                                       Annotation[] anns,
@@ -638,6 +639,12 @@ public final class ResourceUtils {
             type = InjectionUtils.getActualType(genericType);
             isCollection = true;
         }
+        if (type == Object.class && !(genericType instanceof Class)) {
+            Type theType = InjectionUtils.processGenericTypeIfNeeded(serviceClass, 
+                                                      Object.class,
+                                                      genericType);
+            type = InjectionUtils.getActualType(theType);
+        }
         if (type == null
             || InjectionUtils.isPrimitive(type)
             || JAXBElement.class.isAssignableFrom(type)

http://git-wip-us.apache.org/repos/asf/cxf/blob/300ace67/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
index cc0fcc4..8e8ea91 100644
--- a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
+++ b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
@@ -985,6 +985,7 @@ public class WadlGenerator implements ContainerRequestFilter {
             String docCategory;
             Annotation[] anns;
             int inParamIndex = -1;
+            Type genericType = null;
             if (inbound) {
                 inParamIndex = getRequestBodyParam(ori).getIndex();
                 anns = opMethod.getParameterAnnotations()[inParamIndex];
@@ -992,10 +993,12 @@ public class WadlGenerator implements ContainerRequestFilter {
                     anns = opMethod.getAnnotations();
                 }
                 docCategory = DocTarget.PARAM;
+                genericType = opMethod.getGenericParameterTypes()[inParamIndex];
             } else {
                 anns = opMethod.getAnnotations();
                 docCategory = DocTarget.RETURN;
                 allowDefault = false;
+                genericType = opMethod.getGenericReturnType();
             }
             if (isPrimitive) {
                 sb.append(">");
@@ -1007,11 +1010,15 @@ public class WadlGenerator implements ContainerRequestFilter {
                 boolean isCollection = InjectionUtils.isSupportedCollectionOrArray(type);
                 Class<?> theActualType = null;
                 if (isCollection) {
-                    theActualType = InjectionUtils.getActualType(!inbound ? opMethod.getGenericReturnType()
: opMethod
-                        .getGenericParameterTypes()[getRequestBodyParam(ori).getIndex()]);
+                    theActualType = InjectionUtils.getActualType(genericType);
                 } else {
                     theActualType = ResourceUtils.getActualJaxbType(type, opMethod, inbound);
                 }
+                if (theActualType == Object.class && !(genericType instanceof Class))
{
+                    Type theType = InjectionUtils.processGenericTypeIfNeeded(
+                        ori.getClassResourceInfo().getServiceClass(), Object.class, genericType);
+                    theActualType = InjectionUtils.getActualType(theType);
+                }
                 if (isJson) {
                     sb.append(" element=\"").append(theActualType.getSimpleName()).append("\"");
                 } else if (qnameResolver != null

http://git-wip-us.apache.org/repos/asf/cxf/blob/300ace67/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/AbstractStore.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/AbstractStore.java
b/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/AbstractStore.java
new file mode 100644
index 0000000..0bce865
--- /dev/null
+++ b/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/AbstractStore.java
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.model.wadl;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+public class AbstractStore<T> {
+    
+    @Path("/thestore")
+    @GET
+    public T getStoreArtifact() {
+        return null;
+    }
+    
+
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/300ace67/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
b/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
index 2697f51..e3fb74e 100644
--- a/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
+++ b/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
@@ -52,7 +52,7 @@ import org.apache.cxf.jaxrs.model.wadl.jaxb.packageinfo.Book2;
 @Path("/bookstore/{id}")
 @Consumes({"application/xml", "application/json" })
 @Produces({"application/xml", "application/json" })
-public class BookStore implements BookDescription {
+public class BookStore extends AbstractStore<Book> implements BookDescription {
 
     @Descriptions({ 
         @Description(value = "Attachments, max < 10", target = DocTarget.PARAM)

http://git-wip-us.apache.org/repos/asf/cxf/blob/300ace67/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
b/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
index 75ca099..d907dbe 100644
--- a/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
+++ b/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
@@ -458,17 +458,18 @@ public class WadlGeneratorTest extends Assert {
         
         checkDocs(resource, "book store \"resource\"", "super resource", "en-us");
         
-        List<Element> resourceEls = getElements(resource, "resource", 9);
+        List<Element> resourceEls = getElements(resource, "resource", 10);
         
         assertEquals("/book2", resourceEls.get(0).getAttribute("path"));
         assertEquals("/books/{bookid}", resourceEls.get(1).getAttribute("path"));
         assertEquals("/chapter", resourceEls.get(2).getAttribute("path"));
         assertEquals("/chapter2", resourceEls.get(3).getAttribute("path"));
         assertEquals("/thebooks2", resourceEls.get(4).getAttribute("path"));
-        assertEquals("/books/\"{bookid}\"", resourceEls.get(5).getAttribute("path"));
-        assertEquals("/booksubresource", resourceEls.get(6).getAttribute("path"));
-        assertEquals("/form", resourceEls.get(7).getAttribute("path"));
-        assertEquals("/itself", resourceEls.get(8).getAttribute("path"));
+        assertEquals("/thestore", resourceEls.get(5).getAttribute("path"));
+        assertEquals("/books/\"{bookid}\"", resourceEls.get(6).getAttribute("path"));
+        assertEquals("/booksubresource", resourceEls.get(7).getAttribute("path"));
+        assertEquals("/form", resourceEls.get(8).getAttribute("path"));
+        assertEquals("/itself", resourceEls.get(9).getAttribute("path"));
         
         // verify root resource starting with "/"
         // must have a single template parameter
@@ -551,14 +552,16 @@ public class WadlGeneratorTest extends Assert {
         // verify resource starting with /chapter2
         verifyGetResourceMethod(resourceEls.get(3), chapterEl, null);
         
+        verifyGetResourceMethod(resourceEls.get(5), bookEl, null);
+        
         // verify resource starting from /booksubresource
         // should have 2 parameters
-        verifyParameters(resourceEls.get(6), 2, 
+        verifyParameters(resourceEls.get(7), 2, 
                          new Param("id", "template", "xs:int"),
                          new Param("mid", "matrix", "xs:int"));
-        checkDocs(resourceEls.get(6), "", "Book subresource", ""); 
+        checkDocs(resourceEls.get(7), "", "Book subresource", ""); 
         // should have 4 child resources
-        List<Element> subResourceEls = getElements(resourceEls.get(6), "resource",
6);
+        List<Element> subResourceEls = getElements(resourceEls.get(7), "resource",
6);
 
         assertEquals("/book", subResourceEls.get(0).getAttribute("path"));
         assertEquals("/form1", subResourceEls.get(1).getAttribute("path"));


Mime
View raw message