cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1412848 - in /cxf/trunk/tools/wadlto/jaxrs/src: main/java/org/apache/cxf/tools/wadlto/ main/java/org/apache/cxf/tools/wadlto/jaxrs/ test/java/org/apache/cxf/tools/wadlto/jaxrs/ test/resources/wadl/
Date Fri, 23 Nov 2012 12:00:09 GMT
Author: sergeyb
Date: Fri Nov 23 12:00:07 2012
New Revision: 1412848

URL: http://svn.apache.org/viewvc?rev=1412848&view=rev
Log:
[CXF-4648] Update wadl-to-java to support AsyncResponse parameters

Modified:
    cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
    cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
    cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
    cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
    cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java
    cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml

Modified: cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java?rev=1412848&r1=1412847&r2=1412848&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
Fri Nov 23 12:00:07 2012
@@ -52,6 +52,13 @@ public final class WadlToolConstants {
     public static final String CFG_GENERATE_ENUMS = "generateEnums";
     public static final String CFG_INHERIT_PARAMS = "inheritResourceParams";
     
+    // JAX-RS 2.0 @Suspended AsyncResponse
+    public static final String CFG_SUSPENDED_ASYNC = "async";
+    
+    // CXF @UseAsyncMethod - equivalent of the proposed @ManagedAsync which
+    // which did not make it into JAX-RS 2.0
+    //public static final String CFG_MANAGED_ASYNC = "managedAsync";
+    
     public static final String CFG_WADLURL = "wadl";
     
     

Modified: cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java?rev=1412848&r1=1412847&r2=1412848&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
Fri Nov 23 12:00:07 2012
@@ -149,6 +149,8 @@ public class JAXRSContainer extends Abst
         sg.setSchemaTypeMap(getSchemaTypeMap());
         sg.setMediaTypeMap(getMediaTypeMap());
 
+        sg.setSuspendedAsyncMethods(getSuspendedAsyncMethods());
+        
         sg.setGenerateEnums(context.optionSet(WadlToolConstants.CFG_GENERATE_ENUMS));
         sg.setInheritResourceParams(context.optionSet(WadlToolConstants.CFG_INHERIT_PARAMS));
         sg.setSkipSchemaGeneration(context.optionSet(WadlToolConstants.CFG_NO_TYPES));
@@ -205,6 +207,23 @@ public class JAXRSContainer extends Abst
         return absoluteWadlURL;
     }
     
