From 5b3b48409f48548b8e96b59eda4e156004f7157b Mon Sep 17 00:00:00 2001 From: fredericBregier Date: Sun, 17 Aug 2014 20:37:33 +0200 Subject: [PATCH] Fix example for Http Upload Motivation: The example mis handle two elements: 1) Last message is a LastHttpContent and is not taken into account by the server handler 2) The client makes a sync on last write (chunked) but there is no flush before, therefore the sync is waiting forever. Modifications: 1) Take into account the message LastHttpContent in simple Get. 2) Removes sync but add flush for each post and multipost parts Results: Example is no more blocked after get test. Should be done also in 4.0 and Master (similar changes) --- .../java/io/netty/example/http/upload/HttpUploadClient.java | 6 ++++-- .../netty/example/http/upload/HttpUploadServerHandler.java | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java b/example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java index 8fcafdc005..90264b3975 100644 --- a/example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java +++ b/example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java @@ -240,8 +240,9 @@ public final class HttpUploadClient { // test if request was chunked and if so, finish the write if (bodyRequestEncoder.isChunked()) { // could do either request.isChunked() // either do it through ChunkedWriteHandler - channel.write(bodyRequestEncoder).sync(); + channel.write(bodyRequestEncoder); } + channel.flush(); // Do not clear here since we will reuse the InterfaceHttpData on the next request // for the example (limit action on client side). Take this as a broadcast of the same @@ -290,8 +291,9 @@ public final class HttpUploadClient { // test if request was chunked and if so, finish the write if (bodyRequestEncoder.isChunked()) { - channel.write(bodyRequestEncoder).sync(); + channel.write(bodyRequestEncoder); } + channel.flush(); // Now no more use of file representation (and list of HttpData) bodyRequestEncoder.cleanFiles(); diff --git a/example/src/main/java/io/netty/example/http/upload/HttpUploadServerHandler.java b/example/src/main/java/io/netty/example/http/upload/HttpUploadServerHandler.java index 8e192b1e1b..49af258956 100644 --- a/example/src/main/java/io/netty/example/http/upload/HttpUploadServerHandler.java +++ b/example/src/main/java/io/netty/example/http/upload/HttpUploadServerHandler.java @@ -145,7 +145,7 @@ public class HttpUploadServerHandler extends SimpleChannelInboundHandler