[cxf] branch master updated: CXF-8307: Invalid class generated if resource contains hyphen

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

[cxf] branch master updated: CXF-8307: Invalid class generated if resource contains hyphen

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

reta 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 9a5b456  CXF-8307: Invalid class generated if resource contains hyphen
9a5b456 is described below

commit 9a5b4568a94a72569caf4d012a42df6ebbe02779
Author: reta <[hidden email]>
AuthorDate: Sun Jun 28 16:23:35 2020 -0400

    CXF-8307: Invalid class generated if resource contains hyphen
---
 .../cxf/tools/wadlto/jaxrs/SourceGenerator.java    |  2 +-
 .../cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java | 22 +++++++++++
 .../src/test/resources/wadl/bookstoreHyphen.xml    | 46 ++++++++++++++++++++++
 3 files changed, 69 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 82050e1..7ac8164 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
@@ -441,7 +441,7 @@ public class SourceGenerator {
         if (resourceId.isEmpty()) {
             String path = rElement.getAttribute("path");
             if (!path.isEmpty()) {
-                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 8126ebe..4cf1cea 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
@@ -809,6 +809,28 @@ public class JAXRSContainerTest extends ProcessorTestBase {
     }
 
     @Test
+    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.getFilesRecurseUsingSuffix(output, ".class");
+        assertEquals(3, files.size());
+        assertTrue(checkContains(files, "application" + ".BookstoreResource.class"));
+        assertTrue(checkContains(files, "generated" + ".TestCompositeObject.class"));
+        assertTrue(checkContains(files, "generated" + ".ObjectFactory.class"));
+    }
+
+    @Test
     public void testCodeGenTypesOnly() throws Exception {
         JAXRSContainer container = new JAXRSContainer(null);
 
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>