This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-3.7.x in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.7.x by this push: new bb09cf8d camel-http - Optimize to avoid type convertion that would do deep checking. bb09cf8d is described below commit bb09cf8ddb5cf77587d0ea6a9060d8f39dc56e91 Author: Claus Ibsen <claus.ib...@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 7a1cfa5..446e93d 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 @@ -540,12 +540,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();