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
The following commit(s) were added to refs/heads/master by this push:
new 4b6b02a camel-http - Optimize to avoid type convertion that would do
deep checking.
4b6b02a is described below
commit 4b6b02aa636d0051d41aac4b6e75f100cc15dde6
Author: Claus Ibsen <[email protected]>
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();