You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/11/25 05:38:18 UTC

[camel] branch camel-2.25.x updated: ByteArrayBodyGenerator for String body

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.25.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-2.25.x by this push:
     new e4334bc  ByteArrayBodyGenerator for String body
e4334bc is described below

commit e4334bc65b3cd9d7b9448b558bb70f3d6a3f38dc
Author: sms0070 <su...@gmail.com>
AuthorDate: Wed Nov 25 10:57:26 2020 +0530

    ByteArrayBodyGenerator for String body
---
 .../java/org/apache/camel/component/ahc/DefaultAhcBinding.java     | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java
index ffea5f7..0681607 100644
--- a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java
+++ b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java
@@ -48,6 +48,7 @@ import org.asynchttpclient.HttpResponseStatus;
 import org.asynchttpclient.Request;
 import org.asynchttpclient.RequestBuilder;
 import org.asynchttpclient.request.body.generator.BodyGenerator;
+import org.asynchttpclient.request.body.generator.ByteArrayBodyGenerator;
 import org.asynchttpclient.request.body.generator.FileBodyGenerator;
 import org.asynchttpclient.request.body.generator.InputStreamBodyGenerator;
 import org.slf4j.Logger;
@@ -169,7 +170,7 @@ public class DefaultAhcBinding implements AhcBinding {
                         ByteArrayOutputStream bos = new ByteArrayOutputStream(endpoint.getBufferSize());
                         AhcHelper.writeObjectToStream(bos, obj);
                         byte[] bytes = bos.toByteArray();
-                        body = new InputStreamBodyGenerator(new ByteArrayInputStream(bytes));
+                        body = new ByteArrayBodyGenerator(bytes);
                         IOHelper.close(bos);
                     } else if (data instanceof File || data instanceof GenericFile) {
                         // file based (could potentially also be a FTP file etc)
@@ -183,9 +184,9 @@ public class DefaultAhcBinding implements AhcBinding {
                         // do not fallback to use the default charset as it can influence the request
                         // (for example application/x-www-form-urlencoded forms being sent)
                         if (charset != null) {
-                            body = new InputStreamBodyGenerator(new ByteArrayInputStream(((String) data).getBytes(charset)));
+                            body = new ByteArrayBodyGenerator(((String) data).getBytes(charset));
                         } else {
-                            body = new InputStreamBodyGenerator(new ByteArrayInputStream(((String) data).getBytes()));
+                            body = new ByteArrayBodyGenerator(((String) data).getBytes());
                         }
                     }
                     // fallback as input stream