This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 1876d9e3bb9b CAMEL-27160: pollEnrich takes the evaluated uri as
literal text also on the optimised PollDynamicAware path (#30396)
1876d9e3bb9b is described below
commit 1876d9e3bb9b50eb778c4024620f3ebada38b1b3
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Nov 19 12:51:30 2026 +0100
CAMEL-27160: pollEnrich takes the evaluated uri as literal text also on the
optimised PollDynamicAware path (#30396)
PollEnricher#resolveUri no longer resolves property placeholders in the uri
evaluated per message, as
SendDynamicProcessor#resolveUri already does. Placeholders written in the
pollEnrich expression are resolved when the
route is built. This applies to the components with a PollDynamicAware,
such as file and the ftp family.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../org/apache/camel/processor/PollEnricher.java | 10 +++----
.../DynamicEndpointMessagePlaceholderTest.java | 31 ++++++++++++++++++++++
2 files changed, 34 insertions(+), 7 deletions(-)
diff --git
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/PollEnricher.java
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/PollEnricher.java
index 4ccf9034e33b..90688bb0b004 100644
---
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/PollEnricher.java
+++
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/PollEnricher.java
@@ -595,13 +595,9 @@ public class PollEnricher extends BaseProcessorSupport
implements IdAware, Route
uri =
exchange.getContext().getTypeConverter().mandatoryConvertTo(String.class,
exchange, recipient);
}
- // in case path has property placeholders then try to let property
component resolve those
- try {
- uri =
EndpointHelper.resolveEndpointUriPropertyPlaceholders(exchange.getContext(),
uri);
- } catch (Exception e) {
- throw new ResolveEndpointFailedException(uri, e);
- }
-
+ // NOTE: property placeholders in the dynamic-uri expression are
resolved once when the route is built. The
+ // per-message evaluated recipient must not be re-resolved here:
message content that happens to contain {{...}}
+ // is taken as a literal endpoint uri, as in
SendDynamicProcessor#resolveUri
return uri;
}
diff --git
a/core/camel-core/src/test/java/org/apache/camel/processor/DynamicEndpointMessagePlaceholderTest.java
b/core/camel-core/src/test/java/org/apache/camel/processor/DynamicEndpointMessagePlaceholderTest.java
index 22723050fa9a..c06907f8e2a6 100644
---
a/core/camel-core/src/test/java/org/apache/camel/processor/DynamicEndpointMessagePlaceholderTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/processor/DynamicEndpointMessagePlaceholderTest.java
@@ -20,6 +20,7 @@ import java.util.Properties;
import org.apache.camel.CamelContext;
import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.Header;
import org.apache.camel.builder.AggregationStrategies;
@@ -128,6 +129,31 @@ class DynamicEndpointMessagePlaceholderTest extends
ContextTestSupport {
assertThat(seda.getQueue()).hasSize(1);
}
+ @Test
+ void pollEnrichOptimisedPlaceholderInHeaderNotResolved() throws Exception {
+ // the file component polls through its PollDynamicAware, which takes
the evaluated uri as it is
+ getMockEndpoint("mock:done").expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:peFile", "trigger", "dir",
"{{secretTarget}}");
+
+ assertMockEndpointsSatisfied();
+ assertThat(context.getEndpoints()).extracting(Endpoint::getEndpointUri)
+ .filteredOn(uri -> uri.startsWith("file:"))
+ .isNotEmpty()
+ .noneMatch(uri -> uri.contains("resolved"));
+ }
+
+ @Test
+ void pollEnrichOptimisedPlaceholderInRouteTextIsResolved() throws
Exception {
+ getMockEndpoint("mock:done").expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:peFileRoute", "trigger", "dir",
"probe");
+
+ assertMockEndpointsSatisfied();
+ assertThat(context.getEndpoints()).extracting(Endpoint::getEndpointUri)
+ .anyMatch(uri -> uri.startsWith("file:") &&
uri.contains("resolved"));
+ }
+
@Test
void placeholderInStaticTemplateIsResolved() throws Exception {
// control: a placeholder written in the route template itself is
still resolved at build time
@@ -159,6 +185,11 @@ class DynamicEndpointMessagePlaceholderTest extends
ContextTestSupport {
from("direct:dr").dynamicRouter(method(DynamicEndpointMessagePlaceholderTest.this,
"route"));
from("direct:pe").pollEnrich().simple("${header.target}").timeout(2000).end().to("mock:done");
from("direct:staticTemplate").toD("mock:{{secretTarget}}");
+ from("direct:peFile").pollEnrich().simple("file:" +
testDirectory() + "/${header.dir}?initialDelay=0")
+ .timeout(100).end().to("mock:done");
+ from("direct:peFileRoute")
+ .pollEnrich().simple("file:" + testDirectory() +
"/{{secretTarget}}/${header.dir}?initialDelay=0")
+ .timeout(100).end().to("mock:done");
}
};
}