You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2026/09/28 07:28:17 UTC

(cxf) branch coheigea/wsdl2java created (now e8784314825)

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

coheigea pushed a change to branch coheigea/wsdl2java
in repository https://gitbox.apache.org/repos/asf/cxf.git


      at e8784314825 wsdl2java: escape WSDL documentation in javadoc and validate customized names

This branch includes the following new commits:

     new e8784314825 wsdl2java: escape WSDL documentation in javadoc and validate customized names

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(cxf) 01/01: wsdl2java: escape WSDL documentation in javadoc and validate customized names

Posted by co...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch coheigea/wsdl2java
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit e87843148255a0ea9f8dde9cb4ad1222413d529e
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Mon Sep 28 08:27:52 2026 +0100

    wsdl2java: escape WSDL documentation in javadoc and validate customized names
---
 .../cxf/tools/common/model/JavaInterface.java      | 16 ++++++++++++-
 .../cxf/tools/common/model/JavaInterfaceTest.java  | 20 +++++++++++++++-
 .../jaxws/customization/JAXWSBindingParser.java    | 28 ++++++++++++++++++----
 .../jaxws/customization/Messages.properties        |  1 +
 4 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaInterface.java b/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaInterface.java
index ff34381e50b..e7efbf183e6 100644
--- a/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaInterface.java
+++ b/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaInterface.java
@@ -74,6 +74,7 @@ public class JavaInterface implements JavaAnnotatable {
                         }
                     }
                     if (pfx != null) {
+                        s2 = escapeJavaDocContent(s2);
                         if (d2.length() > 0) {
                             d2.append('\n');
                         }
@@ -88,12 +89,25 @@ public class JavaInterface implements JavaAnnotatable {
                 }
                 d = d2.toString();
             } catch (IOException ex) {
-                //ignore, use the raw value
+                //ignore, use the escaped value
+                d = escapeJavaDocContent(d);
             }
         }
         return d;
     }
 
+    /**
+     * Make sure documentation text taken from a WSDL cannot terminate the
+     * enclosing comment block. Unicode escapes are neutralized as well since
+     * the compiler translates them before lexing.
+     */
+    static String escapeJavaDocContent(String s) {
+        if (s.indexOf("\\u") == -1 && s.indexOf("*/") == -1) {
+            return s;
+        }
+        return s.replace("\\u", "&#92;u").replace("*/", "*&#47;");
+    }
+
     public void setWebServiceName(String wsn) {
         this.webserviceName = wsn;
     }
diff --git a/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaInterfaceTest.java b/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaInterfaceTest.java
index 3f3dd04b7a8..c4894ef9c97 100644
--- a/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaInterfaceTest.java
+++ b/tools/common/src/test/java/org/apache/cxf/tools/common/model/JavaInterfaceTest.java
@@ -22,6 +22,7 @@ package org.apache.cxf.tools.common.model;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 
 public class JavaInterfaceTest {
     @Test
@@ -32,4 +33,21 @@ public class JavaInterfaceTest {
         assertEquals("org.apache.cxf.tools.common.model", intf.getPackageName());
         assertEquals("JavaInterface", intf.getName());
     }
-}
\ No newline at end of file
+
+    @Test
+    public void testFormatJavaDocCannotCloseComment() throws Exception {
+        String doc = "Some docs */ int PWNED = 1; /*\n  more \\u002a/ text";
+        String formatted = JavaInterface.formatJavaDoc(doc, " ");
+        assertFalse(formatted.contains("*/"));
+        assertFalse(formatted.contains("\\u"));
+        assertEquals(" * Some docs *&#47; int PWNED = 1; /*\n *   more &#92;u002a/ text", formatted);
+    }
+
+    @Test
+    public void testFormatJavaDocUnchanged() throws Exception {
+        assertEquals("   * Some docs\n   * a/b * c",
+                     JavaInterface.formatJavaDoc("Some docs\na/b * c", "   "));
+        assertEquals(" * C:\\temp matches \\d+",
+                     JavaInterface.formatJavaDoc("C:\\temp matches \\d+", " "));
+    }
+}
diff --git a/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customization/JAXWSBindingParser.java b/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customization/JAXWSBindingParser.java
index 1935b952dfa..556625d6481 100644
--- a/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customization/JAXWSBindingParser.java
+++ b/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customization/JAXWSBindingParser.java
@@ -22,6 +22,7 @@ package org.apache.cxf.tools.wsdlto.frontend.jaxws.customization;
 import java.util.Iterator;
 import java.util.logging.Logger;
 
