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

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


The following commit(s) were added to refs/heads/camel-2.20.x by this push:
     new 4a070d0  CAMEL-12475 Fix the NPE error of camel-undertow component by 
adding the converter from InputStream into ByteBuffer
4a070d0 is described below

commit 4a070d0849812cac85eafb99345b3a27ebeb6c82
Author: Willem Jiang <jiangni...@huawei.com>
AuthorDate: Thu May 3 10:18:33 2018 +0800

    CAMEL-12475 Fix the NPE error of camel-undertow component by adding the 
converter from InputStream into ByteBuffer
---
 .../java/org/apache/camel/converter/IOConverter.java  |  7 +++++++
 .../component/undertow/UndertowProducerTest.java      | 19 +++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git 
a/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java 
b/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
index 72dab06..efb52cc 100644
--- a/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
+++ b/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
@@ -424,6 +424,13 @@ public final class IOConverter {
         return os.toByteArray();
     }
 
+    @Converter
+    public static ByteBuffer covertToByteBuffer(InputStream is) throws 
IOException {
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        IOHelper.copyAndCloseInput(is, os);
+        return ByteBuffer.wrap(os.toByteArray());
+    }
+
     /**
      * @deprecated will be removed in Camel 3.0. Use the method which has 2 
parameters.
      */
diff --git 
a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowProducerTest.java
 
b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowProducerTest.java
index ed6f2a4..91dd1a9 100644
--- 
a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowProducerTest.java
+++ 
b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowProducerTest.java
@@ -16,6 +16,9 @@
  */
 package org.apache.camel.component.undertow;
 
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.junit.Test;
@@ -75,14 +78,30 @@ public class UndertowProducerTest extends BaseUndertowTest {
         assertMockEndpointsSatisfied();
     }
 
+    @Test
+    public void testHttpInputStream() throws Exception {
+        getMockEndpoint("mock:input").expectedBodiesReceived("Hello World");
+        
getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_METHOD, 
"POST");
+
+        String out = 
template.requestBodyAndHeader("undertow:http://localhost:{{port2}}/bar";, "Hello 
World", Exchange.HTTP_METHOD, "POST", String.class);
+        assertEquals("This is the InputStream", out);
+
+        assertMockEndpointsSatisfied();
+    }
+
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
+            private InputStream is = new ByteArrayInputStream("This is the 
InputStream".getBytes());
             @Override
             public void configure() throws Exception {
                 from("undertow:http://localhost:{{port}}/foo";)
                     .to("mock:input")
                     .transform().constant("Bye World");
+
+                from("undertow:http://localhost:{{port2}}/bar";)
+                    .to("mock:input")
+                    .transform().constant(is);
             }
         };
     }

-- 
To stop receiving notification emails like this one, please contact
ningji...@apache.org.

Reply via email to