public abstract class HttpContentDecoder extends SimpleChannelUpstreamHandler implements LifeCycleAwareChannelHandler
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.
ChannelHandler.Sharable| Modifier and Type | Field and Description |
|---|---|
private DecoderEmbedder<ChannelBuffer> |
decoder |
| Modifier | Constructor and Description |
|---|---|
protected |
HttpContentDecoder()
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
afterAdd(ChannelHandlerContext ctx) |
void |
afterRemove(ChannelHandlerContext ctx) |
void |
beforeAdd(ChannelHandlerContext ctx) |
void |
beforeRemove(ChannelHandlerContext ctx) |
void |
channelClosed(ChannelHandlerContext ctx,
ChannelStateEvent e)
Invoked when a
Channel was closed and all its related resources
were released. |
private ChannelBuffer |
decode(ChannelBuffer buf) |
private ChannelBuffer |
finishDecode() |
protected java.lang.String |
getTargetContentEncoding(java.lang.String contentEncoding)
Returns the expected content encoding of the decoded content.
|
void |
messageReceived(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 new
DecoderEmbedder that decodes the HTTP message
content encoded in the specified contentEncoding. |
channelBound, channelConnected, channelDisconnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, exceptionCaught, handleUpstream, writeCompleteprivate DecoderEmbedder<ChannelBuffer> decoder
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws java.lang.Exception
SimpleChannelUpstreamHandlerChannelBuffer) was received
from a remote peer.messageReceived in class SimpleChannelUpstreamHandlerjava.lang.Exceptionpublic void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
SimpleChannelUpstreamHandlerChannel was closed and all its related resources
were released.channelClosed in class SimpleChannelUpstreamHandlerjava.lang.Exceptionprotected abstract DecoderEmbedder<ChannelBuffer> newContentDecoder(java.lang.String contentEncoding) throws java.lang.Exception
DecoderEmbedder that decodes the HTTP message
content encoded in the specified contentEncoding.contentEncoding - the value of the "Content-Encoding" headerDecoderEmbedder if the specified encoding is supported.
null otherwise (alternatively, you can throw an exception
to block unknown encoding).java.lang.Exceptionprotected java.lang.String getTargetContentEncoding(java.lang.String contentEncoding)
throws java.lang.Exception
"identity" by default, which is the case for
most decoders.contentEncoding - the value of the "Content-Encoding" headerjava.lang.Exceptionprivate ChannelBuffer decode(ChannelBuffer buf)
private ChannelBuffer finishDecode()
public void beforeAdd(ChannelHandlerContext ctx) throws java.lang.Exception
beforeAdd in interface LifeCycleAwareChannelHandlerjava.lang.Exceptionpublic void afterAdd(ChannelHandlerContext ctx) throws java.lang.Exception
afterAdd in interface LifeCycleAwareChannelHandlerjava.lang.Exceptionpublic void beforeRemove(ChannelHandlerContext ctx) throws java.lang.Exception
beforeRemove in interface LifeCycleAwareChannelHandlerjava.lang.Exceptionpublic void afterRemove(ChannelHandlerContext ctx) throws java.lang.Exception
afterRemove in interface LifeCycleAwareChannelHandlerjava.lang.Exception