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-6759] Fixing a duplicate method issue, patch from Neal Hu applied with minor updates
Date Fri, 29 Jan 2016 10:16:23 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes f420fe361 -> 560dfbcac


[CXF-6759] Fixing a duplicate method issue, patch from Neal Hu applied with minor updates


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

Branch: refs/heads/3.0.x-fixes
Commit: 560dfbcacc40737186feda09ca27fefcac5f511a
Parents: f420fe3
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Fri Jan 29 10:13:46 2016 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Jan 29 10:16:07 2016 +0000

----------------------------------------------------------------------
 .../cxf/tools/wadlto/jaxrs/SourceGenerator.java | 32 ++++++++++++++-----
 .../tools/wadlto/jaxrs/JAXRSContainerTest.java  | 33 +++++++++++---------
 .../src/test/resources/wadl/testComplexPath.xml |  3 ++
 3 files changed, 46 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/560dfbca/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
----------------------------------------------------------------------
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 1627d49..e25eda7 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
@@ -505,7 +505,10 @@ public class SourceGenerator {
         writeImplementsInterface(sbCode, qname.getLocalPart(), info.isInterfaceGenerated());
             
         sbCode.append(" {" + getLineSep() + getLineSep());
         
-        writeMethods(rElement, classPackage, imports, sbCode, info, resourceId, isRoot, "");
+        Map<String, Integer> methodNameMap = new HashMap<String, Integer>();
+        writeMethods(rElement, classPackage, imports, sbCode, 
+                     info, resourceId, isRoot, "",
+                     methodNameMap);
         
         sbCode.append("}");
         writeImports(sbImports, imports, classPackage);
@@ -610,14 +613,15 @@ public class SourceGenerator {
                               ContextInfo info,
                               String resourceId,
                               boolean isRoot,
-                              String currentPath) {
+                              String currentPath,
+                              Map<String, Integer> methodNameMap) {
     //CHECKSTYLE:ON    
         List<Element> methodEls = getWadlElements(rElement, "method");
         
         List<Element> currentInheritedParams = inheritResourceParams 
             ? new LinkedList<Element>(info.getInheritedParams()) : Collections.<Element>emptyList();
         for (Element methodEl : methodEls) {
-            writeResourceMethod(methodEl, classPackage, imports, sbCode, info, isRoot, currentPath);
   
+            writeResourceMethod(methodEl, classPackage, imports, sbCode, info, isRoot, currentPath,
methodNameMap);    
         }
         if (inheritResourceParams && methodEls.isEmpty()) {
             info.getInheritedParams().addAll(getWadlElements(rElement, "param"));
@@ -632,9 +636,9 @@ public class SourceGenerator {
             String newPath = currentPath + path.replace("//", "/");
             String id = childEl.getAttribute("id");
             if (id.length() == 0) {
-                writeMethods(childEl, classPackage, imports, sbCode, info, id, false, newPath);
+                writeMethods(childEl, classPackage, imports, sbCode, info, id, false, newPath,
methodNameMap);
             } else {
-                writeResourceMethod(childEl, classPackage, imports, sbCode, info, false,
newPath);
+                writeResourceMethod(childEl, classPackage, imports, sbCode, info, false,
newPath, methodNameMap);
             }
         }
         info.getInheritedParams().clear();
@@ -678,13 +682,16 @@ public class SourceGenerator {
         }
     }
     
+    //CHECKSTYLE:OFF
     private void writeResourceMethod(Element methodEl,
                                      String classPackage,
                                      Set<String> imports,
                                      StringBuilder sbCode,
                                      ContextInfo info,
                                      boolean isRoot,
-                                     String currentPath) {
+                                     String currentPath,
+                                     Map<String, Integer> methodNameMap) {
+    //CHECKSTYLE:ON    
         StringBuilder sbMethodCode = sbCode;
         StringBuilder sbMethodDocs = null;
         StringBuilder sbMethodRespDocs = null;
@@ -792,7 +799,18 @@ public class SourceGenerator {
                     }
                     genMethodName += firstCharToUpperCase(sb.toString());
                 }
-                sbMethodCode.append(genMethodName.replace("-", ""));
+                genMethodName = genMethodName.replace("-", "");
+                
+                Integer value = methodNameMap.get(genMethodName);
+                if (value == null) {
+                    value = 0;
+                }
+                methodNameMap.put(genMethodName, ++value);
+                if (value > 1) { 
+                    genMethodName = genMethodName + value.toString();
+                }
+                
+                sbMethodCode.append(genMethodName);
             } else {
                 writeSubresourceMethod(resourceEl, imports, sbMethodCode, info, id, suffixName);
             }

http://git-wip-us.apache.org/repos/asf/cxf/blob/560dfbca/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
----------------------------------------------------------------------
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 bbcde20..2be4efa 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
@@ -431,28 +431,31 @@ public class JAXRSContainerTest extends ProcessorTestBase {
             
             Class<?> test1 = loader.loadClass("application.Resource");
             Method[] test1Methods = test1.getDeclaredMethods();
-            assertEquals(1, test1Methods.length);
+            assertEquals(2, test1Methods.length);
             assertEquals(2, test1Methods[0].getAnnotations().length);
-            assertNotNull(test1Methods[0].getAnnotation(GET.class));            
-            Path path = test1Methods[0].getAnnotation(Path.class);
-            assertNotNull(path);
-            assertEquals("/get-add-method", path.value());
-            
-            assertEquals("getGetaddmethod", test1Methods[0].getName());
-            Class<?>[] paramTypes = test1Methods[0].getParameterTypes();
-            assertEquals(1, paramTypes.length);
-            Annotation[][] paramAnns = test1Methods[0].getParameterAnnotations();
-            assertEquals(String.class, paramTypes[0]);
-            assertEquals(1, paramAnns[0].length);
-            PathParam test1PathParam1 = (PathParam)paramAnns[0][0];
-            assertEquals("id", test1PathParam1.value());
-            
+            checkComplexPathMethod(test1Methods[0], "");
+            checkComplexPathMethod(test1Methods[1], "2");
         } catch (Exception e) {
             e.printStackTrace();
             fail();
         }
     }
     
