You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/02/14 15:17:59 UTC
[camel] branch master updated (9d252d8 -> 32d7810)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.
from 9d252d8 CAMEL-16205: camel-http - Optimize extract response body for small payloads
new 66074e2 camel-vertx-http - Optimize a bit
new a42ba33 CAMEL-16199: camel-http - Optimize headers added as request headers in producer
new 32d7810 camel-vertx-http - Optimize a bit
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../apache/camel/component/http/HttpProducer.java | 102 +++++++++++----------
.../vertx/http/DefaultVertxHttpBinding.java | 27 ++++--
.../vertx/http/VertxHttpProducerLoadTest.java} | 44 ++-------
3 files changed, 82 insertions(+), 91 deletions(-)
copy components/{camel-http/src/test/java/org/apache/camel/component/http/HttpProducerLoadTest.java => camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpProducerLoadTest.java} (70%)
[camel] 03/03: camel-vertx-http - Optimize a bit
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 32d781062785bd377576b549473e15376752b7bf
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Feb 14 16:17:21 2021 +0100
camel-vertx-http - Optimize a bit
---
.../vertx/http/VertxHttpProducerLoadTest.java | 97 ++++++++++++++++++++++
1 file changed, 97 insertions(+)
diff --git a/components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpProducerLoadTest.java b/components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpProducerLoadTest.java
new file mode 100644
index 0000000..670e076
--- /dev/null
+++ b/components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpProducerLoadTest.java
@@ -0,0 +1,97 @@
+/*
+ * 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.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.util.StopWatch;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Disabled("Manual test")
+public class VertxHttpProducerLoadTest extends VertxHttpTestSupport {
+
+ private static final Logger LOG = LoggerFactory.getLogger(VertxHttpProducerLoadTest.class);
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:echo")
+ .to(getProducerUri());
+
+ from(getTestServerUri())
+ .setBody(constant("Hello World"));
+
+ }
+ };
+ }
+
+ @Test
+ public void testProducerLoad() throws Exception {
+ StopWatch watch = new StopWatch();
+ for (int i = 0; i < 10000000; i++) {
+ fluentTemplate.to("direct:echo")
+ .withHeader("a", "aaa")
+ .withHeader("b", "bbb")
+ .withHeader("c", "ccc")
+ .withHeader("d", "ddd")
+ .withHeader("e", "eee")
+ .withHeader("f", "fff")
+ .withHeader("g", "ggg")
+ .withHeader("h", "hhh")
+ .withHeader("i", "iii")
+ .withHeader("j", "jjj")
+ .withHeader("a2", "aaa")
+ .withHeader("b2", "bbb")
+ .withHeader("c2", "ccc")
+ .withHeader("d2", "ddd")
+ .withHeader("e2", "eee")
+ .withHeader("f2", "fff")
+ .withHeader("g2", "ggg")
+ .withHeader("h2", "hhh")
+ .withHeader("i2", "iii")
+ .withHeader("j2", "jjj")
+ .withHeader("a3", "aaa")
+ .withHeader("b3", "bbb")
+ .withHeader("c3", "ccc")
+ .withHeader("d3", "ddd")
+ .withHeader("e3", "eee")
+ .withHeader("f3", "fff")
+ .withHeader("g3", "ggg")
+ .withHeader("h3", "hhh")
+ .withHeader("i3", "iii")
+ .withHeader("j3", "jjj")
+ .withHeader("a4", "aaa")
+ .withHeader("b4", "bbb")
+ .withHeader("c4", "ccc")
+ .withHeader("d4", "ddd")
+ .withHeader("e4", "eee")
+ .withHeader("f4", "fff")
+ .withHeader("g4", "ggg")
+ .withHeader("h4", "hhh")
+ .withHeader("i4", "iii")
+ .withHeader("j4", "jjj")
+ .withHeader("myHeader", "msg" + i).send();
+ }
+ LOG.info("Took {} ms", watch.taken());
+ }
+
+}
[camel] 02/03: CAMEL-16199: camel-http - Optimize headers added as
request headers in producer
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit a42ba335d0f041c54eb3a0889503f79260a5b47a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Feb 14 15:38:09 2021 +0100
CAMEL-16199: camel-http - Optimize headers added as request headers in producer
---
.../apache/camel/component/http/HttpProducer.java | 102 +++++++++++----------
1 file changed, 56 insertions(+), 46 deletions(-)
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
index df4ba01..660fcb0 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
@@ -130,61 +130,71 @@ public class HttpProducer extends DefaultProducer {
}
// propagate headers as HTTP headers
- final TypeConverter tc = exchange.getContext().getTypeConverter();
- for (Map.Entry<String, Object> entry : in.getHeaders().entrySet()) {
- String key = entry.getKey();
- Object headerValue = entry.getValue();
-
- if (headerValue != null) {
-
- if (headerValue instanceof String) {
- // optimise for string values
- String value = (String) headerValue;
- if (strategy == null || !strategy.applyFilterToCamelHeaders(key, value, exchange)) {
- httpRequest.addHeader(key, value);
+ if (strategy != null) {
+ final TypeConverter tc = exchange.getContext().getTypeConverter();
+ for (Map.Entry<String, Object> entry : in.getHeaders().entrySet()) {
+ String key = entry.getKey();
+ Object headerValue = entry.getValue();
+
+ if (headerValue != null) {
+
+ if (headerValue instanceof String) {
+ // optimise for string values
+ String value = (String) headerValue;
+ if (!strategy.applyFilterToCamelHeaders(key, value, exchange)) {
+ httpRequest.addHeader(key, value);
+ }
+ continue;
+ } else if (headerValue instanceof Long || headerValue instanceof Integer
+ || headerValue instanceof Boolean) {
+ // optimise for other common types
+ String value = tc.convertTo(String.class, exchange, headerValue);
+ if (!strategy.applyFilterToCamelHeaders(key, value, exchange)) {
+ httpRequest.addHeader(key, value);
+ }
+ continue;
}
- continue;
- }
- // use an iterator as there can be multiple values. (must not use a delimiter, and allow empty values)
- final Iterator<?> it = ObjectHelper.createIterator(headerValue, null, true);
+ // use an iterator as there can be multiple values. (must not use a delimiter, and allow empty values)
+ final Iterator<?> it = ObjectHelper.createIterator(headerValue, null, true);
- // the value to add as request header
- List<String> multiValues = null;
- String prev = null;
+ // the value to add as request header
+ List<String> multiValues = null;
+ String prev = null;
- // if its a multi value then check each value if we can add it and for multi values they
- // should be combined into a single value
- while (it.hasNext()) {
- String value = tc.convertTo(String.class, it.next());
+ // if its a multi value then check each value if we can add it and for multi values they
+ // should be combined into a single value
+ while (it.hasNext()) {
+ String value = tc.convertTo(String.class, it.next());
- // we should not add headers for the parameters in the uri if we bridge the endpoint
- // as then we would duplicate headers on both the endpoint uri, and in HTTP headers as well
- if (skipRequestHeaders != null && skipRequestHeaders.containsKey(key)) {
- continue;
- }
- if (value != null && strategy != null && !strategy.applyFilterToCamelHeaders(key, value, exchange)) {
- if (prev == null) {
- prev = value;
- } else {
- // only create array for multi values when really needed
- if (multiValues == null) {
- multiValues = new ArrayList<>();
- multiValues.add(prev);
+ // we should not add headers for the parameters in the uri if we bridge the endpoint
+ // as then we would duplicate headers on both the endpoint uri, and in HTTP headers as well
+ if (skipRequestHeaders != null && skipRequestHeaders.containsKey(key)) {
+ continue;
+ }
+ if (value != null && !strategy.applyFilterToCamelHeaders(key, value, exchange)) {
+ if (prev == null) {
+ prev = value;
+ } else {
+ // only create array for multi values when really needed
+ if (multiValues == null) {
+ multiValues = new ArrayList<>();
+ multiValues.add(prev);
+ }
+ multiValues.add(value);
}
- multiValues.add(value);
}
}
- }
- // add the value(s) as a http request header
- if (multiValues != null) {
- // use the default toString of a ArrayList to create in the form [xxx, yyy]
- // if multi valued, for a single value, then just output the value as is
- String s = multiValues.size() > 1 ? multiValues.toString() : multiValues.get(0);
- httpRequest.addHeader(key, s);
- } else if (prev != null) {
- httpRequest.addHeader(key, prev);
+ // add the value(s) as a http request header
+ if (multiValues != null) {
+ // use the default toString of a ArrayList to create in the form [xxx, yyy]
+ // if multi valued, for a single value, then just output the value as is
+ String s = multiValues.size() > 1 ? multiValues.toString() : multiValues.get(0);
+ httpRequest.addHeader(key, s);
+ } else if (prev != null) {
+ httpRequest.addHeader(key, prev);
+ }
}
}
}
[camel] 01/03: camel-vertx-http - Optimize a bit
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 66074e238c5f8db15776a84d29322c0449da0bb3
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Feb 14 15:33:29 2021 +0100
camel-vertx-http - Optimize a bit
---
.../vertx/http/DefaultVertxHttpBinding.java | 27 ++++++++++++++--------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/DefaultVertxHttpBinding.java b/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/DefaultVertxHttpBinding.java
index 024e147..b78354b 100644
--- a/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/DefaultVertxHttpBinding.java
+++ b/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/DefaultVertxHttpBinding.java
@@ -31,6 +31,7 @@ import io.vertx.ext.web.client.HttpResponse;
import io.vertx.ext.web.client.WebClient;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
+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;
@@ -81,9 +82,11 @@ public class DefaultVertxHttpBinding implements VertxHttpBinding {
}
// Configure query params
- Map<String, Object> queryParams = URISupport.parseQuery(queryString);
- for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
- request.addQueryParam(entry.getKey(), entry.getValue().toString());
+ if (ObjectHelper.isNotEmpty(queryString)) {
+ Map<String, Object> queryParams = URISupport.parseQuery(queryString);
+ for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
+ request.addQueryParam(entry.getKey(), entry.getValue().toString());
+ }
}
// Configure basic authentication
@@ -115,11 +118,15 @@ public class DefaultVertxHttpBinding implements VertxHttpBinding {
}
// Transfer exchange headers to the HTTP request while applying the filter strategy
- Message message = exchange.getMessage();
- for (Map.Entry<String, Object> entry : message.getHeaders().entrySet()) {
- String headerValue = message.getHeader(entry.getKey(), String.class);
- if (strategy != null && !strategy.applyFilterToCamelHeaders(entry.getKey(), headerValue, exchange)) {
- request.putHeader(entry.getKey(), headerValue);
+ if (strategy != null) {
+ final TypeConverter tc = exchange.getContext().getTypeConverter();
+ for (Map.Entry<String, Object> entry : exchange.getMessage().getHeaders().entrySet()) {
+ String key = entry.getKey();
+ Object headerValue = entry.getValue();
+ if (!strategy.applyFilterToCamelHeaders(key, headerValue, exchange)) {
+ String str = tc.convertTo(String.class, headerValue);
+ request.putHeader(key, str);
+ }
}
}
}
@@ -152,10 +159,12 @@ public class DefaultVertxHttpBinding implements VertxHttpBinding {
MultiMap headers = response.headers();
+ boolean found = false;
for (String headerName : headers.names()) {
String name = headerName;
String value = headers.get(headerName);
- if (name.equalsIgnoreCase("content-type")) {
+ if (!found && name.equalsIgnoreCase("content-type")) {
+ found = true;
name = Exchange.CONTENT_TYPE;
exchange.setProperty(Exchange.CHARSET_NAME, IOHelper.getCharsetNameFromContentType(value));
}