
public abstract class HttpContentEncoder extends SimpleChannelHandler implements LifeCycleAwareChannelHandler
HttpResponse and HttpChunk.
The original content is replaced with the new content encoded by the
EncoderEmbedder, which is created by newContentEncoder(HttpMessage, String).
Once encoding 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
encoded content. If there is no supported encoding in the
corresponding HttpRequest's "Accept-Encoding" header,
newContentEncoder(HttpMessage, String) should return null so 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) and getTargetContentEncoding(String)
properly to make this class functional. For example, refer to the source
code of HttpContentCompressor.
This handler must be placed after HttpMessageEncoder in the pipeline
so that this handler can intercept HTTP responses before HttpMessageEncoder
converts them into ChannelBuffers.
ChannelHandler.Sharable| Modifier | Constructor and Description |
|---|---|
protected |
HttpContentEncoder()
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. |
protected abstract String |
getTargetContentEncoding(String acceptEncoding)
Returns the expected content encoding of the encoded content.
|
void |
messageReceived(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 new
EncoderEmbedder that encodes the HTTP message
content. |
void |
writeRequested(ChannelHandlerContext ctx,
MessageEvent e)
Invoked when
Channel.write(Object) is called. |
bindRequested, channelBound, channelConnected, channelDisconnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, closeRequested, connectRequested, disconnectRequested, exceptionCaught, handleDownstream, handleUpstream, setInterestOpsRequested, unbindRequested, writeCompletepublic void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
SimpleChannelHandlerChannelBuffer) was received
from a remote peer.messageReceived in class SimpleChannelHandlerExceptionpublic void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception
SimpleChannelHandlerChannel.write(Object) is called.writeRequested in class SimpleChannelHandlerExceptionpublic void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception
SimpleChannelHandlerChannel was closed and all its related resources
were released.channelClosed in class SimpleChannelHandlerExceptionprotected abstract EncoderEmbedder<ChannelBuffer> newContentEncoder(HttpMessage msg, String acceptEncoding) throws Exception
EncoderEmbedder that encodes the HTTP message
content.acceptEncoding - the value of the "Accept-Encoding" headerEncoderEmbedder if there is a supported encoding
in acceptEncoding. null otherwise.Exceptionprotected abstract String getTargetContentEncoding(String acceptEncoding) throws Exception
acceptEncoding - the value of the "Accept-Encoding" headerExceptionpublic void beforeAdd(ChannelHandlerContext ctx) throws Exception
beforeAdd in interface LifeCycleAwareChannelHandlerExceptionpublic void afterAdd(ChannelHandlerContext ctx) throws Exception
afterAdd in interface LifeCycleAwareChannelHandlerExceptionpublic void beforeRemove(ChannelHandlerContext ctx) throws Exception
beforeRemove in interface LifeCycleAwareChannelHandlerExceptionpublic void afterRemove(ChannelHandlerContext ctx) throws Exception
afterRemove in interface LifeCycleAwareChannelHandlerExceptionCopyright © 2008-2014 The Netty Project. All Rights Reserved.