+import javax.lang.model.SourceVersion;
 import javax.wsdl.WSDLException;
 import javax.wsdl.extensions.ExtensionRegistry;
 import javax.xml.XMLConstants;
@@ -119,7 +120,7 @@ public class JAXWSBindingParser {
                         }
                     }
 
-                    String name = childElement.getAttribute("name");
+                    String name = checkIdentifier(childElement.getAttribute("name"));
                     String elementNameString = childElement.getAttribute("childElementName");
                     QName elementName = null;
                     if (!StringUtils.isEmpty(elementNameString)) {
@@ -136,7 +137,7 @@ public class JAXWSBindingParser {
                     jaxwsBinding.addJaxwsPara(jpara);
                 } else if (isJAXWSClass(child)) {
                     Element childElement = (Element)child;
-                    String clzName = childElement.getAttribute("name");
+                    String clzName = checkQualifiedName(childElement.getAttribute("name"));
                     String javadoc = "";
                     Node docChild = DOMUtils.getChild(child, Node.ELEMENT_NODE);
 
@@ -160,7 +161,26 @@ public class JAXWSBindingParser {
 
     private String getMethodName(Node node) {
         Element ele = (Element)node;
-        return ele.getAttribute("name");
+        return checkIdentifier(ele.getAttribute("name"));
+    }
+
+    /**
+     * Customized names end up verbatim in the generated source, so they
+     * must be valid Java identifiers.
+     */
+    private static String checkIdentifier(String name) {
+        if (!StringUtils.isEmpty(name)
+            && (!SourceVersion.isIdentifier(name) || SourceVersion.isKeyword(name))) {
+            throw new ToolException(new Message("INVALID_JAVA_NAME", LOG, name));
+        }
+        return name;
+    }
+
+    private static String checkQualifiedName(String name) {
+        if (!StringUtils.isEmpty(name) && !SourceVersion.isName(name)) {
+            throw new ToolException(new Message("INVALID_JAVA_NAME", LOG, name));
+        }
+        return name;
     }
 
 
@@ -188,7 +208,7 @@ public class JAXWSBindingParser {
 
     private String getPackageName(Node node) {
         Element ele = (Element)node;
-        return ele.getAttribute("name");
+        return checkQualifiedName(ele.getAttribute("name"));
     }
 
     private Boolean isAsyncElement(Node node) {
diff --git a/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customization/Messages.properties b/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customization/Messages.properties
index d9889f15f8d..8e1c36083f3 100644
--- a/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customization/Messages.properties
+++ b/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/customization/Messages.properties
@@ -35,3 +35,4 @@ MISSING_WSDL = Unable to read {0}.
 OLD_JAXWS_NAMESPACE = Old JAXWS binding file namespace \"https://java.sun.com/xml/ns/jaxws\" is used.This binding file will be ignored. Please use \"https://jakarta.ee/xml/ns/jaxws\" instead
 OLD_JAXB_NAMESPACE = Old JAXB binding file namespace \"https://java.sun.com/xml/ns/jaxb\" is used.This binding file will be ignored. Please use \"https://jakarta.ee/xml/ns/jaxb\" instead
 INVALID_BINDING_FILE = Not a valid jaxb or jaxws binding file, please check the namespace
+INVALID_JAVA_NAME = Customized name \"{0}\" is not a valid Java name.