You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ff...@apache.org on 2021/04/09 17:58:32 UTC

[cxf] branch 3.3.x-fixes updated: [CXF-8456]wadl2java plugin generates classes names with invalid identifiers

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

ffang pushed a commit to branch 3.3.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/3.3.x-fixes by this push:
     new b0e6c23  [CXF-8456]wadl2java plugin generates classes names with invalid identifiers
b0e6c23 is described below

commit b0e6c23c28ab6ec15d4f4bf4a743fa3e7cfad4ef
Author: Freeman Fang <fr...@gmail.com>
AuthorDate: Fri Apr 9 13:56:20 2021 -0400

    [CXF-8456]wadl2java plugin generates classes names with invalid identifiers
    
    (cherry picked from commit e3143ef5212b0aed4a34df3cd842ad331bf02fcb)
    (cherry picked from commit 1b49a198212c1798b7755df2591c948f599f5bef)
---
 .../cxf/tools/wadlto/jaxrs/SourceGenerator.java    |  5 +-
 .../cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java | 23 +++++++++
 .../src/test/resources/wadl/bookstoreDigit.xml     | 56 ++++++++++++++++++++++
 3 files changed, 82 insertions(+), 2 deletions(-)

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 b372ad6..74b91b4 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
@@ -474,6 +474,7 @@ public class SourceGenerator {
                     }
                 }
                 resourceId = builder.toString();
+                
             }
             resourceId += DEFAULT_RESOURCE_NAME;
         }
@@ -489,12 +490,12 @@ public class SourceGenerator {
 
 
         final String className = getClassName(qname.getLocalPart(),
-                info.isInterfaceGenerated(), info.getTypeClassNames());
+                info.isInterfaceGenerated(), info.getTypeClassNames()).replaceFirst("^[- 0-9]*", "");
         if (info.getResourceClassNames().contains(className)) {
             return;
         }
         info.getResourceClassNames().add(className);
-        final String classPackage = getClassPackageName(namespaceURI);
+        final String classPackage = getClassPackageName(namespaceURI.replaceFirst("^[- 0-9]*", ""));
 
         StringBuilder sbImports = new StringBuilder();
         StringBuilder sbCode = new StringBuilder();
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 8f892d6..5d3c558 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
@@ -830,6 +830,29 @@ public class JAXRSContainerTest extends ProcessorTestBase {
         assertTrue(checkContains(files, "generated" + ".TestCompositeObject.class"));
         assertTrue(checkContains(files, "generated" + ".ObjectFactory.class"));
     }
+    
+    @Test
+    public void testCodeGenDigit() throws Exception {
+        JAXRSContainer container = new JAXRSContainer(null);
+
+        ToolContext context = new ToolContext();
+        context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
+        context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/bookstoreDigit.xml"));
+        context.put(WadlToolConstants.CFG_IMPL, "true");
+        context.put(WadlToolConstants.CFG_COMPILE, "true");
+
+        container.setContext(context);
+        container.execute();
+
+        assertNotNull(output.list());
+
+        List<File> files = FileUtils.getFilesRecurseUsingSuffix(output, ".class");
+        assertEquals(4, files.size());
+        assertTrue(checkContains(files, "Api1" + ".BookstoreResource.class"));
+        assertTrue(checkContains(files, "application" + ".BookstoreResource.class"));
+        assertTrue(checkContains(files, "generated" + ".TestCompositeObject.class"));
+        assertTrue(checkContains(files, "generated" + ".ObjectFactory.class"));
+    }
 
     @Test
     public void testCodeGenTypesOnly() throws Exception {
diff --git a/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreDigit.xml b/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreDigit.xml
new file mode 100644
index 0000000..8c90fb5
--- /dev/null
+++ b/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreDigit.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements. See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership. The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License. You may obtain a copy of the License at
+ 
+  http://www.apache.org/licenses/LICENSE-2.0
+ 
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied. See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<application xmlns="http://wadl.dev.java.net/2009/02" 
+	xmlns:xs="http://www.w3.org/2001/XMLSchema">
+    <doc title="My Application"/>
+    <grammars>
+        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+        	<xs:element name="test" type="testCompositeObject"/>
+            <xs:complexType name="testCompositeObject">
+                <xs:sequence>
+                    <xs:element name="id" type="xs:int"/>
+                    <xs:element minOccurs="0" name="name" type="xs:string"/>
+                </xs:sequence>
+            </xs:complexType>
+        </xs:schema>
+    </grammars>
+    <resources base="http://localhost:8080/baz">
+        <resource path="1.0/bookstore">
+            <method name="PUT">
+                <request>
+                    <representation mediaType="application/xml" element="test"/>
+                </request>
+                <response>
+                    <representation mediaType="application/xml" element="test"/>
+                </response>
+            </method>
+        </resource>
+        <resource path="api/1.0/bookstore">
+            <method name="PUT">
+                <request>
+                    <representation mediaType="application/xml" element="test"/>
+                </request>
+                <response>
+                    <representation mediaType="application/xml" element="test"/>
+                </response>
+            </method>
+        </resource>
+    </resources>
+</application>