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
protected static class HttpCodecFilter.ContentParsingState
           
protected static class HttpCodecFilter.HeaderParsingState
           
 
Field Summary
protected  boolean chunkingEnabled
           
protected  ArraySet<ContentEncoding> contentEncodings
           
static int DEFAULT_MAX_HTTP_PACKET_HEADER_SIZE
           
protected  boolean isSecure
          flag, which indicates whether this HttpCodecFilter is dealing with the secured HTTP packets.
protected  int maxHeadersSize
           
protected  AbstractJmxMonitoringConfig<HttpProbe> monitoringConfig
          File cache probes
 
Constructor Summary
HttpCodecFilter(Boolean isSecure, 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  void autoDetectSecure(FilterChain filterChain)
          Autodetect whether we will deal with HTTP or HTTPS by trying to find SSLFilter in the FilterChain.
protected static int checkEOL(HttpCodecFilter.HeaderParsingState parsingState, Buffer input)
           
protected  JmxObject createJmxManagementObject()
           
protected  boolean decodeHttpPacket(HttpPacketParsing httpPacket, Buffer input)
           
protected  Buffer encodeHttpPacket(Connection connection, HttpPacket input)
           
protected  Buffer encodeKnownHeaders(MemoryManager memoryManager, Buffer buffer, HttpHeader httpHeader)
           
protected static Buffer encodeMimeHeader(MemoryManager memoryManager, Buffer buffer, BufferChunk name, BufferChunk value, boolean encodeLastCRLF)
           
protected static Buffer encodeMimeHeaders(MemoryManager memoryManager, Buffer buffer, MimeHeaders mimeHeaders)
           
protected static boolean findEOL(HttpCodecFilter.HeaderParsingState state, Buffer input)
           
protected static int findSpace(Buffer input, int offset, int packetLimit)
           
 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 static int indexOf(Buffer input, int offset, byte b, int packetLimit)
           
 void onAdded(FilterChain filterChain)
          
 void onFilterChainChanged(FilterChain filterChain)
          
protected static boolean parseHeader(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, Buffer input)
           
protected static boolean parseHeaderName(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, Buffer input)
           
protected static boolean parseHeaders(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, Buffer input)
           
protected static int parseHeaderValue(HttpHeader httpHeader, HttpCodecFilter.HeaderParsingState parsingState, Buffer input)
           
protected static Buffer put(MemoryManager memoryManager, Buffer dstBuffer, BufferChunk chunk)
           
protected static Buffer put(MemoryManager memoryManager, Buffer headerBuffer, byte value)
           
protected static Buffer put(MemoryManager memoryManager, Buffer headerBuffer, byte[] array)
           
protected static Buffer put(MemoryManager memoryManager, Buffer dstBuffer, String s)
           
 boolean removeContentEncoding(ContentEncoding contentEncoding)
           Removes the specified ContentEncoding from the HttpCodecFilter.
 boolean removeTransferEncoding(TransferEncoding transferEncoding)
           Removes the specified TransferEncoding from the HttpCodecFilter.
protected static Buffer resizeBuffer(MemoryManager memoryManager, Buffer headerBuffer, int grow)
           
protected static int skipSpaces(Buffer input, int offset, int packetLimit)
           
 
Methods inherited from class org.glassfish.grizzly.filterchain.BaseFilter
createContext, exceptionOccurred, getFilterChain, getIndex, handleAccept, handleClose, handleConnect, handleEvent, handleRead, 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

contentEncodings

protected final ArraySet<ContentEncoding> contentEncodings

chunkingEnabled

protected boolean chunkingEnabled

monitoringConfig

protected final AbstractJmxMonitoringConfig<HttpProbe> monitoringConfig
File cache probes


isSecure

protected volatile boolean isSecure
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.


maxHeadersSize

protected final int maxHeadersSize
Constructor Detail

HttpCodecFilter

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

Parameters:
isSecure - true, if the Filter will be used for secured HTTPS communication, or false otherwise. It's possible to pass null, in this case Filter will try to autodetect security.
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

onAdded

public void onAdded(FilterChain filterChain)

Specified by:
onAdded in interface Filter
Overrides:
onAdded in class BaseFilter

onFilterChainChanged

public void onFilterChainChanged(FilterChain filterChain)

Specified by:
onFilterChainChanged in interface Filter
Overrides:
onFilterChainChanged in class BaseFilter

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

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

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

decodeHttpPacket

protected boolean decodeHttpPacket(HttpPacketParsing httpPacket,
                                   Buffer input)

encodeHttpPacket

protected Buffer encodeHttpPacket(Connection connection,
                                  HttpPacket input)

encodeKnownHeaders

protected 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,
                                         BufferChunk name,
                                         BufferChunk value,
                                         boolean encodeLastCRLF)

parseHeaders

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

parseHeader

protected static boolean parseHeader(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)

checkEOL

protected static int checkEOL(HttpCodecFilter.HeaderParsingState parsingState,
                              Buffer input)

findEOL

protected static boolean findEOL(HttpCodecFilter.HeaderParsingState state,
                                 Buffer input)

findSpace

protected static int findSpace(Buffer input,
                               int offset,
                               int packetLimit)

skipSpaces

protected static int skipSpaces(Buffer input,
                                int offset,
                                int packetLimit)

indexOf

protected static int indexOf(Buffer input,
                             int offset,
                             byte b,
                             int packetLimit)

put

protected static Buffer put(MemoryManager memoryManager,
                            Buffer dstBuffer,
                            BufferChunk chunk)

put

protected static Buffer put(MemoryManager memoryManager,
                            Buffer dstBuffer,
                            String s)

put

protected static Buffer put(MemoryManager memoryManager,
                            Buffer headerBuffer,
                            byte[] array)

put

protected static Buffer put(MemoryManager memoryManager,
                            Buffer headerBuffer,
                            byte value)

resizeBuffer

protected static Buffer resizeBuffer(MemoryManager memoryManager,
                                     Buffer headerBuffer,
                                     int grow)

autoDetectSecure

protected void autoDetectSecure(FilterChain filterChain)
Autodetect whether we will deal with HTTP or HTTPS by trying to find SSLFilter in the FilterChain.

Parameters:
filterChain - FilterChain

getMonitoringConfig

public JmxMonitoringConfig<HttpProbe> getMonitoringConfig()

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

createJmxManagementObject

protected JmxObject createJmxManagementObject()


Copyright © 2010 Oracle Corpration. All Rights Reserved.