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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new cca71a606f89 CAMEL-27393: camel-catalog - split the path of a 
spring-ws URI as the component does (#30743)
cca71a606f89 is described below

commit cca71a606f89d00a81f9fc983e3fb9500ff1074c
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Nov 25 08:09:54 2026 +0100

    CAMEL-27393: camel-catalog - split the path of a spring-ws URI as the 
component does (#30743)
    
    
    The catalog split the path of a spring-ws URI by the syntax
    type:lookupKey:webServiceEndpointUri, but a real URI has either a type and a
    lookupKey (consumer) or a webServiceEndpointUri (producer), and both the
    lookupKey and the address may contain colons. So endpointProperties gave the
    parts to the wrong options: spring-ws:http://localhost:8080/ws gave 
type=http
    (reported as an invalid enum value by validateEndpointProperties, which the
    validate goal of camel-report-maven-plugin calls for every endpoint URI),
    spring-ws:http://localhost/ws gave webServiceEndpointUri=http, and
    spring-ws:soapaction:urn:GetFoo gave lookupKey=urn. asEndpointUri then built
    broken URIs from these.
    
    The catalog now splits a spring-ws path as SpringWebserviceComponent does
    (EndpointMappingType.getTypeFromUriPrefix): a path that starts with one of 
the
    type prefixes (rootqname:, action:, to:, soapaction:, xpathresult:, uri:,
    uripath:, beanname:, case-insensitive) is the type and the lookupKey (the 
rest
    of the path), and any other path is the webServiceEndpointUri. This follows
    the special case findTokens already has for activemq and jms. asEndpointUri
    needed no change, as it builds the path from the options that are set.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../camel/catalog/CamelCatalogEdgeCasesTest.java   |   2 +-
 .../org/apache/camel/catalog/CamelCatalogTest.java | 113 +++++++++++++++++++++
 .../camel/catalog/impl/AbstractCamelCatalog.java   |  32 ++++++
 3 files changed, 146 insertions(+), 1 deletion(-)

diff --git 
a/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogEdgeCasesTest.java
 
b/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogEdgeCasesTest.java
index 948be7dfac8f..1e63f465dfdd 100644
--- 
a/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogEdgeCasesTest.java
+++ 
b/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogEdgeCasesTest.java
@@ -74,7 +74,7 @@ public class CamelCatalogEdgeCasesTest {
         assertEquals("dir", map.get("directoryName"));
         assertFalse(map.containsKey("port"));
 
-        // separators that are the same cannot tell which option is omitted
+        // the address of a spring-ws producer is not split at its colons 
(spring-ws has its own split, CAMEL-27393)
         EndpointValidationResult result = 
catalog.validateEndpointProperties("spring-ws:http://foo.com/bar";);
         assertTrue(result.isSuccess(), result.summaryErrorMessage(false));
 
diff --git 
a/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
 
b/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
index bb8319cf4bd2..fdedd928b94f 100644
--- 
a/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
+++ 
b/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
@@ -1926,6 +1926,119 @@ public class CamelCatalogTest {
         assertTrue(result.isSuccess(), result.summaryErrorMessage(false));
     }
 
+    @Test
+    public void testSpringWsEndpointPropertiesConsumer() throws Exception {
+        // a path that starts with a type prefix is the type and the lookupKey 
(the rest, which may contain colons)
+        Map<String, String> map = 
catalog.endpointProperties("spring-ws:soapaction:urn:GetFoo");
+        assertEquals(2, map.size());
+        assertEquals("soapaction", map.get("type"));
+        assertEquals("urn:GetFoo", map.get("lookupKey"));
+
+        map = catalog.endpointProperties("spring-ws:beanname:myDispatcher");
+        assertEquals(2, map.size());
+        assertEquals("beanname", map.get("type"));
+        assertEquals("myDispatcher", map.get("lookupKey"));
+
+        map = 
catalog.endpointProperties("spring-ws:rootqname:{http://example.com/}GetFoo?endpointMapping=#m";);
+        assertEquals(3, map.size());
+        assertEquals("rootqname", map.get("type"));
+        assertEquals("{http://example.com/}GetFoo";, map.get("lookupKey"));
+        assertEquals("#m", map.get("endpointMapping"));
+
+        map = 
catalog.endpointProperties("spring-ws:action:http://example.com/GetFoo?endpointMapping=#m";);
+        assertEquals("action", map.get("type"));
+        assertEquals("http://example.com/GetFoo";, map.get("lookupKey"));
+        assertNull(map.get("webServiceEndpointUri"));
+
+        map = 
catalog.endpointProperties("spring-ws:xpathresult:abc?expression=//foo&endpointMapping=#m");
+        assertEquals("xpathresult", map.get("type"));
+        assertEquals("abc", map.get("lookupKey"));
+        assertEquals("//foo", map.get("expression"));
+
+        // the type prefix is case-insensitive, as in the component
+        map = catalog.endpointProperties("spring-ws:SoapAction:urn:GetFoo");
+        assertEquals("SoapAction", map.get("type"));
+        assertEquals("urn:GetFoo", map.get("lookupKey"));
+
+        // a placeholder in the lookupKey
+        map = 
catalog.endpointProperties("spring-ws:uripath:{{env:WS_PATH:/ws/foo}}");
+        assertEquals("uripath", map.get("type"));
+        assertEquals("{{env:WS_PATH:/ws/foo}}", map.get("lookupKey"));
+    }
+
+    @Test
+    public void testSpringWsEndpointPropertiesProducer() throws Exception {
+        // a path that does not start with a type prefix is the address of the 
producer
+        Map<String, String> map = 
catalog.endpointProperties("spring-ws:http://localhost/ws";);
+        assertEquals(1, map.size());
+        assertEquals("http://localhost/ws";, map.get("webServiceEndpointUri"));
+
+        map = catalog.endpointProperties("spring-ws:http://localhost:8080/ws";);
+        assertEquals(1, map.size());
+        assertEquals("http://localhost:8080/ws";, 
map.get("webServiceEndpointUri"));
+
+        map = 
catalog.endpointProperties("spring-ws:https://host:8443/a/b?soapAction=x";);
+        assertEquals(2, map.size());
+        assertEquals("https://host:8443/a/b";, 
map.get("webServiceEndpointUri"));
+        assertEquals("x", map.get("soapAction"));
+
+        map = 
catalog.endpointProperties("spring-ws:{{env:WS_URL:http://localhost:8080/ws}}";);
+        assertEquals(1, map.size());
+        assertEquals("{{env:WS_URL:http://localhost:8080/ws}}";, 
map.get("webServiceEndpointUri"));
+    }
+
+    @Test
+    public void testSpringWsValidateEndpointProperties() {
+        // the port of the address is not taken as the lookupKey, and the 
scheme of the address not as the type
+        EndpointValidationResult result = 
catalog.validateEndpointProperties("spring-ws:http://localhost:8080/ws";);
+        assertTrue(result.isSuccess(), result.summaryErrorMessage(false));
+
+        result = 
catalog.validateEndpointProperties("spring-ws:https://host:8443/a/b?soapAction=x";,
 false, false, true);
+        assertTrue(result.isSuccess(), result.summaryErrorMessage(false));
+
+        result = 
catalog.validateEndpointProperties("spring-ws:rootqname:{http://example.com/}GetFoo?endpointMapping=#m";,
+                false, true, false);
+        assertTrue(result.isSuccess(), result.summaryErrorMessage(false));
+
+        result = 
catalog.validateEndpointProperties("spring-ws:beanname:myDispatcher", false, 
true, false);
+        assertTrue(result.isSuccess(), result.summaryErrorMessage(false));
+
+        // a producer option on a consumer uri is still reported
+        result = 
catalog.validateEndpointProperties("spring-ws:soapaction:urn:GetFoo?endpointMapping=#m&soapAction=x",
+                false, true, false);
+        assertFalse(result.isSuccess());
+        assertTrue(result.getNotConsumerOnly().contains("soapAction"));
+    }
+
+    @Test
+    public void testSpringWsAsEndpointUriRoundTrip() throws Exception {
+        String[] uris = {
+                
"spring-ws:rootqname:{http://example.com/}GetFoo?endpointMapping=#m";,
+                "spring-ws:soapaction:urn:GetFoo",
+                "spring-ws:beanname:myDispatcher",
+                
"spring-ws:xpathresult:abc?expression=//foo&endpointMapping=#m",
+                
"spring-ws:action:http://example.com/GetFoo?endpointMapping=#m";,
+                "spring-ws:http://localhost/ws";,
+                "spring-ws:http://localhost:8080/ws";,
+                "spring-ws:https://host:8443/a/b?soapAction=x"; };
+        for (String uri : uris) {
+            Map<String, String> map = catalog.endpointProperties(uri);
+            assertEquals(uri, catalog.asEndpointUri("spring-ws", map, false));
+        }
+
+        // build from the options
+        Map<String, String> map = new LinkedHashMap<>();
+        map.put("type", "soapaction");
+        map.put("lookupKey", "urn:GetFoo");
+        map.put("endpointMapping", "#m");
+        assertEquals("spring-ws:soapaction:urn:GetFoo?endpointMapping=#m", 
catalog.asEndpointUri("spring-ws", map, false));
+
+        map = new LinkedHashMap<>();
+        map.put("webServiceEndpointUri", "http://localhost:8080/ws";);
+        map.put("soapAction", "x");
+        assertEquals("spring-ws:http://localhost:8080/ws?soapAction=x";, 
catalog.asEndpointUri("spring-ws", map, false));
+    }
+
     @Test
     public void testNettyHttpDynamicToIssue() throws Exception {
         String uri = 
"netty-http:http://10.192.1.10:8080/client/alerts/summary?throwExceptionOnFailure=false";;
diff --git 
a/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java
 
b/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java
index 9d38a0d174d6..6c94d2576eb8 100644
--- 
a/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java
+++ 
b/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java
@@ -78,6 +78,9 @@ public abstract class AbstractCamelCatalog {
     private static final Pattern ENV_OR_SYS_PATTERN = 
Pattern.compile("\\{\\{(env|sys):\\w+(:[^{}]*)?\\}\\}");
     private static final String ENV_OR_SYS_WORD = "CamelEnvOrSysPlaceholder";
     private static final Pattern COMPONENT_SYNTAX_PARSER = 
Pattern.compile("([^\\w-]*)([\\w-]+)");
+    // the uri prefixes of the endpoint mapping types of spring-ws 
(EndpointMappingType in camel-spring-ws)
+    private static final List<String> SPRING_WS_TYPES
+            = List.of("rootqname", "action", "to", "soapaction", 
"xpathresult", "uri", "uripath", "beanname");
 
     private SuggestionStrategy suggestionStrategy = new 
EditDistanceSuggestionStrategy();
     private JSonSchemaResolver jsonSchemaResolver;
@@ -786,6 +789,12 @@ public abstract class AbstractCamelCatalog {
     }
 
     private static List<String> findTokens(String syntax, String scheme, 
String uriPath, List<Integer> positions) {
+        // special for spring-ws where the path is either the type and the 
lookupKey (consumer) or the address
+        // (producer), and both the lookupKey and the address may contain 
colons
+        if ("spring-ws".equals(scheme)) {
+            return findSpringWsTokens(uriPath, positions);
+        }
+
         String[] tokens = SYNTAX_PATTERN.split(syntax);
 
         // find the position where each option start/end
@@ -850,6 +859,29 @@ public abstract class AbstractCamelCatalog {
         return word2;
     }
 
+    /**
+     * Splits the path of a spring-ws endpoint (syntax 
type:lookupKey:webServiceEndpointUri) as the component does: a
+     * path that starts with a type prefix (case-insensitive) is the type and 
the lookupKey (the rest of the path), and
+     * any other path is the webServiceEndpointUri of the producer.
+     */
+    private static List<String> findSpringWsTokens(String uriPath, 
List<Integer> positions) {
+        List<String> answer = new ArrayList<>();
+        for (String type : SPRING_WS_TYPES) {
+            if (uriPath.regionMatches(true, 0, type + ":", 0, type.length() + 
1)) {
+                // type and lookupKey are the 1st and 2nd option in the syntax
+                answer.add(uriPath.substring(0, type.length()));
+                positions.add(0);
+                answer.add(uriPath.substring(type.length() + 1));
+                positions.add(1);
+                return answer;
+            }
+        }
+        // webServiceEndpointUri is the 3rd option in the syntax
+        answer.add(uriPath);
+        positions.add(2);
+        return answer;
+    }
+
     private Map<String, BaseOptionModel> extractApiProperties(ComponentModel 
model, String key, String key2) {
         Map<String, BaseOptionModel> answer = new LinkedHashMap<>();
         if (key != null) {

Reply via email to