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

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

commit 5d085d422f60a7e6c70bb9f846dad94049326eb2
Author: reta <[email protected]>
AuthorDate: Sun Jun 28 16:23:35 2020 -0400

    CXF-8307: Invalid class generated if resource contains hyphen
    
    (cherry picked from commit 9a5b4568a94a72569caf4d012a42df6ebbe02779)
---
 .../cxf/tools/wadlto/jaxrs/SourceGenerator.java    |  2 +-
 .../cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java | 21 ++++++++++
 .../src/test/resources/wadl/bookstoreHyphen.xml    | 46 ++++++++++++++++++++++
 3 files changed, 68 insertions(+), 1 deletion(-)

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 d5f93c6..09a14bc 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
@@ -467,7 +467,7 @@ public class SourceGenerator {
         if (resourceId.length() == 0) {
             String path = rElement.getAttribute("path");
             if (path.length() > 0) {
-                path = path.replaceAll("[\\{\\}_]*", "");
+                path = path.replaceAll("[-\\{\\}_]*", "");
                 String[] split = path.split("/");
                 StringBuilder builder = new StringBuilder(resourceId);
                 for (int i = 0; i < split.length; i++) {
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 566f3dc..5820df3 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
@@ -970,6 +970,27 @@ public class JAXRSContainerTest extends ProcessorTestBase {
         }
     }
 
+    public void testCodeGenHyphen() 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/bookstoreHyphen.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.getFilesRecurse(output, ".class");
+        assertEquals(3, files.size());
+        assertTrue(checkContains(files, "application" + 
".BookstoreResource.class"));
+        assertTrue(checkContains(files, "generated" + 
".TestCompositeObject.class"));
+        assertTrue(checkContains(files, "generated" + ".ObjectFactory.class"));
+    }
+
     private void verifyFiles(String ext, boolean subresourceExpected, boolean 
interfacesAndImpl,
                              String schemaPackage, String resourcePackage, int 
expectedCount) {
         verifyFiles(ext, subresourceExpected, interfacesAndImpl, 
schemaPackage, resourcePackage,
diff --git a/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreHyphen.xml 
b/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreHyphen.xml
new file mode 100644
index 0000000..f040db0
--- /dev/null
+++ b/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreHyphen.xml
@@ -0,0 +1,46 @@
+<?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="/book-store">
+            <method name="PUT">
+                <request>
+                    <representation mediaType="application/xml" 
element="test"/>
+                </request>
+                <response>
+                    <representation mediaType="application/xml" 
element="test"/>
+                </response>
+            </method>
+        </resource>
+    </resources>
+</application>

Reply via email to