[camel] branch master updated: CAMEL-13572: proper message body handling

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[camel] branch master updated: CAMEL-13572: proper message body handling

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

zregvart 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 ac304cc  CAMEL-13572: proper message body handling
ac304cc is described below

commit ac304cc17433383ab73d19896134e62f637302c3
Author: Zoran Regvart <[hidden email]>
AuthorDate: Fri May 24 11:43:01 2019 +0200

    CAMEL-13572: proper message body handling
   
    This checks if the message contains a non null body and responds with
    that instead of the response already present in the NettyHttpMessage.
---
 .../apache/camel/component/netty4/http/DefaultNettyHttpBinding.java | 2 +-
 .../org/apache/camel/component/netty4/http/ProxyProtocolTest.java   | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultNettyHttpBinding.java b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultNettyHttpBinding.java
index e51f65f..ee1e718 100644
--- a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultNettyHttpBinding.java
+++ b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultNettyHttpBinding.java
@@ -325,7 +325,7 @@ public class DefaultNettyHttpBinding implements NettyHttpBinding, Cloneable {
             final NettyHttpMessage nettyHttpMessage = (NettyHttpMessage) message;
             final FullHttpResponse response = nettyHttpMessage.getHttpResponse();
 
-            if (response != null) {
+            if (response != null && nettyHttpMessage.getBody() == null) {
                 return response.retain();
             }
         }
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/ProxyProtocolTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/ProxyProtocolTest.java
index b1b1dbd..d58dab5 100644
--- a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/ProxyProtocolTest.java
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/ProxyProtocolTest.java
@@ -22,6 +22,7 @@ import java.net.InetSocketAddress;
 import java.net.Proxy;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
+import java.util.Locale;
 
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.DefaultCamelContext;
@@ -47,7 +48,8 @@ public class ProxyProtocolTest {
                 // proxy from <a href="http://localhost:port">http://localhost:port to
                 // <a href="http://localhost:originPort/path">http://localhost:originPort/path
                 from("netty-http:proxy://localhost:" + port)
-                    .to("netty-http:http://localhost:" + originPort);
+                    .to("netty-http:http://localhost:" + originPort)
+                    .process(e -> e.getMessage().setBody(e.getMessage().getBody(String.class).toUpperCase(Locale.US)));
 
                 // origin service that serves `"origin server"` on
                 // <a href="http://localhost:originPort/path">http://localhost:originPort/path
@@ -74,7 +76,7 @@ public class ProxyProtocolTest {
         final HttpURLConnection connection = (HttpURLConnection) new URL("http://test/path").openConnection(proxy);
 
         try (InputStream stream = connection.getInputStream()) {
-            assertThat(IOUtils.readLines(stream, StandardCharsets.UTF_8)).containsOnly("origin server");
+            assertThat(IOUtils.readLines(stream, StandardCharsets.UTF_8)).containsOnly("ORIGIN SERVER");
         }
     }