org.glassfish.grizzly.http
Class HttpCodecFilter

java.lang.Object
  extended by org.glassfish.grizzly.filterchain.BaseFilter
      extended by org.glassfish.grizzly.http.HttpCodecFilter
All Implemented Interfaces:
Filter, JmxMonitoringAware<HttpProbe>, MonitoringAware<HttpProbe>
Direct Known Subclasses:
HttpClientFilter, HttpServerFilter

public abstract class HttpCodecFilter
extends BaseFilter
implements JmxMonitoringAware<HttpProbe>

The Filter, responsible for transforming Buffer into HttpPacket and vice versa in asynchronous mode. When the HttpCodecFilter is added to a FilterChain, on read phase it consumes incoming Buffer and provides HttpContent as the result of transformation. On write phase the HttpCodecFilter consumes input HttpPacket and serializes it to a Buffer, which gets passed farther as the result of transformation. So transformations, provided by this filter are following: (read phase): Buffer -> HttpContent (write phase): HttpPacket -> Buffer.

Author:
Alexey Stashok
See Also:
HttpServerFilter, HttpClientFilter

Nested Class Summary
static class HttpCodecFilter.ContentParsingState
           
static class HttpCodecFilter.HeaderParsingState
           
 
Field Summary
protected  boolean chunkingEnabled
           
protected  ArraySet<ContentEncoding> contentEncodings
           
static int DEFAULT_MAX_HTTP_PACKET_HEADER_SIZE
           
protected static CompletionHandler<WriteResult> FLUSH_AND_CLOSE_HANDLER
           
protected  int maxHeadersSize
           
protected  AbstractJmxMonitoringConfig<HttpProbe> monitoringConfig
          File cache probes
 
Constructor Summary
HttpCodecFilter(boolean chunkingEnabled, int maxHeadersSize)
          Constructor, which creates HttpCodecFilter instance, with the specific max header size parameter.
 
Method Summary
 void addContentEncoding(ContentEncoding contentEncoding)
           Adds the specified ContentEncoding to the HttpCodecFilter.
 void addTransferEncoding(TransferEncoding transferEncoding)
           Adds the specified TransferEncoding to the HttpCodecFilter.
protected  JmxObject createJmxManagementObject()
           
protected  boolean decodeHttpPacket(FilterChainContext ctx, HttpPacketParsing httpPacket, Buffer input)
           
protected  boolean decodeHttpPacketFromBuffer(FilterChainContext ctx, HttpPacketParsing httpPacket, Buffer input)
           
protected  boolean decodeHttpPacketFromBytes(FilterChainContext ctx, HttpPacketParsing httpPacket, Buffer inputBuffer)
           
protected  Buffer encodeHttpPacket(FilterChainContext ctx, HttpHeader httpHeader, HttpContent httpContent, boolean isContentAlreadyEncoded)
           
protected  Buffer encodeHttpPacket(FilterChainContext ctx, HttpPacket input)
           
protected static Buffer encodeKnownHeaders(MemoryManager memoryManager, Buffer buffer, HttpHeader httpHeader)
           
protected static Buffer encodeMimeHeader(MemoryManager memoryManager, Buffer buffer, DataChunk name, DataChunk value, boolean encodeLastCRLF)
           
protected static Buffer encodeMimeHeaders(MemoryManager memoryManager, Buffer buffer, MimeHeaders mimeHeaders)
           
protected static void flushAndClose(FilterChainContext ctx)
          Flush the FilterChainContext and close the associated Connection.
 ContentEncoding[] getContentEncodings()
           Gets registered ContentEncodings.
 JmxMonitoringConfig<HttpProbe> getMonitoringConfig()
          
 TransferEncoding[] getTransferEncodings()
           Gets registered TransferEncodings.
 NextAction handleRead(FilterChainContext ctx, HttpPacketParsing httpPacket)
          The method is called by the specific HttpCodecFilter implementation, once we have received a Buffer, which has to be transformed into HTTP packet part.
 NextAction handleWrite(FilterChainContext ctx)
          The method is called, once we need to serialize a HttpPacket, which may represent HTTP packet header, content or content chunk.
protected  boolean isChunkingEnabled()
          Return true if chunked transfer-encoding may be used.
protected static boolean isSecure(Connection connection)
          flag, which indicates whether this HttpCodecFilter is dealing with the secured HTTP packets.
protected abstract  void onHttpContentEncoded(HttpContent content, FilterChainContext ctx)
           Invoked when a HTTP body chunk has been encoded in preparation to being transmitted to the user-agent.
protected abstract  void onHttpContentError(HttpHeader httpHeader, FilterChainContext ctx, Throwable t)
           Callback which is invoked when parsing an HTTP message payload fails.
