gnodet commented on code in PR #25315:
URL: https://github.com/apache/camel/pull/25315#discussion_r3706198465


##########
core/camel-core-processor/src/main/java/org/apache/camel/processor/SendDynamicProcessor.java:
##########
@@ -494,4 +507,24 @@ public boolean isAutoStartupComponents() {
     public void setAutoStartupComponents(boolean autoStartupComponents) {
         this.autoStartupComponents = autoStartupComponents;
     }
+
+    public String getAllowedSchemes() {
+        return allowedSchemes;
+    }
+
+    public void setAllowedSchemes(String allowedSchemes) {
+        this.allowedSchemes = allowedSchemes;
+    }
+
+    private boolean isSchemeAllowed(String scheme) {
+        if (allowedSchemes == null) {
+            return true;
+        }
+        for (String allowed : allowedSchemes.split(",")) {
+            if (allowed.trim().equals(scheme)) {

Review Comment:
   **Performance nit:** `allowedSchemes.split(",")` allocates a new `String[]` 
on every exchange. For a high-throughput route this adds up. Consider 
pre-parsing into a `Set<String>` once in `setAllowedSchemes()`:
   
   ```java
   private Set<String> allowedSchemesSet;
   
   public void setAllowedSchemes(String allowedSchemes) {
       this.allowedSchemes = allowedSchemes;
       if (allowedSchemes != null) {
           this.allowedSchemesSet = Arrays.stream(allowedSchemes.split(","))
                   .map(String::trim)
                   .filter(s -> !s.isEmpty())
                   .collect(Collectors.toUnmodifiableSet());
       } else {
           this.allowedSchemesSet = null;
       }
   }
   
   private boolean isSchemeAllowed(String scheme) {
       if (allowedSchemesSet == null) {
           return true;
       }
       return allowedSchemesSet.contains(scheme);
   }
   ```
   
   This also makes the whitespace-trimming behavior consistent for all entries.



##########
core/camel-core/src/test/java/org/apache/camel/processor/ToDynamicAllowedSchemesTest.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+package org.apache.camel.processor;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/**
+ * The optional {@code allowedSchemes} allow-list on {@code toD} restricts 
which component schemes a dynamic recipient
+ * may resolve to. A recipient whose scheme is not in the list is rejected, 
independently of
+ * {@code ignoreInvalidEndpoint}. See CAMEL-24298.
+ */
+class ToDynamicAllowedSchemesTest extends ContextTestSupport {
+
+    @Test
+    void allowedSchemeIsSent() throws Exception {
+        getMockEndpoint("mock:allowed").expectedMessageCount(1);
+
+        template.sendBodyAndHeader("direct:start", "Hello", "target", 
"mock:allowed");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    void disallowedSchemeIsRejected() {
+        assertThatThrownBy(() -> template.sendBodyAndHeader("direct:start", 
"Hello", "target", "seda:blocked"))
+                .isInstanceOf(CamelExecutionException.class)
+                .cause()
+                .isInstanceOf(ResolveEndpointFailedException.class)
+                .hasMessageContaining("not in the allowed schemes");
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                
from("direct:start").toD().allowedSchemes("mock").uri("${header.target}");
+            }
+        };
+    }
+}

Review Comment:
   **Test coverage suggestion:** The test covers the core positive/negative 
paths well, but the route only configures a single allowed scheme (`"mock"`). 
Since the documented use case is a comma-separated list (`"http,https"`), it 
would strengthen confidence to also test:
   
   1. Multiple allowed schemes (e.g. `"mock,seda"`) — verify both are accepted
   2. Whitespace in the list (e.g. `"mock, seda"`) — the code handles this via 
`allowed.trim()` but it's untested
   
   Could be a follow-up — not blocking.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to