+    public Set<String> getSuspendedAsyncMethods() {
+        Object value = context.get(WadlToolConstants.CFG_SUSPENDED_ASYNC);
+        if (value != null) {
+            Set<String> methods = new HashSet<String>();
+            String[] values = value.toString().split(",");
+            for (String s : values) {
+                String actual = s.trim();
+                if (!actual.isEmpty()) {
+                    methods.add(actual.toLowerCase());
+                }
+            }
+            return methods;
+        } else {
+            return Collections.emptySet();
+        }
+    }
+    
     //TODO: this belongs to JAXB Databinding, should we just reuse 
     // org.apache.cxf.tools.wsdlto.databinding.jaxb ?
     private void setPackageAndNamespaces() {

Modified: cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java?rev=1412848&r1=1412847&r2=1412848&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
Fri Nov 23 12:00:07 2012
@@ -56,6 +56,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.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
@@ -186,6 +188,7 @@ public class SourceGenerator {
     private List<InputSource> bindingFiles = Collections.emptyList();
     private List<InputSource> schemaPackageFiles = Collections.emptyList();
     private List<String> compilerArgs = new ArrayList<String>();
+    private Set<String> suspendedAsyncMethods = Collections.emptySet();
     private Map<String, String> schemaPackageMap = Collections.emptyMap();
     private Map<String, String> javaTypeMap = Collections.emptyMap();
     private Map<String, String> schemaTypeMap = Collections.emptyMap();
@@ -226,6 +229,10 @@ public class SourceGenerator {
         this.skipSchemaGeneration = skip;
     }
     
+    public void setSuspendedAsyncMethods(Set<String> asyncMethods) {
+        this.suspendedAsyncMethods = asyncMethods;
+    }
+    
     private String getClassPackageName(String wadlPackageName) {
         if (resourcePackageName != null) {
             return resourcePackageName;
@@ -643,18 +650,20 @@ public class SourceGenerator {
         List<Element> allRequestReps = getWadlElements(firstRequestEl, "representation");
         List<Element> xmlRequestReps = getXmlReps(allRequestReps);
         
+        final String methodNameLowerCase = methodEl.getAttribute("name").toLowerCase();
+        String id = methodEl.getAttribute("id");
+        if (id.length() == 0) {
+            id = methodNameLowerCase;
+        }
+        final boolean suspendedAsync = suspendedAsyncMethods.contains(methodNameLowerCase)
+            || methodNameLowerCase != id && suspendedAsyncMethods.contains(id.toLowerCase());
+        
         boolean jaxpSourceRequired = xmlRequestReps.size() > 1 && !supportMultipleXmlReps;
         int numOfMethods = jaxpSourceRequired ? 1 : xmlRequestReps.size(); 
         for (int i = 0; i < numOfMethods; i++) {
             
             Element inXmlRep = xmlRequestReps.get(i);
                         
-            String methodNameLowerCase = methodEl.getAttribute("name").toLowerCase();
-            String id = methodEl.getAttribute("id");
-            if (id.length() == 0) {
-                id = methodNameLowerCase;
-            }
-            
             String suffixName = "";
             if (!jaxpSourceRequired && inXmlRep != null && xmlRequestReps.size()
> 1) {
                 String value = inXmlRep.getAttribute("element");
@@ -687,7 +696,7 @@ public class SourceGenerator {
             }
             boolean responseTypeAvailable = true;
             if (methodNameLowerCase.length() > 0) {
-                responseTypeAvailable = writeResponseType(responseEls, sbCode, imports, info);
+                responseTypeAvailable = writeResponseType(responseEls, sbCode, imports, info,
suspendedAsync);
                 String genMethodName = id + suffixName;
                 if (methodNameLowerCase.equals(genMethodName)) {
                     genMethodName += firstCharToUpperCase(
@@ -723,7 +732,7 @@ public class SourceGenerator {
             
             Element repElement = getActualRepElement(allRequestReps, inXmlRep); 
             writeRequestTypes(firstRequestEl, classPackage, repElement, inParamElements,

-                    jaxpSourceRequired, sbCode, imports, info);
+                    jaxpSourceRequired, sbCode, imports, info, suspendedAsync);
             sbCode.append(")");
             if (info.isInterfaceGenerated()) {
                 sbCode.append(";");
@@ -820,9 +829,10 @@ public class SourceGenerator {
     private boolean writeResponseType(List<Element> responseEls,
                                       StringBuilder sbCode,
                                       Set<String> imports,  
-                                      ContextInfo info) {
+                                      ContextInfo info,
+                                      boolean suspendedAsync) {
         
-        Element okResponse = getOKResponse(responseEls);
+        Element okResponse = !suspendedAsync ? getOKResponse(responseEls) : null;
         
         List<Element> repElements = null;
         if (okResponse != null) {
@@ -832,7 +842,7 @@ public class SourceGenerator {
         }
         
         if (repElements.size() == 0) {
-            if (useVoidForEmptyResponses) {
+            if (useVoidForEmptyResponses || suspendedAsync) {
                 sbCode.append("void ");
             } else {
                 addImport(imports, Response.class.getName());
@@ -882,7 +892,8 @@ public class SourceGenerator {
                                    boolean jaxpRequired,
                                    StringBuilder sbCode, 
                                    Set<String> imports, 
-                                   ContextInfo info) {
+                                   ContextInfo info,
+                                   boolean suspendedAsync) {
     //CHECKSTYLE:ON    
         boolean form = false;
         boolean formParamsAvailable = false;
@@ -968,6 +979,15 @@ public class SourceGenerator {
             }
             sbCode.append(elementParamType).append(" ").append(elementParamName);
         }
+        if (suspendedAsync) {
+            if (inParamEls.size() > 0 || elementParamType != null) {
+                sbCode.append(", ");
+            }
+            addImport(imports, Suspended.class.getName());
+            addImport(imports, AsyncResponse.class.getName());
+            sbCode.append("@").append(Suspended.class.getSimpleName()).append(" ")
+                .append(AsyncResponse.class.getSimpleName()).append(" ").append("async");
+        }
     }
     
     private void generateEnumClass(String clsName, List<Element> options, File src,
String classPackage) {

Modified: cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml?rev=1412848&r1=1412847&r2=1412848&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
Fri Nov 23 12:00:07 2012
@@ -209,7 +209,17 @@ Examples:
                 </annotation>
                 <switch>supportMultipleXmlReps</switch>
             </option>
-            
+ 
+            <option id="async" maxOccurs="unbounded">
+                <annotation>
+                    Specifies a comma separated list of method names or identifiers 
+                    which need to support suspended asynchronous invocations            
        
+                </annotation>
+                <associatedArgument placement="immediate">
+                    <annotation>methodNames</annotation>
+                </associatedArgument>
+                <switch>async</switch>
+            </option>           
 <!-- 
 
 TODO: consider implementing most of the following options
@@ -268,11 +278,6 @@ TODO: consider implementing most of the 
                     <annotation>schema-namespace [= java-package-name]</annotation>
                 </associatedArgument>
             </option>
- 
-            <option id="notypes" maxOccurs="1">
-                <annotation>Turns off generating types</annotation>
-                <switch>noTypes</switch>
-            </option>
             <option id="defaultns" maxOccurs="1">
                 <annotation>
                     Enables loading the default namespace package name mapping. The default
is true.

Modified: cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java?rev=1412848&r1=1412847&r2=1412848&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java
Fri Nov 23 12:00:07 2012
@@ -40,6 +40,7 @@ public class WADLToJavaTest extends Proc
                 output.getCanonicalPath(),
                 "-p",
                 "custom.service",
+                "-async getName,delete",
                 "-compile",
                 getLocation("/wadl/bookstore.xml"),
             };

Modified: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml?rev=1412848&r1=1412847&r2=1412848&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml (original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml Fri Nov 23 12:00:07
2012
@@ -95,6 +95,8 @@ required="true">
      <response status="204"></response>
     </method>
     
+    <method name="DELETE"/>
+    
     <resource path="/book2">
      <method name="GET" id="getBook2">
       <response>



Mime
View raw message