You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2020/06/28 20:37:45 UTC

[cxf] 01/02: CXF-8307: Invalid class generated if resource contains hyphen

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

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

commit 39e1754a0a145805acb775f755c82223e0ce261a
Author: reta <dr...@gmail.com>
AuthorDate: Sun Jun 28 16:23:35 2020 -0400

    CXF-8307: Invalid class generated if resource contains hyphen
    
    (cherry picked from commit 9a5b4568a94a72569caf4d012a42df6ebbe02779)
    
    # Conflicts:
    #	tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
---
 .../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 af72010..b372ad6 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
@@ -465,7 +465,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 f948a48..8f892d6 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
@@ -810,6 +810,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>