Class HttpContentEncoder
- java.lang.Object
-
- org.jboss.netty.channel.SimpleChannelHandler
-
- org.jboss.netty.handler.codec.http.HttpContentEncoder
-
- All Implemented Interfaces:
ChannelDownstreamHandler,ChannelHandler,ChannelUpstreamHandler,LifeCycleAwareChannelHandler
- Direct Known Subclasses:
HttpContentCompressor
public abstract class HttpContentEncoder extends SimpleChannelHandler implements LifeCycleAwareChannelHandler
Encodes the content of the outboundHttpResponseandHttpChunk. The original content is replaced with the new content encoded by theEncoderEmbedder, which is created bynewContentEncoder(HttpMessage, String). Once encoding is finished, the value of the 'Content-Encoding' header is set to the target content encoding, as returned bygetTargetContentEncoding(String). Also, the 'Content-Length' header is updated to the length of the encoded content. If there is no supported encoding in the correspondingHttpRequest's"Accept-Encoding"header,newContentEncoder(HttpMessage, String)should returnnullso that no encoding occurs (i.e. pass-through).Please note that this is an abstract class. You have to extend this class and implement
newContentEncoder(HttpMessage, String)andgetTargetContentEncoding(String)properly to make this class functional. For example, refer to the source code ofHttpContentCompressor.This handler must be placed after
HttpMessageEncoderin the pipeline so that this handler can intercept HTTP responses beforeHttpMessageEncoderconverts them intoChannelBuffers.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedHttpContentEncoder()Creates a new instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidafterAdd(ChannelHandlerContext ctx)voidafterRemove(ChannelHandlerContext ctx)voidbeforeAdd(ChannelHandlerContext ctx)voidbeforeRemove(ChannelHandlerContext ctx)voidchannelClosed(ChannelHandlerContext ctx, ChannelStateEvent e)Invoked when aChannelwas closed and all its related resources were released.protected abstract StringgetTargetContentEncoding(String acceptEncoding)Returns the expected content encoding of the encoded content.voidmessageReceived(ChannelHandlerContext ctx, MessageEvent e)Invoked when a message object (e.g:ChannelBuffer) was received from a remote peer.protected abstract EncoderEmbedder<ChannelBuffer>newContentEncoder(HttpMessage msg, String acceptEncoding)Returns a newEncoderEmbedderthat encodes the HTTP message content.voidwriteRequested(ChannelHandlerContext ctx, MessageEvent e)Invoked whenChannel.write(Object)is called.-
Methods inherited from class org.jboss.netty.channel.SimpleChannelHandler
bindRequested, channelBound, channelConnected, channelDisconnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, closeRequested, connectRequested, disconnectRequested, exceptionCaught, handleDownstream, handleUpstream, setInterestOpsRequested, unbindRequested, writeComplete
-
-
-
-
Method Detail
-
messageReceived
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
Description copied from class:SimpleChannelHandlerInvoked when a message object (e.g:ChannelBuffer) was received from a remote peer.- Overrides:
messageReceivedin classSimpleChannelHandler- Throws:
Exception
-
writeRequested
public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception
Description copied from class:SimpleChannelHandlerInvoked whenChannel.write(Object)is called.- Overrides:
writeRequestedin classSimpleChannelHandler- Throws:
Exception
-
channelClosed
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception
Description copied from class:SimpleChannelHandlerInvoked when aChannelwas closed and all its related resources were released.- Overrides:
channelClosedin classSimpleChannelHandler- Throws:
Exception
-
newContentEncoder
protected abstract EncoderEmbedder<ChannelBuffer> newContentEncoder(HttpMessage msg, String acceptEncoding) throws Exception
Returns a newEncoderEmbedderthat encodes the HTTP message content.- Parameters:
acceptEncoding- the value of the"Accept-Encoding"header- Returns:
- a new
EncoderEmbedderif there is a supported encoding inacceptEncoding.nullotherwise. - Throws:
Exception
-
getTargetContentEncoding
protected abstract String getTargetContentEncoding(String acceptEncoding) throws Exception
Returns the expected content encoding of the encoded content.- Parameters:
acceptEncoding- the value of the"Accept-Encoding"header- Returns:
- the expected content encoding of the new content
- Throws:
Exception
-
beforeAdd
public void beforeAdd(ChannelHandlerContext ctx) throws Exception
- Specified by:
beforeAddin interfaceLifeCycleAwareChannelHandler- Throws:
Exception
-
afterAdd
public void afterAdd(ChannelHandlerContext ctx) throws Exception
- Specified by:
afterAddin interfaceLifeCycleAwareChannelHandler- Throws:
Exception
-
beforeRemove
public void beforeRemove(ChannelHandlerContext ctx) throws Exception
- Specified by:
beforeRemovein interfaceLifeCycleAwareChannelHandler- Throws:
Exception
-
afterRemove
public void afterRemove(ChannelHandlerContext ctx) throws Exception
- Specified by:
afterRemovein interfaceLifeCycleAwareChannelHandler- Throws:
Exception
-
-