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-7027] WADLGenerator support for AsyncResponse
Date Fri, 26 Aug 2016 16:35:11 GMT
Repository: cxf
Updated Branches:
  refs/heads/master ce9332b71 -> 14c37eee6


[CXF-7027] WADLGenerator support for AsyncResponse


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

Branch: refs/heads/master
Commit: 14c37eee6523c7e04bcf83dad71330ca126a0f48
Parents: ce9332b
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Fri Aug 26 17:34:49 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Aug 26 17:34:49 2016 +0100

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/model/ParameterType.java   |  3 +--
 .../apache/cxf/jaxrs/utils/ResourceUtils.java   | 21 ++++++++++----------
 .../cxf/jaxrs/model/wadl/WadlGenerator.java     | 11 ++++++----
 .../apache/cxf/jaxrs/model/wadl/BookStore.java  |  6 ++++--
 4 files changed, 23 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/14c37eee/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ParameterType.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ParameterType.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ParameterType.java
index 2db2afe..243345b 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ParameterType.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ParameterType.java
@@ -29,6 +29,5 @@ public enum ParameterType {
     BEAN,
     
     REQUEST_BODY,
-    CONTEXT,
-    UNKNOWN
+    CONTEXT
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/14c37eee/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 32fd44e..28f09ad 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
@@ -625,13 +625,13 @@ public final class ResourceUtils {
             Method method = ori.getAnnotatedMethod() == null ? ori.getMethodToInvoke() :
ori.getAnnotatedMethod();
             Class<?> realReturnType = method.getReturnType();
             Class<?> cls = realReturnType;
-            if (cls == Response.class) {
+            if (cls == Response.class || ori.isAsync()) {
                 cls = getActualJaxbType(cls, method, false);
             }
             Type type = method.getGenericReturnType();
             if (jaxbOnly) {
-                checkJaxbType(resource.getServiceClass(), cls, realReturnType == Response.class
? cls : type, types, 
-                    method.getAnnotations(), jaxbWriter);
+                checkJaxbType(resource.getServiceClass(), cls, realReturnType == Response.class
|| ori.isAsync() 
+                    ? cls : type, types, method.getAnnotations(), jaxbWriter);
             } else {
                 types.getAllTypes().put(cls, type);
             }
@@ -639,14 +639,15 @@ public final class ResourceUtils {
             for (Parameter pm : ori.getParameters()) {
                 if (pm.getType() == ParameterType.REQUEST_BODY) {
                     Class<?> inType = method.getParameterTypes()[pm.getIndex()];
-                    Type paramType = method.getGenericParameterTypes()[pm.getIndex()];
-                    if (jaxbOnly) {
-                        checkJaxbType(resource.getServiceClass(), inType, paramType, types,

-                                      method.getParameterAnnotations()[pm.getIndex()], jaxbWriter);
-                    } else {
-                        types.getAllTypes().put(inType, paramType);
+                    if (inType != AsyncResponse.class) {
+                        Type paramType = method.getGenericParameterTypes()[pm.getIndex()];
+                        if (jaxbOnly) {
+                            checkJaxbType(resource.getServiceClass(), inType, paramType,
types, 
+                                          method.getParameterAnnotations()[pm.getIndex()],
jaxbWriter);
+                        } else {
+                            types.getAllTypes().put(inType, paramType);
+                        }
                     }
-                    
                 }
             }
             

http://git-wip-us.apache.org/repos/asf/cxf/blob/14c37eee/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 9f13b4b..d2070ee 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
@@ -57,6 +57,7 @@ import javax.ws.rs.HeaderParam;
 import javax.ws.rs.MatrixParam;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.QueryParam;
+import javax.ws.rs.container.AsyncResponse;
 import javax.ws.rs.container.ContainerRequestContext;
 import javax.ws.rs.container.ContainerRequestFilter;
 import javax.ws.rs.core.HttpHeaders;
@@ -584,7 +585,9 @@ public class WadlGenerator implements ContainerRequestFilter {
         if (!handleDocs(anns, sb, DocTarget.METHOD, true, isJson)) {
             handleOperJavaDocs(ori, sb);
         }
-        if (getMethod(ori).getParameterTypes().length != 0 || !classParams.isEmpty()) {
+        int numOfParams = getMethod(ori).getParameterTypes().length;
+        if ((numOfParams > 1 || numOfParams == 1 && !ori.isAsync()) || !classParams.isEmpty())
{
+            
             startMethodRequestTag(sb, ori);
             handleDocs(anns, sb, DocTarget.REQUEST, false, isJson);
 
@@ -606,7 +609,7 @@ public class WadlGenerator implements ContainerRequestFilter {
         }
         startMethodResponseTag(sb, ori);
         Class<?> returnType = getMethod(ori).getReturnType();
-        boolean isVoid = void.class == returnType;
+        boolean isVoid = void.class == returnType && !ori.isAsync();
         ResponseStatus responseStatus = getMethod(ori).getAnnotation(ResponseStatus.class);
         if (responseStatus != null) {
             setResponseStatus(sb, responseStatus.value());
@@ -754,7 +757,7 @@ public class WadlGenerator implements ContainerRequestFilter {
                                    ElementQNameResolver qnameResolver, Map<Class<?>,
QName> clsMap,
                                    OperationResourceInfo ori, Parameter pm, boolean isJson)
{
         Class<?> cls = getMethod(ori).getParameterTypes()[pm.getIndex()];
-        if (pm.getType() == ParameterType.REQUEST_BODY) {
+        if (pm.getType() == ParameterType.REQUEST_BODY && cls != AsyncResponse.class)
{
             handleRepresentation(sb, jaxbTypes, qnameResolver, clsMap, ori, cls, isJson,
true);
             return;
         }
@@ -1031,7 +1034,7 @@ public class WadlGenerator implements ContainerRequestFilter {
         }
 
         Method opMethod = getMethod(ori);
-        boolean isPrimitive = InjectionUtils.isPrimitive(type);
+        boolean isPrimitive = InjectionUtils.isPrimitive(type) && !ori.isAsync();
         for (MediaType mt : types) {
 
             sb.append("<representation");

http://git-wip-us.apache.org/repos/asf/cxf/blob/14c37eee/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 2414ed0..90adb4c 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
@@ -34,6 +34,8 @@ import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
+import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.container.Suspended;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Response;
@@ -156,8 +158,8 @@ public class BookStore extends AbstractStore<Book> implements BookDescription
{
     @GET
     @Path("chapter2")
     @ElementClass(response = Chapter.class)
-    public Response getChapter2() {
-        return Response.ok().entity(new Chapter(1)).build();
+    public void getChapterAsync(@Suspended AsyncResponse async) {
+        async.resume(Response.ok().entity(new Chapter(1)).build());
     }
     
     @Path("form")


Mime
View raw message