[jira] [Commented] (CXF-7636) wadl2java: support Oneway annotation

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

[jira] [Commented] (CXF-7636) wadl2java: support Oneway annotation

JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/CXF-7636?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16355344#comment-16355344 ]

ASF GitHub Bot commented on CXF-7636:
-------------------------------------

amarkevich closed pull request #378: [CXF-7636] wadl2java: support Oneway annotation
URL: https://github.com/apache/cxf/pull/378
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 64a2034e610..6754a81df6e 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 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 42c909c794a..82bc11bcecc 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 @@ private void processWadl() {
 
         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 @@ protected String getAbsoluteWadlURL() {
         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 cfc24db5fa7..d60a0c7e79f 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.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 @@
     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 void setResponseMethods(Set<String> responseMethods) {
         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 @@ private void writeResourceMethod(Element methodEl,
         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 @@ private void writeResourceMethod(Element methodEl,
                         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 463434e11f3..2c32e10a84d 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 0b177894a30..3c75b7f55ba 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.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;
@@ -131,6 +133,30 @@ public void testInheritParameters() {
         }
     }
 
+    @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 {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


> wadl2java: support Oneway annotation
> ------------------------------------
>
>                 Key: CXF-7636
>                 URL: https://issues.apache.org/jira/browse/CXF-7636
>             Project: CXF
>          Issue Type: New Feature
>          Components: Tooling
>    Affects Versions: 3.2.1
>            Reporter: Alexey Markevich
>            Priority: Major
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)