@@ -17,23 +17,25 @@ public class NettyHttpOutboundHandler extends ChannelInboundHandlerAdapter {
1717 private ByteBufToBytes reader ;
1818 private ChannelHandlerContext parentCtx ;
1919 private int contentLength = 0 ;
20- private String proxyServer = null ;
21- public NettyHttpOutboundHandler (ChannelHandlerContext ctx , String proxyServer ) {
20+ private FullHttpRequest fullHttpRequest = null ;
21+ private String backendUrl ;
22+ public NettyHttpOutboundHandler (ChannelHandlerContext ctx , FullHttpRequest fullHttpRequest , String backendUrl ) {
2223 this .parentCtx = ctx ;
23- this .proxyServer = proxyServer ;
24+ this .fullHttpRequest = fullHttpRequest ;
25+ this .backendUrl = backendUrl ;
2426 }
2527 @ Override
2628 public void channelActive (ChannelHandlerContext ctx )
2729 throws Exception {
28- System .out .println ("channelActive" );
30+ // System.out.println("channelActive");
2931 /* URI uri = new URI("/api/hello");
3032 FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri.toASCIIString());
3133 request.headers().add(HttpHeaderNames.CONNECTION,HttpHeaderValues.KEEP_ALIVE);
3234 request.headers().add(HttpHeaderNames.CONTENT_LENGTH,request.content().readableBytes());
3335 ctx.writeAndFlush(request);*/
34- String host = proxyServer .replaceAll ("/" , "" ).split (":" )[1 ];
35- DefaultFullHttpRequest request = new DefaultFullHttpRequest (
36- HttpVersion .HTTP_1_1 , HttpMethod . GET , new URI ( "/api/hello" ). toASCIIString ());
36+ String host = backendUrl .replaceAll ("/" , "" ).split (":" )[1 ];
37+ DefaultFullHttpRequest request = new DefaultFullHttpRequest (
38+ HttpVersion .HTTP_1_1 , fullHttpRequest . method (), fullHttpRequest . uri ());
3739 /*DefaultFullHttpRequest request = new DefaultFullHttpRequest(
3840 HttpVersion.HTTP_1_1, HttpMethod.GET, new URI("/").toASCIIString());*/
3941
@@ -49,12 +51,12 @@ public void channelActive(ChannelHandlerContext ctx)
4951 @ Override
5052 public void channelRead (ChannelHandlerContext ctx , Object msg )
5153 throws Exception {
52- System .out .println ("channelRead" );
54+ // System.out.println("channelRead");
5355
5456 if (msg instanceof HttpResponse ) {
5557 HttpResponse response = (HttpResponse ) msg ;
56- System .out .println ("CONTENT_TYPE:"
57- + response .headers ().get (HttpHeaderNames .CONTENT_TYPE ));
58+ /* System.out.println("CONTENT_TYPE:"
59+ + response.headers().get(HttpHeaderNames.CONTENT_TYPE));*/
5860 if (HttpUtil .isContentLengthSet (response )) {
5961 contentLength = (int ) HttpUtil .getContentLength (response );
6062 reader = new ByteBufToBytes (contentLength );
@@ -66,7 +68,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg)
6668 reader .reading (content );
6769 content .release ();
6870 byte [] bytes = reader .readFull ();
69- System .out .println (new String (bytes ));
71+ // System.out.println(new String(bytes));
7072 if (reader .isEnd ()) {
7173 FullHttpResponse response = null ;
7274 try {
0 commit comments