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 7aec6a1a2b9b Revert "CAMEL-24986: a REST producer says which path
parameter has no value (#26831)"
7aec6a1a2b9b is described below
commit 7aec6a1a2b9b277362ffcbce2e9a41c430c3e84b
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Sep 24 10:57:40 2026 +0200
Revert "CAMEL-24986: a REST producer says which path parameter has no value
(#26831)"
This reverts commit 1f62876382f6.
It broke RestProducerPathTest.testMissingHeader in camel-core: leaving an
unresolved placeholder in the uri when another one resolved is deliberate
("Backward compatibility: if one of the params is resolved", in both the
test and RestProducer), and testNoHeaders documents that nothing resolved
is not an error either. I ran camel-rest and camel-rest-openapi and not
camel-core, where that test lives.
CAMEL-24986 stays open. The problem it addresses is real - a request goes
out with {sku} in the path and the 404 says nothing - but the fix has to
keep both behaviours, so a warning rather than a failure.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Bp3538HRBPMQkb5ta9xRaj
---
.../apache/camel/component/rest/RestProducer.java | 34 ----------------------
.../component/rest/RestProducerAdvancedTest.java | 13 ++++-----
2 files changed, 6 insertions(+), 41 deletions(-)
diff --git
a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestProducer.java
b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestProducer.java
index 9eb40e0e4294..8b8abd47c963 100644
---
a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestProducer.java
+++
b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestProducer.java
@@ -29,7 +29,6 @@ import org.apache.camel.AsyncCallback;
import org.apache.camel.AsyncProcessor;
import org.apache.camel.AsyncProducer;
import org.apache.camel.CamelContext;
-import org.apache.camel.CamelExchangeException;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.Producer;
@@ -168,17 +167,6 @@ public class RestProducer extends DefaultAsyncProducer {
}
}
resolvedUriTemplate = uriTemplateBuilder.toString();
-
- // a placeholder with no value would be sent as it is, and the
service answers 404 for a path that
- // holds a {name}: say which parameter it is instead
(CAMEL-24986)
- String unresolved = firstPlaceholder(resolvedUriTemplate);
- if (unresolved != null) {
- throw new CamelExchangeException(
- "The path parameter {" + unresolved + "} of " +
resolvedUriTemplate + " has no value:"
- + " set the header " +
unresolved + ", or an exchange variable of"
- + " that name, before the
call.",
- exchange);
- }
}
}
@@ -233,28 +221,6 @@ public class RestProducer extends DefaultAsyncProducer {
}
}
- /**
- * The name of the first {@code {name}} left in the template, or null when
every one of them was resolved
- * (CAMEL-24986).
- */
- private static String firstPlaceholder(String uriTemplate) {
- int start = uriTemplate.indexOf('{');
- while (start >= 0) {
- int end = uriTemplate.indexOf('}', start);
- if (end < 0) {
- return null;
- }
- String name = uriTemplate.substring(start + 1, end);
- // a name, not something else that happens to be in braces
- if (!name.isEmpty() && name.chars().allMatch(c ->
Character.isLetterOrDigit(c) || c == '_' || c == '-'
- || c == '.')) {
- return name;
- }
- start = uriTemplate.indexOf('{', end);
- }
- return null;
- }
-
/**
* Replaces placeholders "{}" with message header or exchange variable
values.
*
diff --git
a/components/camel-rest/src/test/java/org/apache/camel/component/rest/RestProducerAdvancedTest.java
b/components/camel-rest/src/test/java/org/apache/camel/component/rest/RestProducerAdvancedTest.java
index d288a2902cae..9680e1d5d00e 100644
---
a/components/camel-rest/src/test/java/org/apache/camel/component/rest/RestProducerAdvancedTest.java
+++
b/components/camel-rest/src/test/java/org/apache/camel/component/rest/RestProducerAdvancedTest.java
@@ -19,7 +19,6 @@ package org.apache.camel.component.rest;
import java.util.HashMap;
import org.apache.camel.CamelContext;
-import org.apache.camel.CamelExchangeException;
import org.apache.camel.Exchange;
import org.apache.camel.Producer;
import org.apache.camel.impl.DefaultCamelContext;
@@ -33,7 +32,6 @@ import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.assertThrows;
@ExtendWith(MockitoExtension.class)
class RestProducerAdvancedTest {
@@ -86,11 +84,12 @@ class RestProducerAdvancedTest {
RestProducer producer = new RestProducer(endpoint, mockProducer,
config);
Exchange exchange = new DefaultExchange(camelContext);
- // no header, so the placeholder has no value: the request would go
out with {userId} in the path and the
- // service would answer 404 for it, so it fails here instead and says
which parameter it is (CAMEL-24986)
- CamelExchangeException e = assertThrows(CamelExchangeException.class,
() -> producer.prepareExchange(exchange));
- assertThat(e.getMessage()).contains("The path parameter
{userId}").contains("set the header userId");
-
assertThat(exchange.getMessage().getHeader(RestConstants.REST_HTTP_URI,
String.class)).isNull();
+ // Don't set the header, so placeholder won't be resolved
+ producer.prepareExchange(exchange);
+
+ // When placeholder is not resolved, REST_HTTP_URI should not be set
+ String uri =
exchange.getMessage().getHeader(RestConstants.REST_HTTP_URI, String.class);
+ assertThat(uri).isNull();
}
@Test