You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2023/02/07 13:25:16 UTC
[camel] branch camel-3.18.x updated: CAMEL-19018: Fix camel-vertx-http potential duplication of HTTP header values
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton 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 09a1c8748f1 CAMEL-19018: Fix camel-vertx-http potential duplication of HTTP header values
09a1c8748f1 is described below
commit 09a1c8748f10b5f5932538cc8850a7068a3d984e
Author: James Netherton <ja...@gmail.com>
AuthorDate: Tue Feb 7 10:37:35 2023 +0000
CAMEL-19018: Fix camel-vertx-http potential duplication of HTTP header values
---
.../vertx/http/DefaultVertxHttpBinding.java | 9 ++-
.../vertx/http/VertxHttpMultiRouteTest.java | 68 ++++++++++++++++++++++
.../http/VertxHttpThrowExceptionOnFailureTest.java | 2 +-
3 files changed, 75 insertions(+), 4 deletions(-)
diff --git a/components/camel-vertx/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/DefaultVertxHttpBinding.java b/components/camel-vertx/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/DefaultVertxHttpBinding.java
index fd78f3d2258..8a8bb1ffc06 100644
--- a/components/camel-vertx/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/DefaultVertxHttpBinding.java
+++ b/components/camel-vertx/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/DefaultVertxHttpBinding.java
@@ -37,6 +37,7 @@ import org.apache.camel.TypeConverter;
import org.apache.camel.http.base.HttpHelper;
import org.apache.camel.http.base.HttpOperationFailedException;
import org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.camel.support.DefaultMessage;
import org.apache.camel.support.ExchangeHelper;
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
@@ -126,7 +127,7 @@ public class DefaultVertxHttpBinding implements VertxHttpBinding {
// Ensure the Content-Type header is always added if the corresponding exchange header is present
String contentType = ExchangeHelper.getContentType(exchange);
if (ObjectHelper.isNotEmpty(contentType)) {
- headers.add(VertxHttpConstants.CONTENT_TYPE, contentType);
+ headers.set(VertxHttpConstants.CONTENT_TYPE, contentType);
}
// Transfer exchange headers to the HTTP request while applying the filter strategy
@@ -137,7 +138,7 @@ public class DefaultVertxHttpBinding implements VertxHttpBinding {
Object headerValue = entry.getValue();
if (!strategy.applyFilterToCamelHeaders(key, headerValue, exchange)) {
String str = tc.convertTo(String.class, headerValue);
- headers.add(key, str);
+ headers.set(key, str);
}
}
}
@@ -146,9 +147,11 @@ public class DefaultVertxHttpBinding implements VertxHttpBinding {
@Override
public void handleResponse(VertxHttpEndpoint endpoint, Exchange exchange, AsyncResult<HttpResponse<Buffer>> response)
throws Exception {
+ Message message = new DefaultMessage(exchange);
+ exchange.setMessage(message);
+
HttpResponse<Buffer> result = response.result();
if (response.succeeded()) {
- Message message = exchange.getMessage();
VertxHttpConfiguration configuration = endpoint.getConfiguration();
boolean ok = endpoint.isStatusCodeOk(result.statusCode());
if (!configuration.isThrowExceptionOnFailure() || configuration.isThrowExceptionOnFailure() && ok) {
diff --git a/components/camel-vertx/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpMultiRouteTest.java b/components/camel-vertx/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpMultiRouteTest.java
new file mode 100644
index 00000000000..6e262ab5aa8
--- /dev/null
+++ b/components/camel-vertx/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpMultiRouteTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.vertx.http;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Test;
+
+public class VertxHttpMultiRouteTest extends VertxHttpTestSupport {
+ @Test
+ void testHttpConsumerToHttpProducer() throws Exception {
+ String expectedBody = "Hello World";
+ MockEndpoint mockEndpoint = getMockEndpoint("mock:result");
+ mockEndpoint.expectedBodiesReceived(expectedBody);
+ mockEndpoint.expectedHeaderReceived(Exchange.CONTENT_LENGTH, expectedBody.length());
+ mockEndpoint.expectedHeaderReceived(Exchange.CONTENT_TYPE, "text/plain");
+ mockEndpoint.expectedMessagesMatches(exchange -> {
+ Object header = exchange.getMessage().getHeader("User-Agent");
+ return header instanceof String && ((String) header).startsWith("Vert.x-WebClient");
+ });
+
+ template.requestBodyAndHeader("vertx-http:http://localhost:" + port + "/greeting", "World", Exchange.CONTENT_TYPE,
+ "text/plain");
+
+ mockEndpoint.assertIsSatisfied();
+ }
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ restConfiguration().port(port);
+
+ rest()
+ .post("/greeting")
+ .to("direct:greet")
+
+ .post("/hello")
+ .to("direct:hello");
+
+ from("direct:greet")
+ .removeHeaders("CamelHttp*")
+ .toF("vertx-http:http://localhost:%d/hello?httpMethod=POST", port)
+ .to("mock:result");
+
+ from("direct:hello")
+ .setBody().simple("Hello ${body}");
+ }
+ };
+ }
+}
diff --git a/components/camel-vertx/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpThrowExceptionOnFailureTest.java b/components/camel-vertx/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpThrowExceptionOnFailureTest.java
index 6851c33d0a9..75e501b01fb 100644
--- a/components/camel-vertx/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpThrowExceptionOnFailureTest.java
+++ b/components/camel-vertx/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpThrowExceptionOnFailureTest.java
@@ -101,7 +101,7 @@ public class VertxHttpThrowExceptionOnFailureTest extends VertxHttpTestSupport {
HttpOperationFailedException exception = exchange.getException(HttpOperationFailedException.class);
assertEquals(500, exception.getStatusCode());
assertEquals("Internal Server Error", exception.getStatusText());
- assertEquals(getTestServerUrl() + "/redirect", exception.getUri());
+ assertEquals(getTestServerUrl(), exception.getUri());
}
@Test