java - Netty 4 Outbound Message Handler Closing Connection -


i'm experimenting custom outbound message handler in netty 4 , cannot seem work. handler logs statement , added toward bottom of channel pipeline. understanding these handlers invoked bottom up, in order, once write operation issued. idea custom handler executed prior other outbound message handlers.

unfortunately, when add logging handler pipeline, see log statement netty seems close connection. here's channel initializer , outbound handler code.

httpoutboundhandler.java

public class httpoutboundhandler extends channeloutboundmessagehandleradapter<defaultfullhttpresponse> {     private static final logger logger = loggerfactory.getlogger(httpoutboundhandler.class);      @override     public void flush(channelhandlercontext context, defaultfullhttpresponse response)             throws exception {         logger.debug("executing outbound handler.");     } } 

httpchannelinitializer.java

@override protected void initchannel(socketchannel socketchannel) throws exception {     pipeline.addlast("encoder", new httpresponseencoder());     pipeline.addlast("decoder", new httprequestdecoder());     pipeline.addlast("aggregator", new httpobjectaggregator(1048576);     pipeline.addlast("compressor", new httpcontentcompressor(gziplevel));     pipeline.addlast("outboundhandler", outboundhandler);     pipeline.addlast(eventexecutorgroup, "inboundhandler", inboundhandler); } 

finally, here's logger output.

[debug] (slf4jlogger:71) - [id: 0xbddf00cf, /0:0:0:0:0:0:0:1:57402 => /0:0:0:0:0:0:0:1:8080] active [debug] (httpoutboundhandler:19) - executing outbound handler. [debug] (slf4jlogger:71) - [id: 0x942993c1, /0:0:0:0:0:0:0:1:57403 :> /0:0:0:0:0:0:0:1:8080] inactive 

answering own question in case else finds this.

it turns out needed add message next outbound message buffer (which believe has effect of passing next handler in chain). needed retain message. updated code looks like...

public class httpoutboundhandler extends channeloutboundmessagehandleradapter<defaultfullhttpresponse> {     private static final logger logger = loggerfactory.getlogger(httpoutboundhandler.class);      @override     public void flush(channelhandlercontext context, defaultfullhttpresponse response)             throws exception {         logger.debug("executing outbound handler.");         channelhandlerutil.addtonextoutboundbuffer(context, response.retain());     } } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -