This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.18.x by this push:
new 898f73c0d4fe [backport camel-4.18.x] CAMEL-28111: camel-core - a
dynamic uri keeps the uri text of the options that the endpoint evaluates for
each message (#31374)
898f73c0d4fe is described below
commit 898f73c0d4fe065cf45903c997d4f64100cdfadc
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Dec 5 21:36:39 2026 +0100
[backport camel-4.18.x] CAMEL-28111: camel-core - a dynamic uri keeps the
uri text of the options that the endpoint evaluates for each message (#31374)
With toD, enrich, pollEnrich and a dynamic wireTap, the options that a
component evaluates as an expression for each message (such as the meter
name and tags of camel-micrometer, the keyName of camel-aws2-s3 or the
move option of the file components) now keep the text of the uri as
written in the route, so the component evaluates it once against the
message, as with a static to. Such an option that is only in the computed
uri is rejected.
Adapted for camel-4.18.x, which has no supportSimpleExpression metadata
and no EndpointUriFactory.expressionPropertyNames(): the uri template
logic is in camel-support (DynamicUriTemplate), and is used by a
SendDynamicAware / PollDynamicAware per component (micrometer,
opentelemetry-metrics, aws2-s3, jpa, sql-stored, google-storage,
mina-sftp, and the generic file aware classes), so it applies when
allowOptimisedComponents is enabled (the default).
(cherry picked from commit cc5c41ebcf870df80bba7597dac1601a923215e9)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../services/org/apache/camel/send-dynamic/aws2-s3 | 2 +
.../camel/component/aws2/s3/AWS2S3Endpoint.java | 5 +
.../component/aws2/s3/AWS2S3SendDynamicAware.java | 42 +++
.../aws2/s3/AWS2S3ToDynamicKeyNameTest.java | 95 ++++++
.../file/GenericFilePollDynamicAware.java | 35 ++-
.../file/GenericFileSendDynamicAware.java | 19 +-
.../org/apache/camel/poll-dynamic/google-storage | 2 +
.../GoogleCloudStoragePollDynamicAware.java | 37 +++
.../services/org/apache/camel/send-dynamic/jpa | 2 +
.../camel/component/jpa/JpaSendDynamicAware.java | 36 +++
.../org/apache/camel/send-dynamic/micrometer | 2 +
.../micrometer/MicrometerSendDynamicAware.java | 43 +++
.../micrometer/MicrometerToDynamicTagTest.java | 110 +++++++
.../org/apache/camel/poll-dynamic/mina-sftp | 2 +
.../org/apache/camel/send-dynamic/mina-sftp | 2 +
.../file/remote/mina/MinaSftpPollDynamicAware.java | 24 ++
.../file/remote/mina/MinaSftpSendDynamicAware.java | 24 ++
.../camel/send-dynamic/opentelemetry-metrics | 2 +
.../metrics/OpenTelemetrySendDynamicAware.java | 43 +++
.../org/apache/camel/send-dynamic/sql-stored | 2 +
.../sql/stored/SqlStoredSendDynamicAware.java | 42 +++
.../file/PollEnrichFileExpressionOptionTest.java | 86 ++++++
.../processor/ToDynamicExpressionOptionTest.java | 279 ++++++++++++++++++
.../services/org/apache/camel/send-dynamic/greet | 19 ++
.../support/component/DynamicUriTemplate.java | 327 +++++++++++++++++++++
.../ExpressionOptionsPollDynamicAware.java | 86 ++++++
.../ExpressionOptionsSendDynamicAware.java | 106 +++++++
27 files changed, 1465 insertions(+), 9 deletions(-)
diff --git
a/components/camel-aws/camel-aws2-s3/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/aws2-s3
b/components/camel-aws/camel-aws2-s3/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/aws2-s3
new file mode 100644
index 000000000000..ce1775f935dc
--- /dev/null
+++
b/components/camel-aws/camel-aws2-s3/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/aws2-s3
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.aws2.s3.AWS2S3SendDynamicAware
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 b095089e225d..82d19b279d8c 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
@@ -31,6 +31,7 @@ import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriPath;
+import org.apache.camel.support.LanguageSupport;
import org.apache.camel.support.ScheduledPollEndpoint;
import
org.apache.camel.support.processor.idempotent.MemoryIdempotentRepository;
import org.apache.camel.support.service.ServiceHelper;
@@ -142,6 +143,10 @@ public class AWS2S3Endpoint extends ScheduledPollEndpoint
implements EndpointSer
}
String bucketName = getConfiguration().getBucketName();
+ if (LanguageSupport.hasSimpleFunction(bucketName)) {
+ LOG.trace("Bucket name [{}] is evaluated for each message, so
skipping bucket check...", bucketName);
+ return;
+ }
LOG.trace("Querying whether bucket [{}] already exists...",
bucketName);
try {
diff --git
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3SendDynamicAware.java
b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3SendDynamicAware.java
new file mode 100644
index 000000000000..6b544c0bae49
--- /dev/null
+++
b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3SendDynamicAware.java
@@ -0,0 +1,42 @@
+/*
+ * 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.component.aws2.s3;
+
+import java.util.Set;
+
+import org.apache.camel.spi.annotations.SendDynamic;
+import org.apache.camel.support.component.ExpressionOptionsSendDynamicAware;
+
+/**
+ * A dynamic aws2-s3 uri keeps the uri text of the bucket name and the key
name, which the producer evaluates for each
+ * message.
+ */
+@SendDynamic("aws2-s3")
+public class AWS2S3SendDynamicAware extends ExpressionOptionsSendDynamicAware {
+
+ private static final Set<String> EXPRESSION_OPTIONS =
Set.of("bucketNameOrArn", "keyName");
+
+ @Override
+ protected Set<String> expressionPropertyNames() {
+ return EXPRESSION_OPTIONS;
+ }
+
+ @Override
+ protected String expressionPathSyntax() {
+ return "://bucketNameOrArn";
+ }
+}
diff --git
a/components/camel-aws/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/AWS2S3ToDynamicKeyNameTest.java
b/components/camel-aws/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/AWS2S3ToDynamicKeyNameTest.java
new file mode 100644
index 000000000000..2cb9abf63db1
--- /dev/null
+++
b/components/camel-aws/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/AWS2S3ToDynamicKeyNameTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.component.aws2.s3;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+import software.amazon.awssdk.services.s3.S3Client;
+import software.amazon.awssdk.services.s3.model.DeleteObjectRequest;
+import software.amazon.awssdk.services.s3.model.DeleteObjectResponse;
+import software.amazon.awssdk.services.s3.model.GetBucketTaggingRequest;
+import software.amazon.awssdk.services.s3.model.GetBucketTaggingResponse;
+import software.amazon.awssdk.services.s3.model.HeadBucketRequest;
+import software.amazon.awssdk.services.s3.model.HeadBucketResponse;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * The key and the bucket of a dynamic uri (toD) are evaluated once, against
the message, as with a static uri.
+ */
+public class AWS2S3ToDynamicKeyNameTest extends CamelTestSupport {
+
+ private final S3Client s3Client = mock(S3Client.class);
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+
when(s3Client.deleteObject(any(DeleteObjectRequest.class))).thenReturn(DeleteObjectResponse.builder().build());
+ when(s3Client.getBucketTagging(any(GetBucketTaggingRequest.class)))
+ .thenReturn(GetBucketTaggingResponse.builder().build());
+
when(s3Client.headBucket(any(HeadBucketRequest.class))).thenReturn(HeadBucketResponse.builder().build());
+ context.getRegistry().bind("s3", s3Client);
+ return context;
+ }
+
+ @Test
+ public void testKeyNameFromHeader() {
+ template.sendBodyAndHeaders("direct:key", "Hello", Map.of("key",
"${header.other}.txt", "other", "report"));
+
+ ArgumentCaptor<DeleteObjectRequest> captor =
ArgumentCaptor.forClass(DeleteObjectRequest.class);
+ verify(s3Client).deleteObject(captor.capture());
+ assertEquals("mybucket", captor.getValue().bucket());
+ // the key is the text of the header
+ assertEquals("${header.other}.txt", captor.getValue().key());
+ }
+
+ @Test
+ public void testBucketFromHeader() {
+ template.sendBodyAndHeaders("direct:bucket", "Hello", Map.of("bucket",
"b-${header.other}", "other", "report"));
+
+ // the bucket is used by the producer with the text of the header
+ ArgumentCaptor<GetBucketTaggingRequest> captor =
ArgumentCaptor.forClass(GetBucketTaggingRequest.class);
+ verify(s3Client).getBucketTagging(captor.capture());
+ assertEquals("b-${header.other}", captor.getValue().bucket());
+ // and a bucket name that is evaluated for each message is not checked
when the endpoint starts
+ verify(s3Client, never()).headBucket(any(HeadBucketRequest.class));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:key")
+
.toD("aws2-s3://mybucket?amazonS3Client=#s3&operation=deleteObject&keyName=${header.key}");
+
+ from("direct:bucket")
+
.toD("aws2-s3://${header.bucket}?amazonS3Client=#s3&operation=getBucketTagging");
+ }
+ };
+ }
+}
diff --git
a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFilePollDynamicAware.java
b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFilePollDynamicAware.java
index 0e002f60df31..0dd2d94a56c9 100644
---
a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFilePollDynamicAware.java
+++
b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFilePollDynamicAware.java
@@ -16,16 +16,32 @@
*/
package org.apache.camel.component.file;
+import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.camel.Exchange;
-import org.apache.camel.support.component.PollDynamicAwareSupport;
+import org.apache.camel.support.component.ExpressionOptionsPollDynamicAware;
import org.apache.camel.util.URISupport;
-public abstract class GenericFilePollDynamicAware extends
PollDynamicAwareSupport {
+public abstract class GenericFilePollDynamicAware extends
ExpressionOptionsPollDynamicAware {
public static final String PROP_FILE_NAME = "fileName";
+ /**
+ * The options that the consumer evaluates as an expression, which keep
the text of the original uri
+ */
+ private static final List<String> EXPRESSION_OPTIONS = List.of(
+ PROP_FILE_NAME, "doneFileName", "idempotentKey", "move",
"moveFailed", "preMove", "filterFile",
+ "filterDirectory", "sortBy");
+
+ private static final Set<String> EXPRESSION_OPTION_NAMES =
Set.copyOf(EXPRESSION_OPTIONS);
+
+ @Override
+ protected Set<String> expressionPropertyNames() {
+ return EXPRESSION_OPTION_NAMES;
+ }
+
@Override
public boolean isLenientProperties() {
return false;
@@ -33,6 +49,8 @@ public abstract class GenericFilePollDynamicAware extends
PollDynamicAwareSuppor
@Override
public DynamicAwareEntry prepare(Exchange exchange, String uri, String
originalUri) throws Exception {
+ // the options that are evaluated as an expression keep the text of
the original uri
+ uri = restoreExpressionOptions(uri, originalUri);
Map<String, Object> properties = endpointProperties(exchange, uri);
return new DynamicAwareEntry(uri, originalUri, properties, null);
}
@@ -44,13 +62,16 @@ public abstract class GenericFilePollDynamicAware extends
PollDynamicAwareSuppor
// which should then be reversed
uri = uri.replace("\t", "\\\\t");
- boolean fileName = entry.getProperties().containsKey(PROP_FILE_NAME);
- // if any of the above are in use, then they should not be pre
evaluated
+ Map<String, Object> params = entry.getProperties();
+ // if any of the expression options are in use, then they should not
be pre evaluated
// and we need to rebuild a new uri with them as-is
- if (fileName) {
- Map<String, Object> params = entry.getProperties();
+ if (EXPRESSION_OPTIONS.stream().anyMatch(params::containsKey)) {
Map<String, Object> originalParams =
URISupport.parseQuery(URISupport.extractQuery(entry.getOriginalUri()));
- compute(originalParams, PROP_FILE_NAME, params);
+ for (String option : EXPRESSION_OPTIONS) {
+ if (params.containsKey(option)) {
+ compute(originalParams, option, params);
+ }
+ }
return asEndpointUri(exchange, uri, params);
} else {
return uri;
diff --git
a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileSendDynamicAware.java
b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileSendDynamicAware.java
index 7f086fb1bd4a..9d8159b57b30 100644
---
a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileSendDynamicAware.java
+++
b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileSendDynamicAware.java
@@ -17,13 +17,14 @@
package org.apache.camel.component.file;
import java.util.Map;
+import java.util.Set;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
-import org.apache.camel.support.component.SendDynamicAwareSupport;
+import org.apache.camel.support.component.ExpressionOptionsSendDynamicAware;
import org.apache.camel.util.URISupport;
-public abstract class GenericFileSendDynamicAware extends
SendDynamicAwareSupport {
+public abstract class GenericFileSendDynamicAware extends
ExpressionOptionsSendDynamicAware {
public static final String PROP_FILE_NAME = "fileName";
public static final String PROP_TEMP_FILE_NAME = "tempFileName";
@@ -33,6 +34,18 @@ public abstract class GenericFileSendDynamicAware extends
SendDynamicAwareSuppor
public static final String PROP_PRE_MOVE = "preMove";
public static final String PROP_MOVE_EXISTING = "moveExisting";
+ /**
+ * The options that the endpoint evaluates as an expression, which keep
the text of the original uri
+ */
+ private static final Set<String> EXPRESSION_OPTIONS = Set.of(
+ PROP_FILE_NAME, PROP_TEMP_FILE_NAME, "doneFileName",
PROP_IDEMPOTENT_KEY, PROP_MOVE, PROP_MOVE_FAILED,
+ PROP_PRE_MOVE, PROP_MOVE_EXISTING, "filterFile",
"filterDirectory", "sortBy");
+
+ @Override
+ protected Set<String> expressionPropertyNames() {
+ return EXPRESSION_OPTIONS;
+ }
+
@Override
public boolean isLenientProperties() {
return false;
@@ -40,6 +53,8 @@ public abstract class GenericFileSendDynamicAware extends
SendDynamicAwareSuppor
@Override
public DynamicAwareEntry prepare(Exchange exchange, String uri, String
originalUri) throws Exception {
+ // the options that are evaluated as an expression keep the text of
the original uri
+ uri = restoreExpressionOptions(uri, originalUri);
Map<String, Object> properties = endpointProperties(exchange, uri);
return new DynamicAwareEntry(uri, originalUri, properties, null);
}
diff --git
a/components/camel-google/camel-google-storage/src/generated/resources/META-INF/services/org/apache/camel/poll-dynamic/google-storage
b/components/camel-google/camel-google-storage/src/generated/resources/META-INF/services/org/apache/camel/poll-dynamic/google-storage
new file mode 100644
index 000000000000..bd7a1dd22538
--- /dev/null
+++
b/components/camel-google/camel-google-storage/src/generated/resources/META-INF/services/org/apache/camel/poll-dynamic/google-storage
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.google.storage.GoogleCloudStoragePollDynamicAware
diff --git
a/components/camel-google/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStoragePollDynamicAware.java
b/components/camel-google/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStoragePollDynamicAware.java
new file mode 100644
index 000000000000..4d1b58e173e4
--- /dev/null
+++
b/components/camel-google/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStoragePollDynamicAware.java
@@ -0,0 +1,37 @@
+/*
+ * 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.component.google.storage;
+
+import java.util.Set;
+
+import org.apache.camel.spi.annotations.PollDynamic;
+import org.apache.camel.support.component.ExpressionOptionsPollDynamicAware;
+
+/**
+ * pollEnrich with a dynamic google-storage uri keeps the uri text of the
download file name, which the consumer
+ * evaluates for each downloaded object.
+ */
+@PollDynamic("google-storage")
+public class GoogleCloudStoragePollDynamicAware extends
ExpressionOptionsPollDynamicAware {
+
+ private static final Set<String> EXPRESSION_OPTIONS =
Set.of("downloadFileName");
+
+ @Override
+ protected Set<String> expressionPropertyNames() {
+ return EXPRESSION_OPTIONS;
+ }
+}
diff --git
a/components/camel-jpa/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/jpa
b/components/camel-jpa/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/jpa
new file mode 100644
index 000000000000..7bdb71e964ee
--- /dev/null
+++
b/components/camel-jpa/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/jpa
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.jpa.JpaSendDynamicAware
diff --git
a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaSendDynamicAware.java
b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaSendDynamicAware.java
new file mode 100644
index 000000000000..07446e1f100e
--- /dev/null
+++
b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaSendDynamicAware.java
@@ -0,0 +1,36 @@
+/*
+ * 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.component.jpa;
+
+import java.util.Set;
+
+import org.apache.camel.spi.annotations.SendDynamic;
+import org.apache.camel.support.component.ExpressionOptionsSendDynamicAware;
+
+/**
+ * A dynamic jpa uri keeps the uri text of the query parameters, which the
producer evaluates for each message.
+ */
+@SendDynamic("jpa")
+public class JpaSendDynamicAware extends ExpressionOptionsSendDynamicAware {
+
+ private static final Set<String> EXPRESSION_OPTIONS =
Set.of("parameters.");
+
+ @Override
+ protected Set<String> expressionPropertyNames() {
+ return EXPRESSION_OPTIONS;
+ }
+}
diff --git
a/components/camel-micrometer/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/micrometer
b/components/camel-micrometer/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/micrometer
new file mode 100644
index 000000000000..91afa3247949
--- /dev/null
+++
b/components/camel-micrometer/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/micrometer
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.micrometer.MicrometerSendDynamicAware
diff --git
a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerSendDynamicAware.java
b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerSendDynamicAware.java
new file mode 100644
index 000000000000..70ea4b90fc84
--- /dev/null
+++
b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerSendDynamicAware.java
@@ -0,0 +1,43 @@
+/*
+ * 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.component.micrometer;
+
+import java.util.Set;
+
+import org.apache.camel.spi.annotations.SendDynamic;
+import org.apache.camel.support.component.ExpressionOptionsSendDynamicAware;
+
+/**
+ * A dynamic micrometer uri keeps the uri text of the meter name, description,
tags and values, which the producer
+ * evaluates for each message.
+ */
+@SendDynamic("micrometer")
+public class MicrometerSendDynamicAware extends
ExpressionOptionsSendDynamicAware {
+
+ private static final Set<String> EXPRESSION_OPTIONS
+ = Set.of("metricsName", "tags.", "action", "decrement",
"increment", "metricsDescription", "value");
+
+ @Override
+ protected Set<String> expressionPropertyNames() {
+ return EXPRESSION_OPTIONS;
+ }
+
+ @Override
+ protected String expressionPathSyntax() {
+ return ":metricsType:metricsName";
+ }
+}
diff --git
a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/MicrometerToDynamicTagTest.java
b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/MicrometerToDynamicTagTest.java
new file mode 100644
index 000000000000..c2bed6362bf1
--- /dev/null
+++
b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/MicrometerToDynamicTagTest.java
@@ -0,0 +1,110 @@
+/*
+ * 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.component.micrometer;
+
+import java.util.Map;
+
+import io.micrometer.core.instrument.Counter;
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static
org.apache.camel.component.micrometer.MicrometerConstants.METRICS_REGISTRY_NAME;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * The tags of a meter in a dynamic uri (toD) are evaluated once, against the
message, as with a static uri.
+ */
+public class MicrometerToDynamicTagTest extends CamelTestSupport {
+
+ private final MeterRegistry registry = new SimpleMeterRegistry();
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ context.getRegistry().bind(METRICS_REGISTRY_NAME, registry);
+ return context;
+ }
+
+ @Test
+ public void testTagValueFromHeader() {
+ template.sendBodyAndHeaders("direct:start", "Hello",
+ Map.of("region", "eu", "name", "orders"));
+ template.sendBodyAndHeaders("direct:start", "Hello",
+ Map.of("region", "${header.name}", "name", "orders"));
+
+ Counter eu = registry.find("orders").tag("region", "eu").counter();
+ assertNotNull(eu);
+ assertEquals(1.0d, eu.count(), 0.01d);
+
+ // the tag value is the text of the header
+ Counter text = registry.find("orders").tag("region",
"${header.name}").counter();
+ assertNotNull(text);
+ assertEquals(1.0d, text.count(), 0.01d);
+ }
+
+ @Test
+ public void testMeterNameFromHeader() {
+ template.sendBodyAndHeaders("direct:name", "Hello",
+ Map.of("meter", "${header.other}", "other", "payments"));
+
+ // the meter name is the text of the header
+ assertNotNull(registry.find("${header.other}").counter());
+ }
+
+ @Test
+ public void testMeterTypeFromHeader() {
+ // the meter type is computed from the message, and the meter name is
evaluated by the producer
+ template.sendBodyAndHeaders("direct:type", "Hello", Map.of("type",
"counter", "region", "eu"));
+ template.sendBodyAndHeaders("direct:type", "Hello", Map.of("type",
"summary", "region", "us", "amount", 42));
+
+ assertNotNull(registry.find("orders.eu").counter());
+ assertNotNull(registry.find("orders.us").summary());
+ assertEquals(42.0d,
registry.find("orders.us").summary().totalAmount(), 0.01d);
+ }
+
+ @Test
+ public void testTagNotInUri() {
+ Map<String, Object> headers = Map.of("name",
"orders&tags.region=${header.region}", "region", "eu");
+ CamelExecutionException e = assertThrows(CamelExecutionException.class,
+ () -> template.sendBodyAndHeaders("direct:description",
"Hello", headers));
+ assertInstanceOf(ResolveEndpointFailedException.class, e.getCause());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("direct:start").toD("micrometer:counter:orders?tags.region=${header.region}");
+
+ from("direct:name").toD("micrometer:counter:${header.meter}");
+
+
from("direct:type").toD("micrometer:${header.type}:orders.${header.region}?value=${header.amount}");
+
from("direct:description").toD("micrometer:counter:orders?metricsDescription=${header.name}");
+ }
+ };
+ }
+}
diff --git
a/components/camel-mina-sftp/src/generated/resources/META-INF/services/org/apache/camel/poll-dynamic/mina-sftp
b/components/camel-mina-sftp/src/generated/resources/META-INF/services/org/apache/camel/poll-dynamic/mina-sftp
new file mode 100644
index 000000000000..bce622c72e90
--- /dev/null
+++
b/components/camel-mina-sftp/src/generated/resources/META-INF/services/org/apache/camel/poll-dynamic/mina-sftp
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.file.remote.mina.MinaSftpPollDynamicAware
diff --git
a/components/camel-mina-sftp/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/mina-sftp
b/components/camel-mina-sftp/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/mina-sftp
new file mode 100644
index 000000000000..db28e6ab265d
--- /dev/null
+++
b/components/camel-mina-sftp/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/mina-sftp
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.file.remote.mina.MinaSftpSendDynamicAware
diff --git
a/components/camel-mina-sftp/src/main/java/org/apache/camel/component/file/remote/mina/MinaSftpPollDynamicAware.java
b/components/camel-mina-sftp/src/main/java/org/apache/camel/component/file/remote/mina/MinaSftpPollDynamicAware.java
new file mode 100644
index 000000000000..5533483491d1
--- /dev/null
+++
b/components/camel-mina-sftp/src/main/java/org/apache/camel/component/file/remote/mina/MinaSftpPollDynamicAware.java
@@ -0,0 +1,24 @@
+/*
+ * 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.component.file.remote.mina;
+
+import org.apache.camel.component.file.GenericFilePollDynamicAware;
+import org.apache.camel.spi.annotations.PollDynamic;
+
+@PollDynamic("mina-sftp")
+public class MinaSftpPollDynamicAware extends GenericFilePollDynamicAware {
+}
diff --git
a/components/camel-mina-sftp/src/main/java/org/apache/camel/component/file/remote/mina/MinaSftpSendDynamicAware.java
b/components/camel-mina-sftp/src/main/java/org/apache/camel/component/file/remote/mina/MinaSftpSendDynamicAware.java
new file mode 100644
index 000000000000..83bfeffd353a
--- /dev/null
+++
b/components/camel-mina-sftp/src/main/java/org/apache/camel/component/file/remote/mina/MinaSftpSendDynamicAware.java
@@ -0,0 +1,24 @@
+/*
+ * 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.component.file.remote.mina;
+
+import org.apache.camel.component.file.GenericFileSendDynamicAware;
+import org.apache.camel.spi.annotations.SendDynamic;
+
+@SendDynamic("mina-sftp")
+public class MinaSftpSendDynamicAware extends GenericFileSendDynamicAware {
+}
diff --git
a/components/camel-opentelemetry-metrics/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/opentelemetry-metrics
b/components/camel-opentelemetry-metrics/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/opentelemetry-metrics
new file mode 100644
index 000000000000..b7633fd5be30
--- /dev/null
+++
b/components/camel-opentelemetry-metrics/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/opentelemetry-metrics
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.opentelemetry.metrics.OpenTelemetrySendDynamicAware
diff --git
a/components/camel-opentelemetry-metrics/src/main/java/org/apache/camel/opentelemetry/metrics/OpenTelemetrySendDynamicAware.java
b/components/camel-opentelemetry-metrics/src/main/java/org/apache/camel/opentelemetry/metrics/OpenTelemetrySendDynamicAware.java
new file mode 100644
index 000000000000..086037590561
--- /dev/null
+++
b/components/camel-opentelemetry-metrics/src/main/java/org/apache/camel/opentelemetry/metrics/OpenTelemetrySendDynamicAware.java
@@ -0,0 +1,43 @@
+/*
+ * 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.opentelemetry.metrics;
+
+import java.util.Set;
+
+import org.apache.camel.spi.annotations.SendDynamic;
+import org.apache.camel.support.component.ExpressionOptionsSendDynamicAware;
+
+/**
+ * A dynamic opentelemetry-metrics uri keeps the uri text of the metric name,
description, attributes and values, which
+ * the producer evaluates for each message.
+ */
+@SendDynamic("opentelemetry-metrics")
+public class OpenTelemetrySendDynamicAware extends
ExpressionOptionsSendDynamicAware {
+
+ private static final Set<String> EXPRESSION_OPTIONS
+ = Set.of("metricName", "attributes.", "action", "decrement",
"increment", "metricsDescription", "value");
+
+ @Override
+ protected Set<String> expressionPropertyNames() {
+ return EXPRESSION_OPTIONS;
+ }
+
+ @Override
+ protected String expressionPathSyntax() {
+ return ":metricType:metricName";
+ }
+}
diff --git
a/components/camel-sql/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/sql-stored
b/components/camel-sql/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/sql-stored
new file mode 100644
index 000000000000..0b2ff228e6e2
--- /dev/null
+++
b/components/camel-sql/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/sql-stored
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.sql.stored.SqlStoredSendDynamicAware
diff --git
a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredSendDynamicAware.java
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredSendDynamicAware.java
new file mode 100644
index 000000000000..221efea60956
--- /dev/null
+++
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/SqlStoredSendDynamicAware.java
@@ -0,0 +1,42 @@
+/*
+ * 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.component.sql.stored;
+
+import java.util.Set;
+
+import org.apache.camel.spi.annotations.SendDynamic;
+import org.apache.camel.support.component.ExpressionOptionsSendDynamicAware;
+
+/**
+ * A dynamic sql-stored uri keeps the uri text of the template, whose
parameters the producer evaluates for each
+ * message.
+ */
+@SendDynamic("sql-stored")
+public class SqlStoredSendDynamicAware extends
ExpressionOptionsSendDynamicAware {
+
+ private static final Set<String> EXPRESSION_OPTIONS = Set.of("template");
+
+ @Override
+ protected Set<String> expressionPropertyNames() {
+ return EXPRESSION_OPTIONS;
+ }
+
+ @Override
+ protected String expressionPathSyntax() {
+ return ":template";
+ }
+}
diff --git
a/core/camel-core/src/test/java/org/apache/camel/component/file/PollEnrichFileExpressionOptionTest.java
b/core/camel-core/src/test/java/org/apache/camel/component/file/PollEnrichFileExpressionOptionTest.java
new file mode 100644
index 000000000000..23429dca4cae
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/component/file/PollEnrichFileExpressionOptionTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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.component.file;
+
+import java.util.Map;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * pollEnrich with a dynamic file uri keeps the uri text of the options that
the file consumer evaluates.
+ */
+public class PollEnrichFileExpressionOptionTest extends ContextTestSupport {
+
+ @Test
+ public void testFilterWithHeaderValue() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+
+ template.sendBodyAndHeader(fileUri(), "Hello World",
Exchange.FILE_NAME, "hello.txt");
+
+ template.sendBodyAndHeader("direct:start", "Trigger", "wanted",
"hello.txt");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testFilterHeaderTextIsUsedAsGiven() throws Exception {
+ // the header is compared as text with the file name, so no file
matches
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+ getMockEndpoint("mock:result").message(0).body().isNull();
+
+ template.sendBodyAndHeader(fileUri(), "Hello World",
Exchange.FILE_NAME, "hello.txt");
+
+ template.sendBodyAndHeaders("direct:start", "Trigger",
Map.of("wanted", "${header.other}", "other", "hello.txt"));
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testOptionNotInUriIsRejected() {
+ template.sendBodyAndHeader(fileUri(), "Hello World",
Exchange.FILE_NAME, "hello.txt");
+
+ Map<String, Object> headers = Map.of("name",
"hello.txt&move=${header.other}", "other", "done");
+ CamelExecutionException e = assertThrows(CamelExecutionException.class,
+ () -> template.sendBodyAndHeaders("direct:name", "Trigger",
headers));
+ assertInstanceOf(ResolveEndpointFailedException.class, e.getCause());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:start")
+ .pollEnrich().simple(fileUri() +
"?initialDelay=0&filterFile=${file:name} == ${header.wanted}")
+ .timeout(1000).end()
+ .to("mock:result");
+
+ from("direct:name")
+ .pollEnrich().simple(fileUri() +
"?initialDelay=0&fileName=${header.name}").timeout(1000).end()
+ .to("mock:result");
+ }
+ };
+ }
+
+}
diff --git
a/core/camel-core/src/test/java/org/apache/camel/processor/ToDynamicExpressionOptionTest.java
b/core/camel-core/src/test/java/org/apache/camel/processor/ToDynamicExpressionOptionTest.java
new file mode 100644
index 000000000000..0446180d5468
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/processor/ToDynamicExpressionOptionTest.java
@@ -0,0 +1,279 @@
+/*
+ * 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 java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.Consumer;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.support.DefaultComponent;
+import org.apache.camel.support.DefaultEndpoint;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.support.component.EndpointUriFactorySupport;
+import org.apache.camel.support.component.ExpressionOptionsSendDynamicAware;
+import org.apache.camel.util.PropertiesHelper;
+import org.apache.camel.util.StringHelper;
+import org.junit.jupiter.api.Test;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * A dynamic uri keeps the uri template text of the options that the endpoint
evaluates as an expression.
+ * <p>
+ * The greet component has a send dynamic aware, which is registered in
+ * META-INF/services/org/apache/camel/send-dynamic/greet.
+ */
+public class ToDynamicExpressionOptionTest extends ContextTestSupport {
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ context.addComponent("greet", new GreetComponent());
+ context.getRegistry().bind("greetFactory", new
GreetEndpointUriFactory());
+ return context;
+ }
+
+ @Test
+ public void testHeaderValueIsUsedAsGiven() throws Exception {
+ getMockEndpoint("mock:result").expectedHeaderReceived("greeting",
"Hello ${header.name}");
+ getMockEndpoint("mock:result").expectedHeaderReceived("tag",
"${header.name}");
+ getMockEndpoint("mock:result").expectedHeaderReceived("label",
"orders");
+
+ template.sendBodyAndHeaders("direct:start", "Hi",
+ Map.of("greeting", "Hello ${header.name}", "tag",
"${header.name}", "label", "orders", "name", "World"));
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testHeaderValueWithoutExpression() throws Exception {
+
getMockEndpoint("mock:result").expectedHeaderValuesReceivedInAnyOrder("greeting",
"Hello World", "Hello Camel");
+
getMockEndpoint("mock:result").expectedHeaderValuesReceivedInAnyOrder("tag",
"blue", "red");
+
getMockEndpoint("mock:result").allMessages().header("label").isEqualTo("orders");
+
+ template.sendBodyAndHeaders("direct:start", "Hi",
+ Map.of("greeting", "Hello World", "tag", "blue", "label",
"orders"));
+ template.sendBodyAndHeaders("direct:start", "Hi",
+ Map.of("greeting", "Hello Camel", "tag", "red", "label",
"orders"));
+
+ assertMockEndpointsSatisfied();
+
+ // the options that are evaluated by the endpoint keep the uri
template, so both messages use the same endpoint
+ long count = context.getEndpoints().stream().filter(e ->
e.getEndpointUri().startsWith("greet:")).count();
+ assertEquals(1, count);
+ }
+
+ @Test
+ public void testPathIsUsedAsGiven() throws Exception {
+ getMockEndpoint("mock:result").expectedHeaderReceived("kind", "loud");
+ getMockEndpoint("mock:result").expectedHeaderReceived("path",
"${header.other}");
+
+ template.sendBodyAndHeaders("direct:path", "Hi", Map.of("kind",
"loud", "path", "${header.other}", "other", "World"));
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testPathPropertyThatIsNotAnExpression() throws Exception {
+ // the kind is a path property that the endpoint does not evaluate, so
it is computed from the message as before,
+ // while the name keeps the text of the uri template and is evaluated
by the endpoint
+
getMockEndpoint("mock:result").expectedHeaderValuesReceivedInAnyOrder("kind",
"loud", "quiet");
+
getMockEndpoint("mock:result").allMessages().header("path").isEqualTo("hello-World");
+
+ template.sendBodyAndHeaders("direct:pathKind", "Hi", Map.of("kind",
"loud", "name", "World"));
+ template.sendBodyAndHeaders("direct:pathKind", "Hi", Map.of("kind",
"quiet", "name", "World"));
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testOptionNotInUriIsRejected() {
+ Map<String, Object> headers = Map.of("greeting", "Hi", "tag", "blue",
"label", "orders&tags.size=${header.name}",
+ "name", "World");
+ CamelExecutionException e = assertThrows(CamelExecutionException.class,
+ () -> template.sendBodyAndHeaders("direct:start", "Hi",
headers));
+ ResolveEndpointFailedException cause =
assertInstanceOf(ResolveEndpointFailedException.class, e.getCause());
+ assertTrue(cause.getMessage().contains("The option tags.size is
evaluated by the greet endpoint"), cause.getMessage());
+ }
+
+ @Test
+ public void testEnrich() throws Exception {
+ getMockEndpoint("mock:result").expectedHeaderReceived("greeting",
"Hello ${header.name}");
+
+ template.sendBodyAndHeaders("direct:enrich", "Hi", Map.of("greeting",
"Hello ${header.name}", "name", "World"));
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testWireTap() {
+ GreetComponent component = context.getComponent("greet",
GreetComponent.class);
+
+ template.sendBodyAndHeaders("direct:wireTap", "Hi", Map.of("greeting",
"Hello ${header.name}", "name", "World"));
+
+ await().atMost(20, TimeUnit.SECONDS).until(() ->
!component.greetings.isEmpty());
+ assertEquals("Hello ${header.name}", component.greetings.get(0));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:start")
+
.toD("greet:a:b?greeting=${header.greeting}&tags.color=${header.tag}&label=${header.label}")
+ .to("mock:result");
+
+
from("direct:path").toD("greet:${header.kind}:${header.path}").to("mock:result");
+
+
from("direct:pathKind").toD("greet:${header.kind}:hello-${header.name}").to("mock:result");
+
+
from("direct:enrich").enrich().simple("greet:a:b?greeting=${header.greeting}").end().to("mock:result");
+
+
from("direct:wireTap").wireTap("greet:a:b?greeting=${header.greeting}");
+ }
+ };
+ }
+
+ /**
+ * A component with the path kind:path that evaluates the path property,
its greeting option and its tags as Simple
+ * expressions for each message (and not the kind).
+ */
+ private static final class GreetComponent extends DefaultComponent {
+
+ private final List<String> greetings = new CopyOnWriteArrayList<>();
+
+ @Override
+ protected Endpoint createEndpoint(String uri, String remaining,
Map<String, Object> parameters) {
+ GreetEndpoint answer = new GreetEndpoint(uri, this);
+ answer.kind = StringHelper.before(remaining, ":", remaining);
+ answer.path = StringHelper.after(remaining, ":", "");
+ answer.greeting = (String) parameters.remove("greeting");
+ answer.label = (String) parameters.remove("label");
+ answer.tags = PropertiesHelper.extractProperties(parameters,
"tags.");
+ return answer;
+ }
+ }
+
+ private static final class GreetEndpoint extends DefaultEndpoint {
+
+ private String kind;
+ private String path;
+ private String greeting;
+ private String label;
+ private Map<String, Object> tags;
+
+ GreetEndpoint(String uri, GreetComponent component) {
+ super(uri, component);
+ }
+
+ @Override
+ public Producer createProducer() {
+ return new DefaultProducer(this) {
+ @Override
+ public void process(Exchange exchange) {
+ String text = evaluate(exchange, greeting);
+ ((GreetComponent) getComponent()).greetings.add(text);
+ exchange.getMessage().setHeader("greeting", text);
+ exchange.getMessage().setHeader("kind", kind);
+ exchange.getMessage().setHeader("path", evaluate(exchange,
path));
+ exchange.getMessage().setHeader("label", label);
+ Object tag = tags.get("color");
+ exchange.getMessage().setHeader("tag", evaluate(exchange,
tag != null ? tag.toString() : null));
+ }
+ };
+ }
+
+ @Override
+ public Consumer createConsumer(Processor processor) {
+ throw new UnsupportedOperationException("Producer only");
+ }
+
+ private static String evaluate(Exchange exchange, String text) {
+ if (text == null) {
+ return null;
+ }
+ return
exchange.getContext().resolveLanguage("simple").createExpression(text).evaluate(exchange,
String.class);
+ }
+ }
+
+ private static final class GreetEndpointUriFactory extends
EndpointUriFactorySupport {
+
+ @Override
+ public boolean isEnabled(String scheme) {
+ return "greet".equals(scheme);
+ }
+
+ @Override
+ public String buildUri(String scheme, Map<String, Object> properties,
boolean encode) {
+ // not in use for this test
+ return null;
+ }
+
+ @Override
+ public Set<String> propertyNames() {
+ return Set.of("kind", "path", "greeting", "label", "tags");
+ }
+
+ @Override
+ public Set<String> secretPropertyNames() {
+ return Set.of();
+ }
+
+ @Override
+ public Map<String, String> multiValuePrefixes() {
+ return Map.of("tags", "tags.");
+ }
+
+ @Override
+ public boolean isLenientProperties() {
+ return false;
+ }
+ }
+
+ /**
+ * The greet endpoint evaluates the path property, its greeting option and
its tags as an expression.
+ */
+ public static final class GreetSendDynamicAware extends
ExpressionOptionsSendDynamicAware {
+
+ @Override
+ protected Set<String> expressionPropertyNames() {
+ return Set.of("path", "greeting", "tags.");
+ }
+
+ @Override
+ protected String expressionPathSyntax() {
+ return ":kind:path";
+ }
+ }
+}
diff --git
a/core/camel-core/src/test/resources/META-INF/services/org/apache/camel/send-dynamic/greet
b/core/camel-core/src/test/resources/META-INF/services/org/apache/camel/send-dynamic/greet
new file mode 100644
index 000000000000..7b93885fdbda
--- /dev/null
+++
b/core/camel-core/src/test/resources/META-INF/services/org/apache/camel/send-dynamic/greet
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+
+
+class=org.apache.camel.processor.ToDynamicExpressionOptionTest$GreetSendDynamicAware
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/component/DynamicUriTemplate.java
b/core/camel-support/src/main/java/org/apache/camel/support/component/DynamicUriTemplate.java
new file mode 100644
index 000000000000..7d2f04ece51c
--- /dev/null
+++
b/core/camel-support/src/main/java/org/apache/camel/support/component/DynamicUriTemplate.java
@@ -0,0 +1,327 @@
+/*
+ * 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.support.component;
+
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.support.EndpointHelper;
+import org.apache.camel.support.ExchangeHelper;
+import org.apache.camel.util.URISupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The uri template of a dynamic endpoint (toD, enrich, pollEnrich and wireTap
with a dynamic uri), for an endpoint that
+ * evaluates some of its options as an expression for each message, such as a
file name or a meter name with
+ * <tt>${header.name}</tt> in it.
+ * <p>
+ * Such an option keeps the text that is written in the uri template, so the
endpoint evaluates the template once, as
+ * with a static uri, and a value taken from the message is used as it is.
Such an option that the uri template does not
+ * have (it is only in the computed uri) is rejected.
+ *
+ * @see ExpressionOptionsSendDynamicAware
+ * @see ExpressionOptionsPollDynamicAware
+ */
+public final class DynamicUriTemplate {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(DynamicUriTemplate.class);
+
+ private final String uri;
+ private final String scheme;
+ private final String path;
+ private final PathSyntax pathSyntax;
+ private final Map<String, Object> parameters;
+ private final Set<String> expressionNames;
+
+ private DynamicUriTemplate(String uri, String scheme, String path,
PathSyntax pathSyntax, Map<String, Object> parameters,
+ Set<String> expressionNames) {
+ this.uri = uri;
+ this.scheme = scheme;
+ this.path = path;
+ this.pathSyntax = pathSyntax;
+ this.parameters = parameters;
+ this.expressionNames = expressionNames;
+ }
+
+ /**
+ * Creates the uri template of the given dynamic uri.
+ *
+ * @param context the camel context
+ * @param uri the dynamic uri as written in the route
+ * @param expressionNames the names of the options that the endpoint
evaluates as an expression for each message; a
+ * multi-valued option by its prefix (such as
<tt>tags.</tt>), and the path properties as
+ * well
+ * @param pathSyntax the syntax of the path of the endpoint uri
(what follows the scheme), such as
+ * <tt>:metricsType:metricsName</tt>, when one of
the path properties is evaluated as an
+ * expression for each message by a producer, or
<tt>null</tt> to compute the path from the
+ * message as before (such as for a consumer with
pollEnrich)
+ * @return the template, or <tt>null</tt> if there is no
option that is evaluated as an expression,
+ * or the scheme of the uri is not known before it
is computed
+ */
+ public static DynamicUriTemplate create(CamelContext context, String uri,
Set<String> expressionNames, String pathSyntax) {
+ if (uri == null || uri.startsWith("language:")) {
+ return null;
+ }
+ try {
+ String text =
EndpointHelper.resolveEndpointUriPropertyPlaceholders(context, uri.trim());
+ String scheme = ExchangeHelper.resolveScheme(text);
+ if (scheme == null || scheme.isEmpty() || !isPlainScheme(scheme)) {
+ return null;
+ }
+ if (expressionNames == null || expressionNames.isEmpty()) {
+ return null;
+ }
+ int pos = indexOfQuery(text);
+ String path = null;
+ PathSyntax syntax = null;
+ if (pathSyntax != null) {
+ path = text.substring(scheme.length() + 1, pos != -1 ? pos :
text.length());
+ syntax = PathSyntax.parse(pathSyntax);
+ }
+ Map<String, Object> parameters = pos != -1
+ ? URISupport.parseQuery(text.substring(pos + 1), true,
true)
+ : Map.of();
+ return new DynamicUriTemplate(text, scheme, path, syntax,
parameters, Set.copyOf(expressionNames));
+ } catch (Exception e) {
+ LOG.debug("Cannot parse the dynamic uri: {} as an uri template due
to: {}. This exception is ignored.",
+ URISupport.sanitizeUri(uri), e.getMessage(), e);
+ return null;
+ }
+ }
+
+ /**
+ * Puts the text of the uri template back into the options that the
endpoint evaluates as an expression.
+ *
+ * @param computed the uri computed from the message
+ * @return the uri to use
+ * @throws ResolveEndpointFailedException if the computed uri has such an
option that the template does not have
+ */
+ public String apply(String computed) throws URISyntaxException {
+ if (computed.equals(uri) || !computed.startsWith(scheme + ":")) {
+ // the same as the template, or another endpoint than the template
+ return computed;
+ }
+ boolean changed = false;
+ int pos = computed.indexOf('?');
+ String computedPath = computed.substring(scheme.length() + 1, pos !=
-1 ? pos : computed.length());
+ if (path != null && !path.equals(computedPath)) {
+ computedPath = restorePath(computedPath);
+ changed = true;
+ }
+ Map<String, Object> computedParameters = pos != -1
+ ? URISupport.parseQuery(computed.substring(pos + 1), true,
true)
+ : Map.of();
+ for (Map.Entry<String, Object> entry : computedParameters.entrySet()) {
+ String key = entry.getKey();
+ if (isExpression(key)) {
+ Object value = parameters.get(key);
+ if (value == null) {
+ throw new ResolveEndpointFailedException(
+ computed, "The option " + key + " is evaluated by
the " + scheme
+ + " endpoint for each message, and must
be in the uri as written in the route");
+ }
+ if (!value.equals(entry.getValue())) {
+ entry.setValue(value);
+ changed = true;
+ }
+ }
+ }
+ if (!changed) {
+ return computed;
+ }
+ StringBuilder sb = new StringBuilder(computed.length());
+ sb.append(scheme).append(':').append(computedPath);
+ char separator = '?';
+ for (Map.Entry<String, Object> entry : computedParameters.entrySet()) {
+ // the values are raw (as in the uri), so they are appended as
they are
+ List<?> values = entry.getValue() instanceof List<?> list ? list :
List.of(entry.getValue());
+ for (Object value : values) {
+
sb.append(separator).append(entry.getKey()).append('=').append(value);
+ separator = '&';
+ }
+ }
+ return sb.toString();
+ }
+
+ /**
+ * The path to use: the path properties that the endpoint evaluates as an
expression keep the text of the uri
+ * template, and the other path properties (such as the meter type of
micrometer) are taken from the computed uri.
+ * If the paths cannot be split by the syntax of the endpoint, the path of
the uri template is used as a whole.
+ */
+ private String restorePath(String computedPath) {
+ if (pathSyntax == null) {
+ return path;
+ }
+ List<String> template = pathSyntax.split(path);
+ List<String> computed = pathSyntax.split(computedPath);
+ if (template == null || computed == null) {
+ return path;
+ }
+ List<String> segments = new ArrayList<>(computed.size());
+ for (int i = 0; i < computed.size(); i++) {
+ segments.add(expressionNames.contains(pathSyntax.names.get(i)) ?
template.get(i) : computed.get(i));
+ }
+ return pathSyntax.join(segments);
+ }
+
+ private boolean isExpression(String key) {
+ if (expressionNames.contains(key)) {
+ return true;
+ }
+ for (String name : expressionNames) {
+ // a multi-valued option, by its prefix
+ if (name.endsWith(".") && key.startsWith(name)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static boolean isPlainScheme(String scheme) {
+ for (int i = 0; i < scheme.length(); i++) {
+ char ch = scheme.charAt(i);
+ if (!Character.isLetterOrDigit(ch) && ch != '-' && ch != '+' && ch
!= '.' && ch != '_') {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * The index of the ? sign that starts the query of the uri template,
which is not inside an expression such as
+ * <tt>${header.name?.trim()}</tt>.
+ */
+ private static int indexOfQuery(String uri) {
+ int depth = 0;
+ for (int i = 0; i < uri.length(); i++) {
+ char ch = uri.charAt(i);
+ if (ch == '{') {
+ depth++;
+ } else if (ch == '}' && depth > 0) {
+ depth--;
+ } else if (ch == '?' && depth == 0) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * The syntax of the path of an endpoint uri, such as
<tt>:metricsType:metricsName</tt> or
+ * <tt>://bucketNameOrArn</tt>: the names of the path properties, and the
delimiters before and between them. The
+ * last path property takes the rest of the path.
+ */
+ static final class PathSyntax {
+
+ private final String prefix;
+ private final List<String> names;
+ private final List<String> delimiters;
+
+ private PathSyntax(String prefix, List<String> names, List<String>
delimiters) {
+ this.prefix = prefix;
+ this.names = names;
+ this.delimiters = delimiters;
+ }
+
+ static PathSyntax parse(String syntax) {
+ // the path of a uri starts after the colon of the scheme
+ String text = syntax.startsWith(":") ? syntax.substring(1) :
syntax;
+ List<String> names = new ArrayList<>();
+ List<String> delimiters = new ArrayList<>();
+ StringBuilder prefix = new StringBuilder();
+ StringBuilder name = new StringBuilder();
+ StringBuilder delimiter = new StringBuilder();
+ for (int i = 0; i < text.length(); i++) {
+ char ch = text.charAt(i);
+ if (Character.isLetterOrDigit(ch) || ch == '_') {
+ if (!delimiter.isEmpty()) {
+ delimiters.add(delimiter.toString());
+ delimiter.setLength(0);
+ }
+ name.append(ch);
+ } else if (names.isEmpty() && name.isEmpty()) {
+ prefix.append(ch);
+ } else {
+ if (!name.isEmpty()) {
+ names.add(name.toString());
+ name.setLength(0);
+ }
+ delimiter.append(ch);
+ }
+ }
+ if (!name.isEmpty()) {
+ names.add(name.toString());
+ }
+ return names.isEmpty() || delimiters.size() != names.size() - 1
+ ? null : new PathSyntax(prefix.toString(), names,
delimiters);
+ }
+
+ /**
+ * Splits a path into the values of its path properties, or returns
<tt>null</tt> if the path does not match the
+ * syntax. A delimiter inside an expression, such as the colon of
<tt>${date:now}</tt>, does not split.
+ */
+ List<String> split(String path) {
+ if (!path.startsWith(prefix)) {
+ return null;
+ }
+ List<String> answer = new ArrayList<>(names.size());
+ int pos = prefix.length();
+ for (String delimiter : delimiters) {
+ int end = indexOf(path, delimiter, pos);
+ if (end == -1) {
+ return null;
+ }
+ answer.add(path.substring(pos, end));
+ pos = end + delimiter.length();
+ }
+ answer.add(path.substring(pos));
+ return answer;
+ }
+
+ String join(List<String> segments) {
+ StringBuilder sb = new StringBuilder(prefix);
+ for (int i = 0; i < segments.size(); i++) {
+ if (i > 0) {
+ sb.append(delimiters.get(i - 1));
+ }
+ sb.append(segments.get(i));
+ }
+ return sb.toString();
+ }
+
+ private static int indexOf(String text, String delimiter, int from) {
+ int depth = 0;
+ for (int i = from; i < text.length(); i++) {
+ char ch = text.charAt(i);
+ if (ch == '{') {
+ depth++;
+ } else if (ch == '}' && depth > 0) {
+ depth--;
+ } else if (depth == 0 && text.startsWith(delimiter, i)) {
+ return i;
+ }
+ }
+ return -1;
+ }
+ }
+}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/component/ExpressionOptionsPollDynamicAware.java
b/core/camel-support/src/main/java/org/apache/camel/support/component/ExpressionOptionsPollDynamicAware.java
new file mode 100644
index 000000000000..fc3966ad785d
--- /dev/null
+++
b/core/camel-support/src/main/java/org/apache/camel/support/component/ExpressionOptionsPollDynamicAware.java
@@ -0,0 +1,86 @@
+/*
+ * 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.support.component;
+
+import java.util.Set;
+
+import org.apache.camel.Exchange;
+
+/**
+ * Support class for a {@link org.apache.camel.spi.PollDynamicAware} of an
endpoint that evaluates some of its consumer
+ * options as an expression, such as a file name with <tt>${file:name}</tt> in
it.
+ * <p>
+ * With pollEnrich with a dynamic uri, these options keep the text that is
written in the uri, so the consumer evaluates
+ * that text, as with a static uri. Such an option that is not written in the
uri, and only comes up in the computed
+ * uri, is rejected. See {@link DynamicUriTemplate}.
+ */
+public abstract class ExpressionOptionsPollDynamicAware extends
PollDynamicAwareSupport {
+
+ private volatile CachedTemplate cached;
+
+ /**
+ * The names of the options that the consumer evaluates as an expression;
a multi-valued option by its prefix.
+ */
+ protected abstract Set<String> expressionPropertyNames();
+
+ @Override
+ public boolean isLenientProperties() {
+ return false;
+ }
+
+ @Override
+ public DynamicAwareEntry prepare(Exchange exchange, String uri, String
originalUri) throws Exception {
+ return new DynamicAwareEntry(restoreExpressionOptions(uri,
originalUri), originalUri, null, null);
+ }
+
+ @Override
+ public String resolveStaticUri(Exchange exchange, DynamicAwareEntry entry)
throws Exception {
+ return entry.getUri();
+ }
+
+ /**
+ * Puts the text of the original uri back into the options that the
endpoint evaluates as an expression.
+ *
+ * @param uri the uri
computed from the message
+ * @param originalUri the dynamic uri
as written in the route
+ * @return the uri to use
+ * @throws org.apache.camel.ResolveEndpointFailedException if the computed
uri has such an option that the original
+ * uri does not
have
+ */
+ protected String restoreExpressionOptions(String uri, String originalUri)
throws Exception {
+ DynamicUriTemplate t = template(originalUri);
+ return t != null && uri != null ? t.apply(uri) : uri;
+ }
+
+ private DynamicUriTemplate template(String originalUri) {
+ if (originalUri == null) {
+ return null;
+ }
+ // the original uri is the same for each message of the same processor
+ CachedTemplate answer = cached;
+ if (answer == null || !originalUri.equals(answer.uri())) {
+ // the path of a consumer is computed from the message as before
+ answer = new CachedTemplate(
+ originalUri, DynamicUriTemplate.create(getCamelContext(),
originalUri, expressionPropertyNames(), null));
+ cached = answer;
+ }
+ return answer.template();
+ }
+
+ private record CachedTemplate(String uri, DynamicUriTemplate template) {
+ }
+}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/component/ExpressionOptionsSendDynamicAware.java
b/core/camel-support/src/main/java/org/apache/camel/support/component/ExpressionOptionsSendDynamicAware.java
new file mode 100644
index 000000000000..3e1490dc0198
--- /dev/null
+++
b/core/camel-support/src/main/java/org/apache/camel/support/component/ExpressionOptionsSendDynamicAware.java
@@ -0,0 +1,106 @@
+/*
+ * 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.support.component;
+
+import java.util.Set;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+
+/**
+ * Support class for a {@link org.apache.camel.spi.SendDynamicAware} of an
endpoint that evaluates some of its options
+ * as an expression for each message, such as a meter name with
<tt>${header.name}</tt> in it.
+ * <p>
+ * With a dynamic uri (toD, enrich and wireTap with a dynamic uri), these
options keep the text that is written in the
+ * uri, so the endpoint evaluates that text once for each message, as with a
static uri. Such an option that is not
+ * written in the uri, and only comes up in the computed uri, is rejected. See
{@link DynamicUriTemplate}.
+ */
+public abstract class ExpressionOptionsSendDynamicAware extends
SendDynamicAwareSupport {
+
+ private volatile CachedTemplate cached;
+
+ /**
+ * The names of the options that the endpoint evaluates as an expression
for each message; a multi-valued option by
+ * its prefix (such as <tt>tags.</tt>), and the path properties as well.
+ */
+ protected abstract Set<String> expressionPropertyNames();
+
+ /**
+ * The syntax of the path of the endpoint uri (what follows the scheme),
such as <tt>:metricsType:metricsName</tt>,
+ * when one of the path properties is evaluated as an expression for each
message, or <tt>null</tt> otherwise.
+ */
+ protected String expressionPathSyntax() {
+ return null;
+ }
+
+ @Override
+ public boolean isLenientProperties() {
+ return false;
+ }
+
+ @Override
+ public DynamicAwareEntry prepare(Exchange exchange, String uri, String
originalUri) throws Exception {
+ return new DynamicAwareEntry(restoreExpressionOptions(uri,
originalUri), originalUri, null, null);
+ }
+
+ @Override
+ public String resolveStaticUri(Exchange exchange, DynamicAwareEntry entry)
throws Exception {
+ return entry.getUri();
+ }
+
+ @Override
+ public Processor createPreProcessor(Exchange exchange, DynamicAwareEntry
entry) throws Exception {
+ return null;
+ }
+
+ @Override
+ public Processor createPostProcessor(Exchange exchange, DynamicAwareEntry
entry) throws Exception {
+ return null;
+ }
+
+ /**
+ * Puts the text of the original uri back into the options that the
endpoint evaluates as an expression.
+ *
+ * @param uri the uri
computed from the message
+ * @param originalUri the dynamic uri
as written in the route
+ * @return the uri to use
+ * @throws org.apache.camel.ResolveEndpointFailedException if the computed
uri has such an option that the original
+ * uri does not
have
+ */
+ protected String restoreExpressionOptions(String uri, String originalUri)
throws Exception {
+ DynamicUriTemplate t = template(originalUri);
+ return t != null && uri != null ? t.apply(uri) : uri;
+ }
+
+ private DynamicUriTemplate template(String originalUri) {
+ if (originalUri == null) {
+ return null;
+ }
+ // the original uri is the same for each message of the same processor
+ CachedTemplate answer = cached;
+ if (answer == null || !originalUri.equals(answer.uri())) {
+ answer = new CachedTemplate(
+ originalUri, DynamicUriTemplate.create(getCamelContext(),
originalUri, expressionPropertyNames(),
+ expressionPathSyntax()));
+ cached = answer;
+ }
+ return answer.template();
+ }
+
+ private record CachedTemplate(String uri, DynamicUriTemplate template) {
+ }
+}