protected abstract  void onHttpContentParsed(HttpContent content, FilterChainContext ctx)
           Invoked as request/response body content has been processed by this Filter.
protected abstract  void onHttpHeaderError(HttpHeader httpHeader, FilterChainContext ctx, Throwable t)
           Callback which is invoked when parsing an HTTP message header fails.
protected abstract  boolean onHttpHeaderParsed(HttpHeader httpHeader, Buffer buffer, FilterChainContext ctx)
          Callback invoked when the HTTP message header parsing is complete.
protected abstract  void onHttpHeadersEncoded(HttpHeader httpHeader, FilterChainContext ctx)
           Invoked when HTTP headers have been encoded in preparation to being transmitted to the user-agent.
protected abstract  void onHttpHeadersParsed(HttpHeader httpHeader, FilterChainContext ctx)
           Invoked when all headers of the packet have been parsed.
protected abstract  boolean onHttpPacketParsed(HttpHeader httpHeader, FilterChainContext ctx)
          Callback method, called when HttpPacket parsing has been completed.
protected abstract  void onInitialLineEncoded(HttpHeader httpHeader, FilterChainContext ctx)
           Invoked when the intial response line has been encoded in preparation to being transmitted to the user-agent.
protected abstract  void onInitialLineParsed(HttpHeader httpHeader, FilterChainContext ctx)
           Invoked when either the request line or status line has been parsed.
protected static boolean parseHeaderFromBuffer(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, Buffer input)
           
protected static boolean parseHeaderFromBytes(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, byte[] input, int end)
           
protected static boolean parseHeaderName(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, Buffer input)
           
protected static boolean parseHeaderName(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, byte[] input, int end)
           
protected  boolean parseHeadersFromBuffer(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, Buffer input)
           
protected  boolean parseHeadersFromBytes(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, byte[] input, int end)
           
protected static int parseHeaderValue(HttpHeader httpHeader, HttpCodecFilter.HeaderParsingState parsingState, Buffer input)
           
protected static int parseHeaderValue(HttpHeader httpHeader, HttpCodecFilter.HeaderParsingState parsingState, byte[] input, int end)
           
 boolean removeContentEncoding(ContentEncoding contentEncoding)
           Removes the specified ContentEncoding from the HttpCodecFilter.
 boolean removeTransferEncoding(TransferEncoding transferEncoding)
           Removes the specified TransferEncoding from the HttpCodecFilter.
 
Methods inherited from class org.glassfish.grizzly.filterchain.BaseFilter
createContext, exceptionOccurred, getFilterChain, getIndex, handleAccept, handleClose, handleConnect, handleEvent, handleRead, onAdded, onFilterChainChanged, onRemoved
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAX_HTTP_PACKET_HEADER_SIZE

public static final int DEFAULT_MAX_HTTP_PACKET_HEADER_SIZE
See Also:
Constant Field Values

FLUSH_AND_CLOSE_HANDLER

protected static final CompletionHandler<WriteResult> FLUSH_AND_CLOSE_HANDLER

contentEncodings

protected final ArraySet<ContentEncoding> contentEncodings

chunkingEnabled

protected final boolean chunkingEnabled

monitoringConfig

protected final AbstractJmxMonitoringConfig<HttpProbe> monitoringConfig
File cache probes


maxHeadersSize

protected final int maxHeadersSize
Constructor Detail

HttpCodecFilter

public HttpCodecFilter(boolean chunkingEnabled,
                       int maxHeadersSize)
Constructor, which creates HttpCodecFilter instance, with the specific max header size parameter.

Parameters:
chunkingEnabled - true if the chunked transfer encoding should be used when no explicit content length has been set.
maxHeadersSize - the maximum size of the HTTP message header.
Method Detail

onHttpPacketParsed

protected abstract boolean onHttpPacketParsed(HttpHeader httpHeader,
                                              FilterChainContext ctx)
Callback method, called when HttpPacket parsing has been completed.

Parameters:
httpHeader - HttpHeader, which represents parsed HTTP packet header
ctx - processing context.
Returns:
true if an error has occurred while processing the header portion of the HTTP request, otherwise returns false.s

onHttpHeaderParsed

protected abstract boolean onHttpHeaderParsed(HttpHeader httpHeader,
                                              Buffer buffer,
                                              FilterChainContext ctx)
Callback invoked when the HTTP message header parsing is complete.

Parameters:
httpHeader - HttpHeader, which represents parsed HTTP packet header
buffer - Buffer the header was parsed from
ctx - processing context.
Returns:
true if an error has occurred while processing the header portion of the HTTP request, otherwise returns false.

onInitialLineParsed

protected abstract void onInitialLineParsed(HttpHeader httpHeader,
                                            FilterChainContext ctx)

Invoked when either the request line or status line has been parsed.

