This is an automated email from the ASF dual-hosted git repository.
Croway 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 acc24d3ea106 CAMEL-27065: camel-core - a to with a Simple expression
in its endpoint uri logs a WARN that says to use toD (#30224)
acc24d3ea106 is described below
commit acc24d3ea10625d54c79aa2a9053ed73161d38f9
Author: Federico Mariani <[email protected]>
AuthorDate: Tue Nov 17 13:20:36 2026 +0100
CAMEL-27065: camel-core - a to with a Simple expression in its endpoint uri
logs a WARN that says to use toD (#30224)
* CAMEL-27065: camel-core - a to with a Simple expression in its endpoint
uri logs a WARN that says to use toD
A to resolves its endpoint once, when the route is created, so
to("jms:queue:${header.q}") sends every message to one
endpoint named by the text of the expression, and nothing said so at
runtime. SendReifier now logs a WARN for such a
to, with the rule camel validate uses: only the path is looked at, not the
options after the ?, and the language
component, the :#${...} and :#in:${...} parameters of sql, and the
components whose path option has
supportSimpleExpression in their metadata are left alone. A component
without metadata is left alone too.
The template of sql-stored and the bucket name of aws2-s3 are evaluated for
each message, so their path options get
supportSimpleExpression, which also keeps the offline checks from reporting
them.
* CAMEL-27065: camel-core - the To EIP page says how a component marks a
path it evaluates for each message
The To EIP page names the supportSimpleExpression metadata of the path
option as what keeps a component from the
WARN, with sql-stored, aws2-s3 and micrometer as examples, and says the
language component is left alone because its
path is a script. The Javadoc of SendReifier.expressionInPath says it
returns null for the language component. The
test sends two messages and checks the WARN is logged once.
---
.../apache/camel/catalog/components/aws2-s3.json | 2 +-
.../camel/catalog/components/sql-stored.json | 2 +-
.../org/apache/camel/catalog/docs/to-eip.adoc | 9 +
.../apache/camel/component/aws2/s3/aws2-s3.json | 2 +-
.../camel/component/aws2/s3/AWS2S3Endpoint.java | 2 +-
.../camel/component/sql/stored/sql-stored.json | 2 +-
.../component/sql/stored/SqlStoredEndpoint.java | 3 +-
.../src/main/docs/modules/eips/pages/to-eip.adoc | 9 +
.../java/org/apache/camel/reifier/SendReifier.java | 99 ++++++++++-
.../reifier/SendReifierExpressionInUriTest.java | 196 +++++++++++++++++++++
.../org/apache/camel/reifier/evaluatedpath.json | 14 ++
.../org/apache/camel/reifier/fixedpath.json | 14 ++
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 9 +
13 files changed, 356 insertions(+), 7 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-s3.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-s3.json
index 219d3cac429d..3d1b7c78e8db 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-s3.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-s3.json
@@ -151,7 +151,7 @@
"producerOut": { "carriers": [ "unchanged" ], "byOption": [ { "option":
"operation", "value": "getObject", "carriers": [ "stream" ] }, { "option":
"operation", "value": "getObjectRange", "carriers": [ "stream" ] }, { "option":
"operation", "value": "listObjects", "carriers": [ "list" ], "javaType":
"java.util.List<software.amazon.awssdk.services.s3.model.S3Object>" }, {
"option": "operation", "value": "listBuckets", "carriers": [ "list" ],
"javaType": "java.util.List<software.amazon. [...]
},
"properties": {
- "bucketNameOrArn": { "index": 0, "kind": "path", "displayName": "Bucket
Name Or Arn", "group": "common", "label": "", "required": true, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "description": "Bucket name or ARN" },
+ "bucketNameOrArn": { "index": 0, "kind": "path", "displayName": "Bucket
Name Or Arn", "group": "common", "label": "", "required": true, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "supportSimpleExpression": true, "description": "Bucket
name or ARN" },
"autoCreateBucket": { "index": 1, "kind": "parameter", "displayName":
"Auto Create Bucket", "group": "common", "label": "common", "required": false,
"type": "boolean", "javaType": "boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.aws2.s3.AWS2S3Configuration", "configurationField":
"configuration", "description": "Setting the autocreation of the S3 bucket
bucketName. This will apply also in cas [...]
"delimiter": { "index": 2, "kind": "parameter", "displayName":
"Delimiter", "group": "common", "label": "", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "configurationClass":
"org.apache.camel.component.aws2.s3.AWS2S3Configuration", "configurationField":
"configuration", "description": "The delimiter which is used in the
com.amazonaws.services.s3.model.ListObjectsRequest to only consume objects we
are i [...]
"forcePathStyle": { "index": 3, "kind": "parameter", "displayName": "Force
Path Style", "group": "common", "label": "", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.aws2.s3.AWS2S3Configuration", "configurationField":
"configuration", "description": "Set whether the S3 client should use
path-style URL instead of virtual-hosted-style" },
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/sql-stored.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/sql-stored.json
index da425f8f07f9..b6a8551ad475 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/sql-stored.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/sql-stored.json
@@ -40,7 +40,7 @@
"producerOut": { "carriers": [ "map" ], "javaType": "java.util.Map<String,
Object>", "dependsOn": [ "outputHeader" ], "byOption": [ { "option": "noop",
"value": "true", "carriers": [ "unchanged" ] }, { "option": "batch", "value":
"true", "carriers": [ "unchanged" ] } ], "description": "A Map of the names of
the OUT and INOUT parameters and their values, with a result set the procedure
returns under #result-set-1 (a List of Maps) and the update count under
#update-count-1, which is al [...]
},
"properties": {
- "template": { "index": 0, "kind": "path", "displayName": "Template",
"group": "producer", "label": "", "required": true, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "supportFileReference": true, "largeInput": true,
"inputLanguage": "sql", "description": "Sets the stored procedure template to
perform. You can externalize the template by using file: or classpath: as
prefix and specify the location of the file." },
+ "template": { "index": 0, "kind": "path", "displayName": "Template",
"group": "producer", "label": "", "required": true, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "supportFileReference": true, "largeInput": true,
"supportSimpleExpression": true, "inputLanguage": "sql", "description": "Sets
the stored procedure template to perform. You can externalize the template by
using file: or classpath: as prefix and specify the l [...]
"batch": { "index": 1, "kind": "parameter", "displayName": "Batch",
"group": "producer", "label": "", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "description": "Enables or disables batch mode" },
"dataSource": { "index": 2, "kind": "parameter", "displayName": "Data
Source", "group": "producer", "label": "", "required": false, "type": "object",
"javaType": "javax.sql.DataSource", "deprecated": false, "autowired": false,
"secret": false, "description": "Sets the DataSource to use to communicate with
the database." },
"function": { "index": 3, "kind": "parameter", "displayName": "Function",
"group": "producer", "label": "", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "description": "Whether this call is for a
function." },
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/to-eip.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/to-eip.adoc
index 2ec2080a6001..c20c3269f7ea 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/to-eip.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/to-eip.adoc
@@ -145,6 +145,15 @@ 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 `?`. Left alone
are the
+xref:ROOT:language-component.adoc[Language] component, whose path is a script,
the `:#${...}` parameters of the
+xref:ROOT:sql-component.adoc[SQL] component, and the components that evaluate
their path for each message: they mark
+their path option with `@Metadata(supportSimpleExpression = true)`, as
+xref:ROOT:sql-stored-component.adoc[SQL Stored Procedure],
xref:ROOT:aws2-s3-component.adoc[AWS S3] and
+xref:ROOT:micrometer-component.adoc[Micrometer] do.
+
[TIP]
====
*This is valid code*
diff --git
a/components/camel-aws/camel-aws2-s3/src/generated/resources/META-INF/org/apache/camel/component/aws2/s3/aws2-s3.json
b/components/camel-aws/camel-aws2-s3/src/generated/resources/META-INF/org/apache/camel/component/aws2/s3/aws2-s3.json
index 219d3cac429d..3d1b7c78e8db 100644
---
a/components/camel-aws/camel-aws2-s3/src/generated/resources/META-INF/org/apache/camel/component/aws2/s3/aws2-s3.json
+++
b/components/camel-aws/camel-aws2-s3/src/generated/resources/META-INF/org/apache/camel/component/aws2/s3/aws2-s3.json
@@ -151,7 +151,7 @@
"producerOut": { "carriers": [ "unchanged" ], "byOption": [ { "option":
"operation", "value": "getObject", "carriers": [ "stream" ] }, { "option":
"operation", "value": "getObjectRange", "carriers": [ "stream" ] }, { "option":
"operation", "value": "listObjects", "carriers": [ "list" ], "javaType":
"java.util.List<software.amazon.awssdk.services.s3.model.S3Object>" }, {
"option": "operation", "value": "listBuckets", "carriers": [ "list" ],
"javaType": "java.util.List<software.amazon. [...]
},
"properties": {
- "bucketNameOrArn": { "index": 0, "kind": "path", "displayName": "Bucket
Name Or Arn", "group": "common", "label": "", "required": true, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "description": "Bucket name or ARN" },
+ "bucketNameOrArn": { "index": 0, "kind": "path", "displayName": "Bucket
Name Or Arn", "group": "common", "label": "", "required": true, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "supportSimpleExpression": true, "description": "Bucket
name or ARN" },
"autoCreateBucket": { "index": 1, "kind": "parameter", "displayName":
"Auto Create Bucket", "group": "common", "label": "common", "required": false,
"type": "boolean", "javaType": "boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.aws2.s3.AWS2S3Configuration", "configurationField":
"configuration", "description": "Setting the autocreation of the S3 bucket
bucketName. This will apply also in cas [...]
"delimiter": { "index": 2, "kind": "parameter", "displayName":
"Delimiter", "group": "common", "label": "", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "configurationClass":
"org.apache.camel.component.aws2.s3.AWS2S3Configuration", "configurationField":
"configuration", "description": "The delimiter which is used in the
com.amazonaws.services.s3.model.ListObjectsRequest to only consume objects we
are i [...]
"forcePathStyle": { "index": 3, "kind": "parameter", "displayName": "Force
Path Style", "group": "common", "label": "", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.aws2.s3.AWS2S3Configuration", "configurationField":
"configuration", "description": "Set whether the S3 client should use
path-style URL instead of virtual-hosted-style" },
diff --git
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Endpoint.java
b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Endpoint.java
index dca21b1e5c22..794e0b21b591 100644
---
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Endpoint.java
+++
b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Endpoint.java
@@ -148,7 +148,7 @@ public class AWS2S3Endpoint extends ScheduledPollEndpoint
implements EndpointSer
private S3Client s3Client;
@UriPath(description = "Bucket name or ARN")
- @Metadata(required = true)
+ @Metadata(required = true, supportSimpleExpression = true)
private String bucketNameOrArn; // to support component docs
@UriParam
private AWS2S3Configuration configuration;
diff --git
a/components/camel-sql/src/generated/resources/META-INF/org/apache/camel/component/sql/stored/sql-stored.json
b/components/camel-sql/src/generated/resources/META-INF/org/apache/camel/component/sql/stored/sql-stored.json
index da425f8f07f9..b6a8551ad475 100644
---
a/components/camel-sql/src/generated/resources/META-INF/org/apache/camel/component/sql/stored/sql-stored.json
+++
b/components/camel-sql/src/generated/resources/META-INF/org/apache/camel/component/sql/stored/sql-stored.json
@@ -40,7 +40,7 @@
"producerOut": { "carriers": [ "map" ], "javaType": "java.util.Map<String,
Object>", "dependsOn": [ "outputHeader" ], "byOption": [ { "option": "noop",
"value": "true", "carriers": [ "unchanged" ] }, { "option": "batch", "value":
"true", "carriers": [ "unchanged" ] } ], "description": "A Map of the names of
the OUT and INOUT parameters and their values, with a result set the procedure
returns under #result-set-1 (a List of Maps) and the update count under
#update-count-1, which is al [...]
},
"properties": {
- "template": { "index": 0, "kind": "path", "displayName": "Template",
"group": "producer", "label": "", "required": true, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "supportFileReference": true, "largeInput": true,
"inputLanguage": "sql", "description": "Sets the stored procedure template to
perform. You can externalize the template by using file: or classpath: as
prefix and specify the location of the file." },
+ "template": { "index": 0, "kind": "path", "displayName": "Template",
"group": "producer", "label": "", "required": true, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "supportFileReference": true, "largeInput": true,
"supportSimpleExpression": true, "inputLanguage": "sql", "description": "Sets
the stored procedure template to perform. You can externalize the template by
using file: or classpath: as prefix and specify the l [...]
"batch": { "index": 1, "kind": "parameter", "displayName": "Batch",
"group": "producer", "label": "", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "description": "Enables or disables batch mode" },
"dataSource": { "index": 2, "kind": "parameter", "displayName": "Data
Source", "group": "producer", "label": "", "required": false, "type": "object",
"javaType": "javax.sql.DataSource", "deprecated": false, "autowired": false,
"secret": false, "description": "Sets the DataSource to use to communicate with
the database." },
"function": { "index": 3, "kind": "parameter", "displayName": "Function",
"group": "producer", "label": "", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "description": "Whether this call is for a
function." },
diff --git
a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredEndpoint.java
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredEndpoint.java
index fdc5414db542..93f65cd13f21 100644
---
a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredEndpoint.java
+++
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredEndpoint.java
@@ -79,7 +79,8 @@ public class SqlStoredEndpoint extends DefaultEndpoint
implements EndpointServic
private Map<String, String> serviceMetadata;
@UriPath(description = "Sets the stored procedure template to perform. You
can externalize the template by using file: or classpath: as prefix and specify
the location of the file.")
- @Metadata(required = true, supportFileReference = true, largeInput = true,
inputLanguage = "sql")
+ @Metadata(required = true, supportFileReference = true, largeInput = true,
inputLanguage = "sql",
+ supportSimpleExpression = true)
private String template;
@UriParam(description = "Sets the DataSource to use to communicate with
the database.")
private DataSource dataSource;
diff --git
a/core/camel-core-engine/src/main/docs/modules/eips/pages/to-eip.adoc
b/core/camel-core-engine/src/main/docs/modules/eips/pages/to-eip.adoc
index 2ec2080a6001..c20c3269f7ea 100644
--- a/core/camel-core-engine/src/main/docs/modules/eips/pages/to-eip.adoc
+++ b/core/camel-core-engine/src/main/docs/modules/eips/pages/to-eip.adoc
@@ -145,6 +145,15 @@ 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 `?`. Left alone
are the
+xref:ROOT:language-component.adoc[Language] component, whose path is a script,
the `:#${...}` parameters of the
+xref:ROOT:sql-component.adoc[SQL] component, and the components that evaluate
their path for each message: they mark
+their path option with `@Metadata(supportSimpleExpression = true)`, as
+xref:ROOT:sql-stored-component.adoc[SQL Stored Procedure],
xref:ROOT:aws2-s3-component.adoc[AWS S3] and
+xref:ROOT:micrometer-component.adoc[Micrometer] do.
+
[TIP]
====
*This is valid code*
diff --git
a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/SendReifier.java
b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/SendReifier.java
index f724016d9623..c2fc8933e64e 100644
---
a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/SendReifier.java
+++
b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/SendReifier.java
@@ -16,6 +16,10 @@
*/
package org.apache.camel.reifier;
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.camel.CatalogCamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.ExchangePattern;
import org.apache.camel.LineNumberAware;
@@ -26,10 +30,22 @@ import org.apache.camel.model.ProcessorDefinitionHelper;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.ToDefinition;
import org.apache.camel.processor.SendProcessor;
+import org.apache.camel.spi.PropertiesComponent;
import org.apache.camel.support.CamelContextHelper;
+import org.apache.camel.support.EndpointHelper;
+import org.apache.camel.util.URISupport;
+import org.apache.camel.util.json.JsonObject;
+import org.apache.camel.util.json.Jsoner;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class SendReifier extends ProcessorReifier<ToDefinition> {
+ private static final Logger LOG =
LoggerFactory.getLogger(SendReifier.class);
+
+ /** The component whose path is a script in another language, not an
address: language:simple:Hello ${body}. */
+ private static final String SCRIPT_PATH = "language";
+
public SendReifier(Route route, ProcessorDefinition<?> definition) {
super(route, (ToDefinition) definition);
}
@@ -45,7 +61,9 @@ public class SendReifier extends
ProcessorReifier<ToDefinition> {
}
}
- SendProcessor answer = new SendProcessor(resolveEndpoint(),
parse(ExchangePattern.class, definition.getPattern()));
+ Endpoint endpoint = resolveEndpoint();
+ warnIfExpressionInUri();
+ SendProcessor answer = new SendProcessor(endpoint,
parse(ExchangePattern.class, definition.getPattern()));
answer.setDisabled(isDisabled(camelContext, definition));
answer.setVariableSend(parseString(definition.getVariableSend()));
answer.setVariableReceive(parseString(definition.getVariableReceive()));
@@ -67,4 +85,83 @@ public class SendReifier extends
ProcessorReifier<ToDefinition> {
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.
+ * Null for the language component too, whose path is a script. A :#${...}
or :#in:${...} is skipped: it is a
+ * parameter the sql components bind for each message, not a part of the
address.
+ */
+ private static String expressionInPath(String uri) {
+ int question = uri.indexOf('?');
+ String path = question >= 0 ? uri.substring(0, question) : uri;
+ int colon = path.indexOf(':');
+ if (colon <= 0 || SCRIPT_PATH.equals(path.substring(0, colon))) {
+ return null;
+ }
+ for (int i = path.indexOf('$', colon); i >= 0; i = path.indexOf('$', i
+ 1)) {
+ if ((path.startsWith("${", i) || path.startsWith("$simple{", i))
+ && !path.startsWith(":#", i - 2) &&
!path.startsWith(":#in:", i - 5)) {
+ int end = path.indexOf('}', i);
+ return end > 0 ? path.substring(i, end + 1) :
path.substring(i);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Whether the component may evaluate its path for each message: a path
option of its metadata supports a Simple
+ * expression (micrometer, sql-stored), or the component has no metadata,
and then nothing is said rather than the
+ * wrong thing.
+ */
+ private boolean pathTakesExpression(String scheme) throws IOException {
+ if (!(camelContext instanceof CatalogCamelContext catalog)) {
+ return true;
+ }
+ String json = catalog.getComponentParameterJsonSchema(scheme);
+ JsonObject root = json != null ? Jsoner.deserialize(json, (JsonObject)
null) : null;
+ Map<String, Object> properties = root != null ?
root.getMap("properties") : null;
+ if (properties == null) {
+ return true;
+ }
+ for (Object value : properties.values()) {
+ if (value instanceof JsonObject option &&
"path".equals(option.getString("kind"))
+ &&
Boolean.TRUE.equals(option.getBoolean("supportSimpleExpression"))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
}
diff --git
a/core/camel-core/src/test/java/org/apache/camel/reifier/SendReifierExpressionInUriTest.java
b/core/camel-core/src/test/java/org/apache/camel/reifier/SendReifierExpressionInUriTest.java
new file mode 100644
index 000000000000..4841732b0c50
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/reifier/SendReifierExpressionInUriTest.java
@@ -0,0 +1,196 @@
+/*
+ * 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.reifier;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.log.ConsumingAppender;
+import org.apache.camel.component.mock.MockComponent;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * A to resolves its endpoint once, when the route is created, so a Simple
expression in the path of its uri is sent as
+ * text. The route still starts, and a WARN names toD, except where the
component evaluates its path for each message.
+ */
+public class SendReifierExpressionInUriTest extends ContextTestSupport {
+
+ private static final String LOGGER = SendReifier.class.getName();
+ private static final String APPENDER = "SendReifierExpressionInUriTest";
+
+ private final List<String> warnings = new CopyOnWriteArrayList<>();
+ private Appender appender;
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext camelContext = super.createCamelContext();
+ // the component json of these test components is in
META-INF/org/apache/camel/reifier
+ camelContext.addComponent("evaluatedpath", new TestComponent());
+ camelContext.addComponent("fixedpath", new TestComponent());
+ camelContext.addComponent("nometadata", new TestComponent());
+ camelContext.getPropertiesComponent().addInitialProperty("target.uri",
"mock:placeholder-${header.id}");
+ return camelContext;
+ }
+
+ @BeforeEach
+ public void captureWarnings() {
+ // test classes run in parallel in one JVM: keep only the WARNs about
the routes of this test
+ appender = ConsumingAppender.newAppender(LOGGER, APPENDER, Level.WARN,
event -> {
+ String message = event.getMessage().getFormattedMessage();
+ if (event.getLevel().isMoreSpecificThan(Level.WARN) &&
message.contains("expression-in-uri-")) {
+ warnings.add(message);
+ }
+ });
+ // the routes the tests add are created at once in a started context
+ context.start();
+ }
+
+ @AfterEach
+ public void stopCapture() {
+ LoggerContext logging = (LoggerContext) LogManager.getContext(false);
+ logging.getConfiguration().removeLogger(LOGGER);
+ logging.updateLoggers();
+ appender.stop();
+ }
+
+ @Test
+ public void toWithExpressionInPathWarnsAndSendsToTheLiteralEndpoint()
throws Exception {
+ addRoute("expression-in-uri-mock", "direct:mock",
"mock:out-${header.id}");
+
+ assertThat(warnings).singleElement().asString()
+ .contains("expression-in-uri-mock", "mock:out-${header.id}",
"${header.id}", "toD");
+
+ template.sendBodyAndHeader("direct:mock", "hello", "id", "1");
+ template.sendBodyAndHeader("direct:mock", "hello", "id", "2");
+
+ // the WARN comes once, when the route is created, not for each message
+ assertThat(warnings).hasSize(1);
+ // the behaviour is unchanged: one endpoint, named by the text of the
expression, gets every message
+ assertThat(context.hasEndpoint("mock://out-1")).isNull();
+ assertThat(context.hasEndpoint("mock://out-2")).isNull();
+ Endpoint literal = context.hasEndpoint("mock://out-$%7Bheader.id%7D");
+ assertThat(literal).isInstanceOf(MockEndpoint.class);
+ assertThat(((MockEndpoint) literal).getReceivedCounter()).isEqualTo(2);
+ }
+
+ @Test
+ public void toWithExpressionFromPropertyPlaceholderWarns() throws
Exception {
+ addRoute("expression-in-uri-placeholder", "direct:placeholder",
"{{target.uri}}");
+
+ assertThat(warnings).singleElement().asString()
+ .contains("expression-in-uri-placeholder", "${header.id}",
"toD");
+ }
+
+ @Test
+ public void toWithExpressionInPathOfComponentWithoutPathMetadataWarns()
throws Exception {
+ addRoute("expression-in-uri-fixed", "direct:fixed",
"fixedpath:orders-${header.region}");
+
+ assertThat(warnings).singleElement().asString()
+ .contains("expression-in-uri-fixed", "${header.region}",
"toD");
+ }
+
+ @Test
+ public void toDDoesNotWarnAndSendsToThePerMessageEndpoint() throws
Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("direct:dynamic").routeId("expression-in-uri-tod").toD("mock:out-${header.id}");
+ }
+ });
+ template.sendBodyAndHeader("direct:dynamic", "hello", "id", "2");
+
+ assertThat(warnings).isEmpty();
+ Endpoint out = context.hasEndpoint("mock://out-2");
+ assertThat(out).isInstanceOf(MockEndpoint.class);
+ assertThat(((MockEndpoint) out).getReceivedCounter()).isEqualTo(1);
+ }
+
+ @Test
+ public void expressionOnlyInTheOptionsDoesNotWarn() throws Exception {
+ addRoute("expression-in-uri-option", "direct:option",
"log:orders?marker=${header.marker}");
+
+ assertThat(warnings).isEmpty();
+ }
+
+ @Test
+ public void languageComponentDoesNotWarn() throws Exception {
+ // the path of the language component is a script, not an address
+ addRoute("expression-in-uri-language", "direct:language",
"language:simple:Hello ${body}");
+
+ assertThat(warnings).isEmpty();
+ assertThat(template.requestBody("direct:language", "World",
String.class)).isEqualTo("Hello World");
+ }
+
+ @Test
+ public void componentThatEvaluatesItsPathDoesNotWarn() throws Exception {
+ // its component json says the path supports a Simple expression
(supportSimpleExpression)
+ addRoute("expression-in-uri-evaluated", "direct:evaluated",
"evaluatedpath:orders.${header.region}");
+
+ assertThat(warnings).isEmpty();
+ }
+
+ @Test
+ public void componentWithoutMetadataDoesNotWarn() throws Exception {
+ // nothing says what the component does with its path: say nothing
rather than the wrong thing
+ addRoute("expression-in-uri-unknown", "direct:unknown",
"nometadata:orders-${header.region}");
+
+ assertThat(warnings).isEmpty();
+ }
+
+ @Test
+ public void parameterBoundPerMessageDoesNotWarn() throws Exception {
+ // :#${...} and :#in:${...} are parameters the sql components bind for
each message
+ addRoute("expression-in-uri-bound", "direct:bound", "fixedpath:select
* from orders where id = :#${body}");
+ addRoute("expression-in-uri-bound-in", "direct:boundIn",
+ "fixedpath:select * from orders where id in (:#in:${body})");
+
+ assertThat(warnings).isEmpty();
+ }
+
+ private void addRoute(String routeId, String from, String to) throws
Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ from(from).routeId(routeId).to(to);
+ }
+ });
+ }
+
+ /**
+ * A mock component of its own package, where the test component json is.
+ */
+ private static final class TestComponent extends MockComponent {
+ }
+}
diff --git
a/core/camel-core/src/test/resources/META-INF/org/apache/camel/reifier/evaluatedpath.json
b/core/camel-core/src/test/resources/META-INF/org/apache/camel/reifier/evaluatedpath.json
new file mode 100644
index 000000000000..fe7c289e0d15
--- /dev/null
+++
b/core/camel-core/src/test/resources/META-INF/org/apache/camel/reifier/evaluatedpath.json
@@ -0,0 +1,14 @@
+{
+ "component": {
+ "kind": "component",
+ "name": "evaluatedpath",
+ "title": "Evaluated Path",
+ "description": "A test component that evaluates its path for each message",
+ "scheme": "evaluatedpath",
+ "syntax": "evaluatedpath:name",
+ "producerOnly": true
+ },
+ "properties": {
+ "name": { "index": 0, "kind": "path", "displayName": "Name", "group":
"producer", "label": "", "required": true, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"supportSimpleExpression": true, "description": "A name that is evaluated for
each message" }
+ }
+}
diff --git
a/core/camel-core/src/test/resources/META-INF/org/apache/camel/reifier/fixedpath.json
b/core/camel-core/src/test/resources/META-INF/org/apache/camel/reifier/fixedpath.json
new file mode 100644
index 000000000000..addad916d0df
--- /dev/null
+++
b/core/camel-core/src/test/resources/META-INF/org/apache/camel/reifier/fixedpath.json
@@ -0,0 +1,14 @@
+{
+ "component": {
+ "kind": "component",
+ "name": "fixedpath",
+ "title": "Fixed Path",
+ "description": "A test component whose path is fixed when the endpoint is
created",
+ "scheme": "fixedpath",
+ "syntax": "fixedpath:name",
+ "producerOnly": true
+ },
+ "properties": {
+ "name": { "index": 0, "kind": "path", "displayName": "Name", "group":
"producer", "label": "", "required": true, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "A name that is fixed when the endpoint is created" }
+ }
+}
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index a4961994fdc2..b449b993d228 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -118,6 +118,15 @@ messages, and grew with each one. An exception from a
predicate of `onException`
Split is no longer added to it either, and is logged instead. Use
`throwException(MyException.class, "...")`, or
`exceptionType` and `message`, to get a new exception for each message, with
the previous exception as suppressed.
+=== camel-core - a to with an expression in its endpoint uri logs a WARN
+
+A `to` resolves its endpoint once, when the route starts, so
`to("jms:queue:${header.queue}")` sends every message to
+one queue named by the text of the expression. Camel now logs a WARN for such
a `to` when it creates the route, and
+the WARN says to use `toD`. The route works as before. Only the endpoint path
is checked, not the options after the
+`?`. The components that evaluate their path for each message are left alone:
`language`, the `:#${...}` parameters
+of `sql`, and the components whose path option is marked
`supportSimpleExpression` in their metadata, which now
+includes the template of `sql-stored` and the bucket name of `aws2-s3`.
+
=== camel-core-model - doTry keeps doCatch and doFinally in its outputs
`doCatch` and `doFinally` written as properties of `doTry` in the YAML DSL are
now kept in the outputs of the