Class HttpContentDecoder
- java.lang.Object
-
- org.jboss.netty.channel.SimpleChannelUpstreamHandler
-
- org.jboss.netty.handler.codec.http.HttpContentDecoder
-
- All Implemented Interfaces:
ChannelHandler,ChannelUpstreamHandler,LifeCycleAwareChannelHandler
- Direct Known Subclasses:
HttpContentDecompressor
public abstract class HttpContentDecoder extends SimpleChannelUpstreamHandler implements LifeCycleAwareChannelHandler
Decodes the content of the receivedHttpRequestandHttpChunk. The original content is replaced with the new content decoded by theDecoderEmbedder, which is created bynewContentDecoder(String). Once decoding 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 decoded content. If the content encoding of the original is not supported by the decoder,newContentDecoder(String)should returnnullso that no decoding occurs (i.e. pass-through).Please note that this is an abstract class. You have to extend this class and implement
newContentDecoder(String)properly to make this class functional. For example, refer to the source code ofHttpContentDecompressor.This handler must be placed after
HttpMessageDecoderin the pipeline so that this handler can intercept HTTP requests afterHttpMessageDecoderconvertsChannelBuffers into HTTP requests.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Field Summary
Fields Modifier and Type Field Description private DecoderEmbedder<ChannelBuffer>decoder
-
Constructor Summary
Constructors Modifier Constructor Description protectedHttpContentDecoder()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.private ChannelBufferdecode(ChannelBuffer buf)private ChannelBufferfinishDecode()protected java.lang.StringgetTargetContentEncoding(java.lang.String contentEncoding)Returns the expected content encoding of the decoded content.voidmessageReceived(ChannelHandlerContext ctx, MessageEvent e)Invoked when a message object (e.g:ChannelBuffer) was received from a remote peer.protected abstract DecoderEmbedder<ChannelBuffer>newContentDecoder(java.lang.String contentEncoding)Returns a newDecoderEmbedderthat decodes the HTTP message content encoded in the specified contentEncoding.-
Methods inherited from class org.jboss.netty.channel.SimpleChannelUpstreamHandler
channelBound, channelConnected, channelDisconnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, exceptionCaught, handleUpstream, writeComplete
-
-
-
-
Field Detail
-
decoder
private DecoderEmbedder<ChannelBuffer> decoder
-
-
Method Detail
-
messageReceived
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws java.lang.Exception
Description copied from class:SimpleChannelUpstreamHandlerInvoked when a message object (e.g:ChannelBuffer) was received from a remote peer.- Overrides:
messageReceivedin classSimpleChannelUpstreamHandler- Throws:
java.lang.Exception
-
channelClosed
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
Description copied from class:SimpleChannelUpstreamHandlerInvoked when aChannelwas closed and all its related resources were released.- Overrides:
channelClosedin classSimpleChannelUpstreamHandler- Throws:
java.lang.Exception
-
newContentDecoder
protected abstract DecoderEmbedder<ChannelBuffer> newContentDecoder(java.lang.String contentEncoding) throws java.lang.Exception
Returns a newDecoderEmbedderthat decodes the HTTP message content encoded in the specified contentEncoding.- Parameters:
contentEncoding- the value of the"Content-Encoding"header- Returns:
- a new
DecoderEmbedderif the specified encoding is supported.nullotherwise (alternatively, you can throw an exception to block unknown encoding). - Throws:
java.lang.Exception
-
getTargetContentEncoding
protected java.lang.String getTargetContentEncoding(java.lang.String contentEncoding) throws java.lang.ExceptionReturns the expected content encoding of the decoded content. This method returns"identity"by default, which is the case for most decoders.- Parameters:
contentEncoding- the value of the"Content-Encoding"header- Returns:
- the expected content encoding of the new content
- Throws:
java.lang.Exception
-
decode
private ChannelBuffer decode(ChannelBuffer buf)
-
finishDecode
private ChannelBuffer finishDecode()
-
beforeAdd
public void beforeAdd(ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
beforeAddin interfaceLifeCycleAwareChannelHandler- Throws:
java.lang.Exception
-
afterAdd
public void afterAdd(ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
afterAddin interfaceLifeCycleAwareChannelHandler- Throws:
java.lang.Exception
-
beforeRemove
public void beforeRemove(ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
beforeRemovein interfaceLifeCycleAwareChannelHandler- Throws:
java.lang.Exception
-
afterRemove
public void afterRemove(ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
afterRemovein interfaceLifeCycleAwareChannelHandler- Throws:
java.lang.Exception
-
-