[cxf] branch master updated: [CXF-7636] wadl2java: support Oneway annotation (#378)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[cxf] branch master updated: [CXF-7636] wadl2java: support Oneway annotation (#378)

buhhunyx
This is an automated email from the ASF dual-hosted git repository.

buhhunyx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new cf863bd  [CXF-7636] wadl2java: support Oneway annotation (#378)
cf863bd is described below

commit cf863bdf389aea0cf249491ef48de4bf9d68b846
Author: Alexey Markevich <[hidden email]>
AuthorDate: Wed Feb 7 14:41:58 2018 +0300

    [CXF-7636] wadl2java: support Oneway annotation (#378)
---
 .../apache/cxf/tools/wadlto/WadlToolConstants.java |  1 +
 .../cxf/tools/wadlto/jaxrs/JAXRSContainer.java     |  5 +++++
 .../cxf/tools/wadlto/jaxrs/SourceGenerator.java    | 11 +++++++++
 .../cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml      | 10 +++++++++
 .../cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java | 26 ++++++++++++++++++++++
 5 files changed, 53 insertions(+)

diff --git a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
index 64a2034..6754a81 100644
--- a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
+++ b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
@@ -61,6 +61,7 @@ public final class WadlToolConstants {
     public static final String CFG_GENERATE_RESPONSE_IF_HEADERS_SET = "generateResponseIfHeadersSet";
     public static final String CFG_GENERATE_RESPONSE_FOR_METHODS = "generateResponseForMethods";
     public static final String CFG_VALIDATE_WADL = "validate";
+    public static final String CFG_ONEWAY = "oneway";
 
     // JAX-RS 2.0 @Suspended AsyncResponse
     public static final String CFG_SUSPENDED_ASYNC = "async";
diff --git a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
index 42c909c..82bc11b 100644
--- a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
+++ b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
@@ -160,6 +160,7 @@ public class JAXRSContainer extends AbstractCXFToolContainer {
 
         sg.setSuspendedAsyncMethods(getSuspendedAsyncMethods());
         sg.setResponseMethods(getResponseMethods());
+        sg.setOnewayMethods(getOnewayMethods());
 
         sg.setGenerateEnums(context.optionSet(WadlToolConstants.CFG_GENERATE_ENUMS));
         sg.setValidateWadl(context.optionSet(WadlToolConstants.CFG_VALIDATE_WADL));
@@ -238,6 +239,10 @@ public class JAXRSContainer extends AbstractCXFToolContainer {
         return parseMethodList(WadlToolConstants.CFG_GENERATE_RESPONSE_FOR_METHODS);
     }
 
+    public Set<String> getOnewayMethods() {
+        return parseMethodList(WadlToolConstants.CFG_ONEWAY);
+    }
+
     private Set<String> parseMethodList(String paramName) {
         Object value = context.get(paramName);
         if (value != null) {
diff --git a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
index cfc24db..d60a0c7 100644
--- a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
+++ b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
@@ -100,6 +100,7 @@ import org.apache.cxf.common.xmlschema.SchemaCollection;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.helpers.JavaUtils;
+import org.apache.cxf.jaxrs.ext.Oneway;
 import org.apache.cxf.jaxrs.ext.multipart.Multipart;
 import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
 import org.apache.cxf.jaxrs.model.wadl.WadlGenerator;
@@ -215,6 +216,7 @@ public class SourceGenerator {
     private List<String> compilerArgs = new ArrayList<>();
     private Set<String> suspendedAsyncMethods = Collections.emptySet();
     private Set<String> responseMethods = Collections.emptySet();
+    private Set<String> onewayMethods = Collections.emptySet();
     private Map<String, String> schemaPackageMap = Collections.emptyMap();
     private Map<String, String> javaTypeMap = Collections.emptyMap();
     private Map<String, String> schemaTypeMap = Collections.emptyMap();
@@ -273,6 +275,10 @@ public class SourceGenerator {
         this.responseMethods = responseMethods;
     }
 
+    public void setOnewayMethods(Set<String> onewayMethods) {
+        this.onewayMethods = onewayMethods;
+    }
+
     private String getClassPackageName(String wadlPackageName) {
         if (resourcePackageName != null) {
             return resourcePackageName;
@@ -724,6 +730,7 @@ public class SourceGenerator {
         final boolean responseRequired = isMethodMatched(responseMethods, methodNameLowerCase, id);
         final boolean suspendedAsync = responseRequired ? false
             : isMethodMatched(suspendedAsyncMethods, methodNameLowerCase, id);
+        final boolean oneway = isMethodMatched(onewayMethods, methodNameLowerCase, id);
 
         boolean jaxpSourceRequired = requestRepsWithElements.size() > 1 && !supportMultipleRepsWithElements;
         int numOfMethods = jaxpSourceRequired ? 1 : requestRepsWithElements.size();
@@ -772,6 +779,10 @@ public class SourceGenerator {
                         addImport(imports, BEAN_VALID_FULL_NAME);
                         sbMethodCode.append("@").append(BEAN_VALID_SIMPLE_NAME).append(getLineSep()).append(TAB);
                     }
+                    if (oneway) {
+                        addImport(imports, Oneway.class.getName());
+                        sbMethodCode.append("@").append(Oneway.class.getSimpleName()).append(getLineSep()).append(TAB);
+                    }
                 }
                 if (!isRoot && !"/".equals(currentPath)) {
                     writeAnnotation(sbMethodCode, imports, Path.class, currentPath, true, true);
diff --git a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
index 463434e..2c32e10 100644
--- a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
+++ b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
@@ -279,6 +279,16 @@ Examples:
                 </associatedArgument>
                 <switch>authentication</switch>
             </option>
+            <option id="oneway" maxOccurs="1">
+                <annotation>
+                    Specifies a comma separated list of method names or identifiers
+                    which need to support oneway invocations
+                </annotation>
+                <associatedArgument placement="immediate">
+                    <annotation> methodNames</annotation>
+                </associatedArgument>
+                <switch>oneway</switch>
+            </option>
         </optionGroup>
         <optionGroup id="common_options">
             <option id="help" maxOccurs="1">
diff --git a/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java b/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
index 0b17789..3c75b7f 100644
--- a/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
+++ b/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
@@ -37,9 +37,11 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 
 import org.apache.cxf.helpers.FileUtils;
+import org.apache.cxf.jaxrs.ext.Oneway;
 import org.apache.cxf.jaxrs.ext.multipart.Multipart;
 import org.apache.cxf.tools.common.ProcessorTestBase;
 import org.apache.cxf.tools.common.ToolContext;
+import org.apache.cxf.tools.util.ClassCollector;
 import org.apache.cxf.tools.wadlto.WadlToolConstants;
 
 import org.junit.Test;
@@ -132,6 +134,30 @@ public class JAXRSContainerTest extends ProcessorTestBase {
     }
 
     @Test
+    public void testOnewayMethod() throws Exception {
+        JAXRSContainer container = new JAXRSContainer(null);
+
+        final String onewayMethod = "deleteRepository";
+        ToolContext context = new ToolContext();
+        context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
+        context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/test.xml"));
+        context.put(WadlToolConstants.CFG_COMPILE, "true");
+        context.put(WadlToolConstants.CFG_ONEWAY, onewayMethod);
+        container.setContext(context);
+        container.execute();
+
+        assertNotNull(output.list());
+
+        ClassCollector cc = context.get(ClassCollector.class);
+        assertEquals(1, cc.getServiceClassNames().size());
+        try (URLClassLoader loader = new URLClassLoader(new URL[]{output.toURI().toURL()})) {
+            final Class<?> generatedClass = loader.loadClass(cc.getServiceClassNames().values().iterator().next());
+            Method m = generatedClass.getMethod(onewayMethod, String.class);
+            assertNotNull(m.getAnnotation(Oneway.class));
+        }
+    }
+
+    @Test
     public void testCodeGenInterfacesMultipleInXmlReps() {
         try {
             JAXRSContainer container = new JAXRSContainer(null);

--
To stop receiving notification emails like this one, please contact
[hidden email].