Parameters:
httpHeader - HttpHeader, which represents HTTP packet header
ctx - processing context.

onInitialLineEncoded

protected abstract void onInitialLineEncoded(HttpHeader httpHeader,
                                             FilterChainContext ctx)

Invoked when the intial response line has been encoded in preparation to being transmitted to the user-agent.

Parameters:
httpHeader - HttpHeader, which represents HTTP packet header
ctx - processing context.
Since:
2.1.2

onHttpHeadersParsed

protected abstract void onHttpHeadersParsed(HttpHeader httpHeader,
                                            FilterChainContext ctx)

Invoked when all headers of the packet have been parsed. Depending on the transfer encoding being used by the current request, this method may be invoked multiple times.

Parameters:
httpHeader - HttpHeader, which represents HTTP packet header
ctx - processing context.

onHttpHeadersEncoded

protected abstract void onHttpHeadersEncoded(HttpHeader httpHeader,
                                             FilterChainContext ctx)

Invoked when HTTP headers have been encoded in preparation to being transmitted to the user-agent.

Parameters:
httpHeader - HttpHeader, which represents HTTP packet header
ctx - processing context.
Since:
2.1.2

onHttpContentParsed

protected abstract void onHttpContentParsed(HttpContent content,
                                            FilterChainContext ctx)

Invoked as request/response body content has been processed by this Filter.

Parameters:
content - request/response body content
ctx - processing context.

onHttpContentEncoded

protected abstract void onHttpContentEncoded(HttpContent content,
                                             FilterChainContext ctx)

Invoked when a HTTP body chunk has been encoded in preparation to being transmitted to the user-agent.

Parameters:
content - HttpContent, which represents HTTP packet header
ctx - processing context.
Since:
2.1.2

onHttpHeaderError

protected abstract void onHttpHeaderError(HttpHeader httpHeader,
                                          FilterChainContext ctx,
                                          Throwable t)
                                   throws IOException

Callback which is invoked when parsing an HTTP message header fails. The processing logic has to take care about error handling and following connection closing.

Parameters:
httpHeader - HttpHeader, which represents HTTP packet header
ctx - the FilterChainContext processing this request
t - the cause of the error
Throws:
IOException

onHttpContentError

protected abstract void onHttpContentError(HttpHeader httpHeader,
                                           FilterChainContext ctx,
                                           Throwable t)
                                    throws IOException

Callback which is invoked when parsing an HTTP message payload fails. The processing logic has to take care about error handling and following connection closing.

Parameters:
httpHeader - HttpHeader, which represents HTTP packet header
ctx - the FilterChainContext processing this request
t - the cause of the error
Throws:
IOException

getTransferEncodings

public TransferEncoding[] getTransferEncodings()

Gets registered TransferEncodings.

Returns:
registered TransferEncodings.

addTransferEncoding

public void addTransferEncoding(TransferEncoding transferEncoding)

Adds the specified TransferEncoding to the HttpCodecFilter.

Parameters:
transferEncoding - the TransferEncoding to add

removeTransferEncoding

public boolean removeTransferEncoding(TransferEncoding transferEncoding)

Removes the specified TransferEncoding from the HttpCodecFilter.

Parameters:
transferEncoding - the TransferEncoding to remove
Returns:
true if the TransferEncoding was removed, otherwise false indicating the TransferEncoding was not already present

getContentEncodings

public ContentEncoding[] getContentEncodings()

Gets registered ContentEncodings.

Returns:
registered ContentEncodings.

addContentEncoding

public void addContentEncoding(ContentEncoding contentEncoding)

Adds the specified ContentEncoding to the HttpCodecFilter.

Parameters:
contentEncoding - the ContentEncoding to add

removeContentEncoding

public boolean removeContentEncoding(ContentEncoding contentEncoding)

Removes the specified ContentEncoding from the HttpCodecFilter.

Parameters:
contentEncoding - the ContentEncoding to remove
Returns:
true if the ContentEncoding was removed, otherwise false indicating the ContentEncoding was not already present

isChunkingEnabled

protected boolean isChunkingEnabled()
Return true if chunked transfer-encoding may be used.

Returns:
true if chunked transfer-encoding may be used.
Since:
2.1.2

handleRead

public final NextAction handleRead(FilterChainContext ctx,
                                   HttpPacketParsing httpPacket)
                            throws IOException
The method is called by the specific HttpCodecFilter implementation, once we have received a Buffer, which has to be transformed into HTTP packet part. Filter gets Buffer, which represents a part or complete HTTP message. As the result of "read" transformation - we will get HttpContent message, which will represent HTTP packet content (might be zero length content) and reference to a HttpHeader, which contains HTTP message header.

Parameters:
ctx - Request processing context
httpPacket - the current HttpPacket, which is being processed.
Returns:
NextAction
Throws:
IOException

