The ChannelFuture for the writeAndFlush tells DefaultChannelPromise@52d10fb8(failure: java.lang.UnsupportedOperationException: unsupported message type: DefaultFullHttpRequest (expected: ByteBuf, FileRegion)). I want the handler print the http response of the http request if it works.
On Tuesday, July 4, 2017 at 5:03:03 PM UTC+8, Norman Maurer wrote: > > What does not work mean ? > > Please give a few more details. Also what does the ChannelFuture for the > writeAndFlush operations tell you ? > > > On 4. Jul 2017, at 10:44, ngp lah <[email protected] <javascript:>> wrote: > > // Configure the client. > EventLoopGroup group = new NioEventLoopGroup(); > try { > Bootstrap b = new Bootstrap(); > //b.group(group) > // .channel(NioSocketChannel.class) > // .handler(new HttpSnoopClientInitializer(sslCtx)); > // > //// Make the connection attempt. > //Channel ch = b.connect(host, port).sync().channel(); > > b.group(group).channel(NioSocketChannel.class).handler(new > HttpSnoopClientInitializer(sslCtx)).remoteAddress(host, port); > CountingChannelPoolHandler handler = new > CountingChannelPoolHandler(); // CountingChannelPoolHandler is copied > from netty test! > SimpleChannelPool pool = new SimpleChannelPool(b, handler); > Channel ch = pool.acquire().sync().getNow(); > > // Prepare the HTTP request. > HttpRequest request = new DefaultFullHttpRequest( > HttpVersion.HTTP_1_1, HttpMethod.GET, uri.getRawPath()); > request.headers().set(HttpHeaderNames.HOST, host); > request.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues > .CLOSE); > request.headers().set(HttpHeaderNames.ACCEPT_ENCODING, > HttpHeaderValues.GZIP); > > // Set some example cookies. > request.headers().set( > HttpHeaderNames.COOKIE, > ClientCookieEncoder.STRICT.encode( > new DefaultCookie("my-cookie", "foo"), > new DefaultCookie("another-cookie", "bar"))); > > // Send the HTTP request. > ch.writeAndFlush(request); > > // Wait for the server to close the connection. > ch.closeFuture().sync(); > } finally { > // Shut down executor threads to exit. > group.shutdownGracefully(); > } > > I have posted this question on SO, but few of them get reply, so I post my > question here. > I use the snoop client of netty example in netty source code for testing. > I make some changes to the HttpSnoopClient class to get channel from > channel pool instead of getting it from Bootstrap, But that doesn't work > for me. > I have searched solution for one day, but I can still not get one. Please > tell me If you have any idea. > > > > -- > You received this message because you are subscribed to the Google Groups > "Netty discussions" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] <javascript:>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/netty/80fae616-a29b-49d8-b5d1-f4a20bb6e7ad%40googlegroups.com > > <https://groups.google.com/d/msgid/netty/80fae616-a29b-49d8-b5d1-f4a20bb6e7ad%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > > > -- You received this message because you are subscribed to the Google Groups "Netty discussions" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/netty/260183cb-bbd4-4539-b2ea-cef94c5055d2%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
