Croway commented on code in PR #30224:
URL: https://github.com/apache/camel/pull/30224#discussion_r4598580569


##########
core/camel-core-engine/src/main/docs/modules/eips/pages/to-eip.adoc:
##########
@@ -145,6 +145,13 @@ is capable of computing a dynamic URI using
 an xref:manual::expression.adoc[Expression], such as
 the xref:components:eips:toD-eip.adoc[toD] or 
xref:components:eips:recipientList-eip.adoc[Recipient List] EIP pattern.
 
+The route still starts: the `to` sends every message to one endpoint, named by 
the text of the expression.
+Camel logs a WARN for such a `to` when it creates the route, and the WARN says 
to use `toD`.
+Only the endpoint path is checked, not the options after the `?`. A component 
that evaluates the expressions
+in its path for each message is left alone, such as 
xref:ROOT:language-component.adoc[Language] and
+xref:ROOT:sql-stored-component.adoc[SQL Stored Procedure], as are the 
`:#${...}` parameters of the
+xref:ROOT:sql-component.adoc[SQL] component.

Review Comment:
   Thanks. I checked which components have the flag on a path option: aws2-s3, 
micrometer, opentelemetry-metrics and sql-stored. file and hibernate have it 
only on query options, which the check does not look at. language has no flag: 
it is left alone by name because its path is a script, so it does not fit under 
the metadata sentence. The page now says that, and names 
`@Metadata(supportSimpleExpression = true)` on the path option as what keeps a 
component from the WARN, with sql-stored, aws2-s3 and micrometer as examples 
(0adf74a850dc).
   
   _Claude Code on behalf of Federico Mariani_
   



##########
core/camel-core-reifier/src/main/java/org/apache/camel/reifier/SendReifier.java:
##########
@@ -67,4 +85,83 @@ public Endpoint resolveEndpoint() {
         return answer;
     }
 
+    /**
+     * A to resolves its endpoint once, when the route is created, so a Simple 
expression in the path of its uri is not
+     * evaluated for each message: every message goes to the one endpoint 
named by the text of the expression. Logs a
+     * WARN that says to use toD, unless the component evaluates its path 
itself. It is the rule camel validate checks
+     * the routes with: only the path is looked at, not the options after the 
?.
+     */
+    private void warnIfExpressionInUri() {
+        if (definition.getEndpoint() != null) {
+            // an endpoint given as an object, not a uri written in the route
+            return;
+        }
+        try {
+            String uri = definition.getEndpointUri();
+            if (uri == null) {
+                return;
+            }
+            String resolved = uri;
+            if (uri.contains(PropertiesComponent.PREFIX_TOKEN)) {
+                resolved = 
EndpointHelper.resolveEndpointUriPropertyPlaceholders(camelContext, uri);
+            }
+            String expression = expressionInPath(resolved);
+            if (expression != null && 
!pathTakesExpression(resolved.substring(0, resolved.indexOf(':')))) {
+                LOG.warn("The to in route {} sends to {}, whose uri has the 
expression {}: a to resolves its endpoint"
+                         + " once, when the route is created, so the 
expression is not evaluated for each message, and"
+                         + " every message goes to the endpoint named by its 
text. Use toD to compute the endpoint uri"
+                         + " for each message.",
+                        route.getRouteId(), URISupport.sanitizeUri(uri), 
expression);
+            }
+        } catch (Exception e) {
+            LOG.debug("Cannot check the uri of {} for an expression. This 
exception is ignored.", definition, e);
+        }
+    }
+
+    /**
+     * The first Simple expression in the path of the uri (what comes before 
its options), or null when there is none.

Review Comment:
   The `language` check is in `expressionInPath` itself: 
`SCRIPT_PATH.equals(path.substring(0, colon))` returns null before the loop, 
and `warnIfExpressionInUri` has no such check, so the Javadoc was right. I 
reworded it so it reads as what the method returns: "Null for the language 
component too, whose path is a script" (0adf74a850dc).
   
   _Claude Code on behalf of Federico Mariani_
   



-- 
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