can't get netty channel pool to work with the snoop example

173 views
Skip to first unread message

ngp lah

unread,
Jul 4, 2017, 4:44:45 AM7/4/17
to Netty discussions
    // 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.


Norman Maurer

unread,
Jul 4, 2017, 5:03:03 AM7/4/17
to ne...@googlegroups.com
What does not work mean ?

Please give a few more details. Also what does the ChannelFuture for the writeAndFlush operations tell you ?


--
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 netty+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netty/80fae616-a29b-49d8-b5d1-f4a20bb6e7ad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ngp lah

unread,
Jul 4, 2017, 5:28:58 AM7/4/17
to Netty discussions
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.
Reply all
Reply to author
Forward
0 new messages