Requête HTTP à l'aide de Netty

Je viens de commencer netty et je suis vraiment déçu de la documentation présente sur
leur site web.

Je suis en train d'essayer de vous connecter à une URL à l'aide de Netty.. j'ai pris le temps de client exemple à partir de leur site web et il a changé comme par mon exigence..

Code :

public class NettyClient {

      public static void main(String[] args) throws Exception {
          String host = "myUrl.com/v1/parma?param1=value";
            int port = 443;
            EventLoopGroup workerGroup = new NioEventLoopGroup();

            try {
                Bootstrap b = new Bootstrap();             
                b.group(workerGroup); 
                b.channel(NioSocketChannel.class); 
                b.option(ChannelOption.SO_KEEPALIVE, true); 
                b.handler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ch.pipeline().addLast(new ClientHandler());
                        ch.pipeline().addLast("encoder", new HttpRequestEncoder());
                    }
                });

                //Start the client.
                ChannelFuture f = b.connect(host, port).sync(); 

                //Wait until the connection is closed.
                f.channel().closeFuture().sync();
            } finally {
                workerGroup.shutdownGracefully();
            }
        }
}

Mais le problème est qu'il s'attend à ce que l'url sans les paramètres de la requête.. Comment puis-je passer les paramètres de la requête avec l'URL?
et s'il vous plaît me donner un lien d'une bonne documentation pour Netty 4..

MODIFIER

Code Client après avoir cité l'exemple mentionné dans la réponse :

URI uri = new URI("myUrl.com/v1/parma?param1=value");          
           String scheme = uri.getScheme() == null? "http" : uri.getScheme();
           String host = "myUrl.com";
            int port = 443;



            boolean ssl = "https".equalsIgnoreCase(scheme);

         //Configure the client.
            EventLoopGroup group = new NioEventLoopGroup();
            try {
                Bootstrap b = new Bootstrap();
                b.group(group)
                 .channel(NioSocketChannel.class)
                 .handler(new NettyClientInitializer(ssl));
                //Make the connection attempt.
                Channel ch = b.connect(host, port).sync().channel();
                //Prepare the HTTP request.
                HttpRequest request = new DefaultHttpRequest(
                        HttpVersion.HTTP_1_1, HttpMethod.GET, uri.getRawPath());
                request.headers().set(HttpHeaders.Names.HOST, host);
                request.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
                //request.headers().set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);

                /*//Set some example cookies.
                request.headers().set(
                        HttpHeaders.Names.COOKIE,
                        ClientCookieEncoder.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();
            }

code du gestionnaire :

public class ClientHandler extends SimpleChannelInboundHandler<HttpObject> {

    @Override
    public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
        if (msg instanceof HttpResponse) {
            HttpResponse response = (HttpResponse) msg;

            System.out.println("STATUS: " + response.getStatus());
            System.out.println("VERSION: " + response.getProtocolVersion());
            System.out.println();

            if (!response.headers().isEmpty()) {
                for (String name: response.headers().names()) {
                    for (String value: response.headers().getAll(name)) {
                        System.out.println("HEADER: " + name + " = " + value);
                    }
                }
                System.out.println();
            }

            if (HttpHeaders.isTransferEncodingChunked(response)) {
                System.out.println("CHUNKED CONTENT {");
            } else {
                System.out.println("CONTENT {");
            }
        }
        if (msg instanceof HttpContent) {
            HttpContent content = (HttpContent) msg;

            System.out.print(content.content().toString(CharsetUtil.UTF_8));
            System.out.flush();

            if (content instanceof LastHttpContent) {
                System.out.println("} END OF CONTENT");
            }
        }
    }

    @Override
    public void exceptionCaught(
            ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }


}

initialiseur de code :

public class NettyClientInitializer extends ChannelInitializer<SocketChannel> {

    private final boolean ssl;

    public NettyClientInitializer(boolean ssl) {
        this.ssl = ssl;
    }

    @Override
    public void initChannel(SocketChannel ch) throws Exception {
        //Create a default pipeline implementation.
        ChannelPipeline p = ch.pipeline();

        p.addLast("log", new LoggingHandler(LogLevel.INFO));
        //Enable HTTPS if necessary.
        /*
        if (ssl) {
            SSLEngine engine =
                SecureChatSslContextFactory.getClientContext().createSSLEngine();
            engine.setUseClientMode(true);

            p.addLast("ssl", new SslHandler(engine));
        }
*/
        p.addLast("codec", new HttpClientCodec());

        //Remove the following line if you don't want automatic content decompression.
       //p.addLast("inflater", new HttpContentDecompressor());

        //Uncomment the following line if you don't want to handle HttpChunks.
        p.addLast("aggregator", new HttpObjectAggregator(1048576));
        p.addLast("handler", new ClientHandler());
    }
}

OriginalL'auteur Mitaksh Gupta | 2013-11-18