help required chaining httphandler and proxyhandler

rzo rzo at gmx.de
Thu Sep 24 14:18:37 EDT 2009


hello,

I got this working.
for those interested here the changes:

stophandler:

             public void messageReceived(ChannelHandlerContext ctx, 
MessageEvent evt) {
                 if (evt.getMessage() != null)
                 {
                     HttpRequest request = (HttpRequest) evt.getMessage();
-->                     if (request.getContentLength() == 0 || 
request.getContentLength() == request.getContent().writerIndex())
                     {
                     ChannelBuffer buf = (ChannelBuffer) 
ctx.getPipeline().getContext("interceptStart").getAttachment();
                      if (buf == null)
                     {
                         System.out.println("no buff found");
                     }
                     else if (buf.writerIndex() != 0)
                     {
-->                         
ctx.getPipeline().getContext("interceptStart").setAttachment(null);
                         ctx.sendUpstream(new 
UpstreamMessageEvent(evt.getChannel(), buf, evt.getRemoteAddress()));
                     }
                     }

                 }
                }

- Ron


rzorzorzo wrote:
> hello,
>
> i am trying to implement a proxy which checks the http requests before
> forwarding these to another server.
> i tried implementing this with the following pipeline
>
> starthandler -> HttpRequestDecoder-> stophandler ->
> HexDumpProxyInboundHandler
>
> starthandler:
>
> remembers the incoming bytes in a dynamic buffer until the httprequest has
> been completely parsed
>
>    @Override
> 	 public void messageReceived(ChannelHandlerContext ctx, MessageEvent evt)
> throws Exception
> 	 {
> 		 ChannelBuffer m = (ChannelBuffer) evt.getMessage();
> 		 ChannelBuffer buf = (ChannelBuffer) ctx.getAttachment();
> 		 if (buf == null)
> 		 {
> 			 buf = dynamicBuffer();
> 			 ctx.setAttachment(buf);
> 		 }
> 		 m.markReaderIndex();
> 		 buf.writeBytes(m);
> 		 m.resetReaderIndex();
> 	     super.messageReceived(ctx, evt);
> 	    }
>
> stophandler
>
>
> 		    @Override
> 			 public void messageReceived(ChannelHandlerContext ctx, MessageEvent evt)
> {
> 				 if (isOk((HttpRequest)evt.getMessage()))
> 				 {
> 					 ChannelBuffer buf = (ChannelBuffer)
> ctx.getPipeline().getContext("interceptStart").getAttachment();
> 					ctx.sendUpstream(new UpstreamMessageEvent(evt.getChannel(), buf,
> evt.getRemoteAddress()));
>
> 				 }
> 			    }
>
> both extend simple channel upstream handler and
> @ChannelPipelineCoverage("one")
>
> for the first page this seems to work well, but for subsequent http requests
> not.
>
> any hints or help or other ideas how to implement this with netty ?
>
> - Ron
>
>   



More information about the netty-users mailing list