org.jboss.netty.handler.codec.http2
Class HttpContentEncoder

java.lang.Object
  extended by org.jboss.netty.channel.SimpleChannelHandler
      extended by org.jboss.netty.handler.codec.http2.HttpContentEncoder
All Implemented Interfaces:
org.jboss.netty.channel.ChannelDownstreamHandler, org.jboss.netty.channel.ChannelHandler, org.jboss.netty.channel.ChannelUpstreamHandler
Direct Known Subclasses:
HttpContentCompressor

public abstract class HttpContentEncoder
extends org.jboss.netty.channel.SimpleChannelHandler

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(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(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(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.

Version:
$Rev: 1107 $, $Date: 2012-04-15 19:00:57 +0200 (dim., 15 avr. 2012) $
Author:
The Netty Project, Trustin Lee

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
org.jboss.netty.channel.ChannelHandler.Sharable
 
Constructor Summary
protected HttpContentEncoder()
          Creates a new instance.
 
Method Summary
protected abstract  String getTargetContentEncoding(String acceptEncoding)
          Returns the expected content encoding of the encoded content.
 void messageReceived(org.jboss.netty.channel.ChannelHandlerContext ctx, org.jboss.netty.channel.MessageEvent e)
           
protected abstract  org.jboss.netty.handler.codec.embedder.EncoderEmbedder<org.jboss.netty.buffer.ChannelBuffer> newContentEncoder(String acceptEncoding)
          Returns a new EncoderEmbedder that encodes the HTTP message content.
 void writeRequested(org.jboss.netty.channel.ChannelHandlerContext ctx, org.jboss.netty.channel.MessageEvent e)
           
 
Methods inherited from class org.jboss.netty.channel.SimpleChannelHandler
bindRequested, channelBound, channelClosed, channelConnected, channelDisconnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, closeRequested, connectRequested, disconnectRequested, exceptionCaught, handleDownstream, handleUpstream, setInterestOpsRequested, unbindRequested, writeComplete
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpContentEncoder

protected HttpContentEncoder()
Creates a new instance.

Method Detail

messageReceived

public void messageReceived(org.jboss.netty.channel.ChannelHandlerContext ctx,
                            org.jboss.netty.channel.MessageEvent e)
                     throws Exception
Overrides:
messageReceived in class org.jboss.netty.channel.SimpleChannelHandler
Throws:
Exception

writeRequested

public void writeRequested(org.jboss.netty.channel.ChannelHandlerContext ctx,
                           org.jboss.netty.channel.MessageEvent e)
                    throws Exception
Overrides:
writeRequested in class org.jboss.netty.channel.SimpleChannelHandler
Throws:
Exception

newContentEncoder

protected abstract org.jboss.netty.handler.codec.embedder.EncoderEmbedder<org.jboss.netty.buffer.ChannelBuffer> newContentEncoder(String acceptEncoding)
                                                                                                                           throws Exception
Returns a new EncoderEmbedder that encodes the HTTP message content.

Parameters:
acceptEncoding - the value of the "Accept-Encoding" header
Returns:
a new EncoderEmbedder if there is a supported encoding in acceptEncoding. null otherwise.
Throws:
Exception

getTargetContentEncoding

protected abstract String getTargetContentEncoding(String acceptEncoding)
                                            throws Exception
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


Copyright © 2009-2012 Frederic Bregier. All Rights Reserved.