+    private void checkComplexPathMethod(Method m, String suffix) {
+        assertNotNull(m.getAnnotation(GET.class));            
+        Path path = m.getAnnotation(Path.class);
+        assertNotNull(path);
+        assertEquals("/get-add-method", path.value());
+        assertEquals("getGetaddmethod" + suffix, m.getName());
+        Class<?>[] paramTypes = m.getParameterTypes();
+        assertEquals(1, paramTypes.length);
+        Annotation[][] paramAnns = m.getParameterAnnotations();
+        assertEquals(String.class, paramTypes[0]);
+        assertEquals(1, paramAnns[0].length);
+        PathParam methodPathParam1 = (PathParam)paramAnns[0][0];
+        assertEquals("id", methodPathParam1.value());
+    }
+    
     @Test    
     public void testCodeGenWithImportedSchemaAndResourceSet() {
         try {

http://git-wip-us.apache.org/repos/asf/cxf/blob/560dfbca/tools/wadlto/jaxrs/src/test/resources/wadl/testComplexPath.xml
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/test/resources/wadl/testComplexPath.xml b/tools/wadlto/jaxrs/src/test/resources/wadl/testComplexPath.xml
index 372ca85..63cf53f 100644
--- a/tools/wadlto/jaxrs/src/test/resources/wadl/testComplexPath.xml
+++ b/tools/wadlto/jaxrs/src/test/resources/wadl/testComplexPath.xml
@@ -7,6 +7,9 @@
         <method name="GET">
           <response/>
         </method>
+        <method name="GET">
+          <response/>
+        </method>
       </resource>
      </resource>
 	</resources>


Mime
View raw message