decodeHttpPacket

protected boolean decodeHttpPacket(FilterChainContext ctx,
                                   HttpPacketParsing httpPacket,
                                   Buffer input)

decodeHttpPacketFromBytes

protected boolean decodeHttpPacketFromBytes(FilterChainContext ctx,
                                            HttpPacketParsing httpPacket,
                                            Buffer inputBuffer)

parseHeadersFromBytes

protected boolean parseHeadersFromBytes(HttpHeader httpHeader,
                                        MimeHeaders mimeHeaders,
                                        HttpCodecFilter.HeaderParsingState parsingState,
                                        byte[] input,
                                        int end)

parseHeaderFromBytes

protected static boolean parseHeaderFromBytes(HttpHeader httpHeader,
                                              MimeHeaders mimeHeaders,
                                              HttpCodecFilter.HeaderParsingState parsingState,
                                              byte[] input,
                                              int end)

parseHeaderName

protected static boolean parseHeaderName(HttpHeader httpHeader,
                                         MimeHeaders mimeHeaders,
                                         HttpCodecFilter.HeaderParsingState parsingState,
                                         byte[] input,
                                         int end)

parseHeaderValue

protected static int parseHeaderValue(HttpHeader httpHeader,
                                      HttpCodecFilter.HeaderParsingState parsingState,
                                      byte[] input,
                                      int end)

decodeHttpPacketFromBuffer

protected boolean decodeHttpPacketFromBuffer(FilterChainContext ctx,
                                             HttpPacketParsing httpPacket,
                                             Buffer input)

parseHeadersFromBuffer

protected boolean parseHeadersFromBuffer(HttpHeader httpHeader,
                                         MimeHeaders mimeHeaders,
                                         HttpCodecFilter.HeaderParsingState parsingState,
                                         Buffer input)

parseHeaderFromBuffer

protected static boolean parseHeaderFromBuffer(HttpHeader httpHeader,
                                               MimeHeaders mimeHeaders,
                                               HttpCodecFilter.HeaderParsingState parsingState,
                                               Buffer input)

parseHeaderName

protected static boolean parseHeaderName(HttpHeader httpHeader,
                                         MimeHeaders mimeHeaders,
                                         HttpCodecFilter.HeaderParsingState parsingState,
                                         Buffer input)

parseHeaderValue

protected static int parseHeaderValue(HttpHeader httpHeader,
                                      HttpCodecFilter.HeaderParsingState parsingState,
                                      Buffer input)

handleWrite

public NextAction handleWrite(FilterChainContext ctx)
                       throws IOException
The method is called, once we need to serialize a HttpPacket, which may represent HTTP packet header, content or content chunk. Filter gets HttpPacket, which represents a HTTP header, content, or content part. As the result of "write" transformation - we will get Buffer, which will represent serialized HTTP packet.

Specified by:
handleWrite in interface Filter
Overrides:
handleWrite in class BaseFilter
Parameters:
ctx - Request processing context
Returns:
NextAction
Throws:
IOException

encodeHttpPacket

protected Buffer encodeHttpPacket(FilterChainContext ctx,
                                  HttpPacket input)

encodeHttpPacket

protected final Buffer encodeHttpPacket(FilterChainContext ctx,
                                        HttpHeader httpHeader,
                                        HttpContent httpContent,
                                        boolean isContentAlreadyEncoded)

encodeKnownHeaders

protected static Buffer encodeKnownHeaders(MemoryManager memoryManager,
                                           Buffer buffer,
                                           HttpHeader httpHeader)

encodeMimeHeaders

protected static Buffer encodeMimeHeaders(MemoryManager memoryManager,
                                          Buffer buffer,
                                          MimeHeaders mimeHeaders)

encodeMimeHeader

protected static Buffer encodeMimeHeader(MemoryManager memoryManager,
                                         Buffer buffer,
                                         DataChunk name,
                                         DataChunk value,
                                         boolean encodeLastCRLF)

isSecure

protected static boolean isSecure(Connection connection)
flag, which indicates whether this HttpCodecFilter is dealing with the secured HTTP packets. For this filter flag means nothing, it's just a value, which is getting set to a HttpRequestPacket or HttpResponsePacket.


flushAndClose

protected static void flushAndClose(FilterChainContext ctx)
                             throws IOException
Flush the FilterChainContext and close the associated Connection.

Throws:
IOException

getMonitoringConfig

public JmxMonitoringConfig<HttpProbe> getMonitoringConfig()

Specified by:
getMonitoringConfig in interface JmxMonitoringAware<HttpProbe>
Specified by:
getMonitoringConfig in interface MonitoringAware<HttpProbe>

createJmxManagementObject

protected JmxObject createJmxManagementObject()


Copyright © 2012 Oracle Corporation. All Rights Reserved.