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 outbound
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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jboss.netty.channel.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 ChannelBufferencode(ChannelBuffer buf) private ChannelBufferprotected abstract StringgetTargetContentEncoding(String acceptEncoding) Returns the expected content encoding of the encoded content.voidInvoked 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.voidInvoked 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
-
Field Details
-
acceptEncodingQueue
-
encoder
-
offerred
private volatile boolean offerred
-
-
Constructor Details
-
HttpContentEncoder
protected HttpContentEncoder()Creates a new instance.
-
-
Method Details
-
messageReceived
Description copied from class:SimpleChannelHandlerInvoked when a message object (e.g:ChannelBuffer) was received from a remote peer.- Overrides:
messageReceivedin classSimpleChannelHandler- Throws:
Exception
-
writeRequested
Description copied from class:SimpleChannelHandlerInvoked whenChannel.write(Object)is called.- Overrides:
writeRequestedin classSimpleChannelHandler- Throws:
Exception
-
channelClosed
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
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
-
encode
-
finishEncode
-
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
-