This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.18.x by this push:
new 1f1addeb58a CAMEL-18782: camel-http - HTTP_PATH header not working
with toD
1f1addeb58a is described below
commit 1f1addeb58a8253e03fa475c14cff2c7bd2b39b2
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Dec 1 14:15:27 2022 +0100
CAMEL-18782: camel-http - HTTP_PATH header not working with toD
---
.../camel/http/base/HttpSendDynamicAware.java | 3 +
.../http/HttpSendDynamicAwarePathHeaderTest.java | 78 ++++++++++++++++++++++
2 files changed, 81 insertions(+)
diff --git
a/components/camel-http-base/src/main/java/org/apache/camel/http/base/HttpSendDynamicAware.java
b/components/camel-http-base/src/main/java/org/apache/camel/http/base/HttpSendDynamicAware.java
index 97efdc2934c..d3cc10de8eb 100644
---
a/components/camel-http-base/src/main/java/org/apache/camel/http/base/HttpSendDynamicAware.java
+++
b/components/camel-http-base/src/main/java/org/apache/camel/http/base/HttpSendDynamicAware.java
@@ -102,6 +102,9 @@ public class HttpSendDynamicAware extends
SendDynamicAwareSupport {
query = URISupport.createQueryString(new
LinkedHashMap<>(entry.getLenientProperties()));
}
+ if ((path == null || path.isEmpty()) &&
ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Exchange.HTTP_PATH))) {
+ path = (String) exchange.getIn().getHeader(Exchange.HTTP_PATH);
+ }
if (query == null &&
ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Exchange.HTTP_QUERY))) {
query = (String) exchange.getIn().getHeader(Exchange.HTTP_QUERY);
}
diff --git
a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpSendDynamicAwarePathHeaderTest.java
b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpSendDynamicAwarePathHeaderTest.java
new file mode 100644
index 00000000000..e4014478442
--- /dev/null
+++
b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpSendDynamicAwarePathHeaderTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.http;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.http.handler.DrinkValidationHandler;
+import org.apache.http.impl.bootstrap.HttpServer;
+import org.apache.http.impl.bootstrap.ServerBootstrap;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.camel.component.http.HttpMethods.GET;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class HttpSendDynamicAwarePathHeaderTest extends BaseHttpTest {
+
+ private HttpServer localServer;
+
+ @BeforeEach
+ @Override
+ public void setUp() throws Exception {
+ localServer =
ServerBootstrap.bootstrap().setHttpProcessor(getBasicHttpProcessor())
+
.setConnectionReuseStrategy(getConnectionReuseStrategy()).setResponseFactory(getHttpResponseFactory())
+
.setExpectationVerifier(getHttpExpectationVerifier()).setSslContext(getSSLContext())
+ .registerHandler("/mybar", new
DrinkValidationHandler(GET.name(), null, null, "drink")).create();
+ localServer.start();
+
+ super.setUp();
+ }
+
+ @AfterEach
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ if (localServer != null) {
+ localServer.stop();
+ }
+ }
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:moes")
+ .toD("http://localhost:" + localServer.getLocalPort()
+ +
"?throwExceptionOnFailure=false&drink=${header.drink}");
+ }
+ };
+ }
+
+ @Test
+ public void testEmptyPath() throws Exception {
+ String out = fluentTemplate.to("direct:moes")
+ .withHeader(Exchange.HTTP_PATH, "mybar")
+ .withHeader("drink", "beer").request(String.class);
+ assertEquals("Drinking beer", out);
+ }
+
+}