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 received
HttpRequest and HttpChunk.
The original content is replaced with the new content decoded by the
DecoderEmbedder, which is created by newContentDecoder(String).
Once decoding is finished, the value of the 'Content-Encoding'
header is set to the target content encoding, as returned by getTargetContentEncoding(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 return null
so 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 of HttpContentDecompressor.
This handler must be placed after HttpMessageDecoder in the pipeline
so that this handler can intercept HTTP requests after HttpMessageDecoder
converts ChannelBuffers into HTTP requests.
-
Nested Class Summary
Nested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.Sharable -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidvoidvoidvoidInvoked when aChannelwas closed and all its related resources were released.private ChannelBufferdecode(ChannelBuffer buf) private ChannelBufferprotected StringgetTargetContentEncoding(String contentEncoding) Returns the expected content encoding of the decoded content.voidInvoked when a message object (e.g:ChannelBuffer) was received from a remote peer.protected abstract DecoderEmbedder<ChannelBuffer> newContentDecoder(String contentEncoding) Returns a newDecoderEmbedderthat decodes the HTTP message content encoded in the specified contentEncoding.Methods inherited from class SimpleChannelUpstreamHandler
channelBound, channelConnected, channelDisconnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, exceptionCaught, handleUpstream, writeComplete
-
Field Details
-
decoder
-
-
Constructor Details
-
HttpContentDecoder
protected HttpContentDecoder()Creates a new instance.
-
-
Method Details
-
messageReceived
Description copied from class:SimpleChannelUpstreamHandlerInvoked when a message object (e.g:ChannelBuffer) was received from a remote peer.- Overrides:
messageReceivedin classSimpleChannelUpstreamHandler- Throws:
Exception
-
channelClosed
Description copied from class:SimpleChannelUpstreamHandlerInvoked when aChannelwas closed and all its related resources were released.- Overrides:
channelClosedin classSimpleChannelUpstreamHandler- Throws:
Exception
-
newContentDecoder
protected abstract DecoderEmbedder<ChannelBuffer> newContentDecoder(String contentEncoding) throws 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:
Exception
-
getTargetContentEncoding
Returns 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:
Exception
-
decode
-
finishDecode
-
beforeAdd
- Specified by:
beforeAddin interfaceLifeCycleAwareChannelHandler- Throws:
Exception
-
afterAdd
- Specified by:
afterAddin interfaceLifeCycleAwareChannelHandler- Throws:
Exception
-
beforeRemove
- Specified by:
beforeRemovein interfaceLifeCycleAwareChannelHandler- Throws:
Exception
-
afterRemove
- Specified by:
afterRemovein interfaceLifeCycleAwareChannelHandler- Throws:
Exception
-