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/18 05:38:06 UTC
[camel] 01/02: camel-http - Optimize to avoid type convertion that
would do deep checking.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch exchange-factory
in repository https://gitbox.apache.org/repos/asf/camel.git
commit b4019b2564b8814f49fe6d40235807b5d30c080d
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Feb 17 16:25:45 2021 +0100
camel-http - Optimize to avoid type convertion that would do deep checking.
---
.../org/apache/camel/component/http/HttpProducer.java | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 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 154debb..41d5205 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
@@ -616,12 +616,25 @@ public class HttpProducer extends DefaultProducer {
* @throws CamelExchangeException is thrown if error creating RequestEntity
*/
protected HttpEntity createRequestEntity(Exchange exchange) throws CamelExchangeException {
+ HttpEntity answer = null;
+
Message in = exchange.getIn();
- if (in.getBody() == null) {
- return null;
+ Object body = in.getBody();
+ try {
+ if (body == null) {
+ return null;
+ // special optimized for using these 3 type converters for common message payload types
+ } else if (body instanceof byte[]) {
+ answer = HttpEntityConverter.toHttpEntity((byte[]) body, exchange);
+ } else if (body instanceof InputStream) {
+ answer = HttpEntityConverter.toHttpEntity((InputStream) body, exchange);
+ } else if (body instanceof String) {
+ answer = HttpEntityConverter.toHttpEntity((String) body, exchange);
+ }
+ } catch (Exception e) {
+ throw new CamelExchangeException("Error creating RequestEntity from message body", exchange, e);
}
- HttpEntity answer = in.getBody(HttpEntity.class);
if (answer == null) {
try {
Object data = in.getBody();