[cxf] branch 3.2.x-fixes updated: CXF-8282: Set read timeout using netty client. Closing the context when HTTP response is fully read

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

[cxf] branch 3.2.x-fixes updated: CXF-8282: Set read timeout using netty client. Closing the context when HTTP response is fully read

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

reta pushed a commit to branch 3.2.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/3.2.x-fixes by this push:
     new ae58236  CXF-8282: Set read timeout using netty client. Closing the context when HTTP response is fully read
ae58236 is described below

commit ae58236888707c8f481fe45cd303c189dbe91c4f
Author: reta <[hidden email]>
AuthorDate: Tue May 19 13:22:42 2020 -0400

    CXF-8282: Set read timeout using netty client. Closing the context when HTTP response is fully read
   
    (cherry picked from commit e8408a701c7051a2354c654d128b8c17d5645f17)
    (cherry picked from commit 01cc632cb56e5b23aea0985aa1e17259ee4b5516)
---
 .../http/netty/client/NettyHttpClientHandler.java  | 32 ++++++++++++----------
 .../http/netty/client/NettyHttpConduitTest.java    | 17 +++++++++++-
 2 files changed, 34 insertions(+), 15 deletions(-)

diff --git a/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpClientHandler.java b/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpClientHandler.java
index f6d1d5f..218997c 100644
--- a/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpClientHandler.java
+++ b/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpClientHandler.java
@@ -26,7 +26,9 @@ import java.util.concurrent.LinkedBlockingDeque;
 import io.netty.channel.ChannelDuplexHandler;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelPromise;
+import io.netty.handler.codec.http.HttpObject;
 import io.netty.handler.codec.http.HttpResponse;
+import io.netty.handler.codec.http.LastHttpContent;
 import io.netty.handler.timeout.ReadTimeoutException;
 
 public class NettyHttpClientHandler extends ChannelDuplexHandler {
@@ -35,14 +37,19 @@ public class NettyHttpClientHandler extends ChannelDuplexHandler {
 
     @Override
     public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
-
-        if (msg instanceof HttpResponse) {
-            // just make sure we can combine the request and response together
-            HttpResponse response = (HttpResponse)msg;
-            NettyHttpClientRequest request = sendedQueue.poll();
-            request.setResponse(response);
-            // calling the callback here
-            request.getCxfResponseCallback().responseReceived(response);
+        if (msg instanceof HttpObject) {
+            if (msg instanceof HttpResponse) {
+                // just make sure we can combine the request and response together
+                HttpResponse response = (HttpResponse)msg;
+                NettyHttpClientRequest request = sendedQueue.poll();
+                request.setResponse(response);
+                // calling the callback here
+                request.getCxfResponseCallback().responseReceived(response);
+            }
+            
+            if (msg instanceof LastHttpContent) {
+                ctx.close();
+            }
         } else {
             super.channelRead(ctx, msg);
         }
@@ -66,17 +73,14 @@ public class NettyHttpClientHandler extends ChannelDuplexHandler {
         if (cause instanceof ReadTimeoutException) {
             final NettyHttpClientRequest request = sendedQueue.poll();
             request.getCxfResponseCallback().error(new IOException(cause));
+        } else {
+            cause.printStackTrace();
+            ctx.close();
         }
-        
-        cause.printStackTrace();
-        ctx.close();
     }
 
     @Override
     public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
         ctx.flush();
     }
-
-
-
 }
diff --git a/rt/transports/http-netty/netty-client/src/test/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduitTest.java b/rt/transports/http-netty/netty-client/src/test/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduitTest.java
index b270445..70ea35b 100644
--- a/rt/transports/http-netty/netty-client/src/test/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduitTest.java
+++ b/rt/transports/http-netty/netty-client/src/test/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduitTest.java
@@ -146,7 +146,6 @@ public class NettyHttpConduitTest extends AbstractBusClientServerTestBase {
         }
     }
 
-
     @Test
     public void testTimeoutWithPropertySetting() throws Exception {
         ((javax.xml.ws.BindingProvider)g).getRequestContext().put("javax.xml.ws.client.receiveTimeout",
@@ -175,6 +174,22 @@ public class NettyHttpConduitTest extends AbstractBusClientServerTestBase {
             //expected!!!
         }
     }
+    
+    @Test
+    public void testNoTimeoutAsync() throws Exception {
+        updateAddressPort(g, PORT);
+        HTTPConduit c = (HTTPConduit)ClientProxy.getClient(g).getConduit();
+        c.getClient().setReceiveTimeout(2000);
+        c.getClient().setAsyncExecuteTimeout(2000);
+
+        Response<GreetMeLaterResponse> future = g.greetMeLaterAsync(-100L);
+        future.get();
+        
+        Response<GreetMeLaterResponse> future2 = g.greetMeLaterAsync(-100L);
+        future2.get();
+        
+        Thread.sleep(3000);
+    }
 
     @Test
     public void testTimeoutAsyncWithPropertySetting() throws Exception {