org.glassfish.grizzly.http
Class HttpClientFilter

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

public class HttpClientFilter
extends HttpCodecFilter

Client side HttpCodecFilter implementation, which is responsible for decoding HttpResponsePacket and encoding HttpRequestPacket messages. This Filter is usually used, when we build an asynchronous HTTP client connection.

Author:
Alexey Stashok
See Also:
HttpCodecFilter, HttpServerFilter

Nested Class Summary
 
Nested classes/interfaces inherited from class org.glassfish.grizzly.http.HttpCodecFilter
HttpCodecFilter.ContentParsingState, HttpCodecFilter.HeaderParsingState
 
Field Summary
 
Fields inherited from class org.glassfish.grizzly.http.HttpCodecFilter
chunkingEnabled, contentEncodings, DEFAULT_MAX_HTTP_PACKET_HEADER_SIZE, FLUSH_AND_CLOSE_HANDLER, maxHeadersSize, monitoringConfig
 
Constructor Summary
HttpClientFilter()
          Constructor, which creates HttpClientFilter instance
HttpClientFilter(int maxHeadersSize)
          Constructor, which creates HttpClientFilter instance, with the specific secure and max header size parameter.
 
Method Summary
protected  void clearResponse(Connection connection)
           
protected  Buffer encodeHttpPacket(FilterChainContext ctx, HttpPacket input)
           
 NextAction handleRead(FilterChainContext ctx)
          The method is called, once we have received a Buffer, which has to be transformed into HTTP response 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  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  void onHttpContentError(HttpHeader httpHeader, FilterChainContext ctx, Throwable t)
           Callback which is invoked when parsing an HTTP message payload fails.
protected  void onHttpContentParsed(HttpContent content, FilterChainContext ctx)
           Invoked as request/response body content has been processed by this Filter.
protected  void onHttpHeaderError(HttpHeader httpHeader, FilterChainContext ctx, Throwable t)
           Callback which is invoked when parsing an HTTP message header fails.
protected  boolean onHttpHeaderParsed(HttpHeader httpHeader, Buffer buffer, FilterChainContext ctx)
          Callback invoked when the HTTP message header parsing is complete.
protected  void onHttpHeadersEncoded(HttpHeader httpHeader, FilterChainContext ctx)
           Invoked when HTTP headers have been encoded in preparation to being transmitted to the user-agent.
protected  void onHttpHeadersParsed(HttpHeader httpHeader, FilterChainContext ctx)
           Invoked when all headers of the packet have been parsed.
protected  boolean onHttpPacketParsed(HttpHeader httpHeader, FilterChainContext ctx)
          Callback method, called when HttpPacket parsing has been completed.
protected  void onInitialLineEncoded(HttpHeader header, FilterChainContext ctx)
           Invoked when the intial response line has been encoded in preparation to being transmitted to the user-agent.
protected  void onInitialLineParsed(HttpHeader httpHeader, FilterChainContext ctx)
           Invoked when either the request line or status line has been parsed.
 
Methods inherited from class org.glassfish.grizzly.http.HttpCodecFilter
addContentEncoding, addTransferEncoding, createJmxManagementObject, decodeHttpPacket, decodeHttpPacketFromBuffer, decodeHttpPacketFromBytes, encodeHttpPacket, encodeKnownHeaders, encodeMimeHeader, encodeMimeHeaders, flushAndClose, getContentEncodings, getMonitoringConfig, getTransferEncodings, handleRead, isChunkingEnabled, isSecure, parseHeaderFromBuffer, parseHeaderFromBytes, parseHeaderName, parseHeaderName, parseHeadersFromBuffer, parseHeadersFromBytes, parseHeaderValue, parseHeaderValue, removeContentEncoding, removeTransferEncoding
 
Methods inherited from class org.glassfish.grizzly.filterchain.BaseFilter
createContext, exceptionOccurred, getFilterChain, getIndex, handleAccept, handleClose, handleConnect, handleEvent, onAdded, onFilterChainChanged, onRemoved
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpClientFilter

public HttpClientFilter()
Constructor, which creates HttpClientFilter instance


HttpClientFilter

public HttpClientFilter(int maxHeadersSize)
Constructor, which creates HttpClientFilter instance, with the specific secure and max header size parameter.

Parameters:
maxHeadersSize - the maximum size of the HTTP message header.
Method Detail

handleWrite

public NextAction handleWrite(FilterChainContext ctx)
                       throws IOException
Description copied from class: HttpCodecFilter
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 HttpCodecFilter
Parameters:
ctx - Request processing context
Returns:
NextAction
Throws:
IOException

handleRead

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

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

onHttpPacketParsed

protected boolean onHttpPacketParsed(HttpHeader httpHeader,
                                     FilterChainContext ctx)
Description copied from class: HttpCodecFilter
Callback method, called when HttpPacket parsing has been completed.

Specified by:
onHttpPacketParsed in class HttpCodecFilter
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 boolean onHttpHeaderParsed(HttpHeader httpHeader,
                                     Buffer buffer,
                                     FilterChainContext ctx)
Description copied from class: HttpCodecFilter
Callback invoked when the HTTP message header parsing is complete.

Specified by:
onHttpHeaderParsed in class HttpCodecFilter
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.

onHttpHeaderError

protected void onHttpHeaderError(HttpHeader httpHeader,
                                 FilterChainContext ctx,
                                 Throwable t)
                          throws IOException
Description copied from class: HttpCodecFilter

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.

Specified by:
onHttpHeaderError in class HttpCodecFilter
Parameters:
httpHeader - HttpHeader, which represents HTTP packet header
ctx - the FilterChainContext processing this request
t - the cause of the error
Throws:
IOException

onHttpContentError

protected void onHttpContentError(HttpHeader httpHeader,
                                  FilterChainContext ctx,
                                  Throwable t)
                           throws IOException
Description copied from class: HttpCodecFilter

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.

Specified by:
onHttpContentError in class HttpCodecFilter
Parameters:
httpHeader - HttpHeader, which represents HTTP packet header
ctx - the FilterChainContext processing this request
t - the cause of the error
Throws:
IOException

onInitialLineParsed

protected void onInitialLineParsed(HttpHeader httpHeader,
                                   FilterChainContext ctx)
Description copied from class: HttpCodecFilter

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

Specified by:
onInitialLineParsed in class HttpCodecFilter
Parameters:
httpHeader - HttpHeader, which represents HTTP packet header
ctx - processing context.

onInitialLineEncoded

protected void onInitialLineEncoded(HttpHeader header,
                                    FilterChainContext ctx)
Description copied from class: HttpCodecFilter

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

Specified by:
onInitialLineEncoded in class HttpCodecFilter
Parameters:
header - HttpHeader, which represents HTTP packet header
ctx - processing context.

onHttpHeadersParsed

protected void onHttpHeadersParsed(HttpHeader httpHeader,
                                   FilterChainContext ctx)
Description copied from class: HttpCodecFilter

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.

Specified by:
onHttpHeadersParsed in class HttpCodecFilter
Parameters:
httpHeader - HttpHeader, which represents HTTP packet header
ctx - processing context.

onHttpHeadersEncoded

protected void onHttpHeadersEncoded(HttpHeader httpHeader,
                                    FilterChainContext ctx)
Description copied from class: HttpCodecFilter

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

Specified by:
onHttpHeadersEncoded in class HttpCodecFilter
Parameters:
httpHeader - HttpHeader, which represents HTTP packet header
ctx - processing context.

onHttpContentParsed

protected void onHttpContentParsed(HttpContent content,
                                   FilterChainContext ctx)
Description copied from class: HttpCodecFilter

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

Specified by:
onHttpContentParsed in class HttpCodecFilter
Parameters:
content - request/response body content
ctx - processing context.

onHttpContentEncoded

protected void onHttpContentEncoded(HttpContent content,
                                    FilterChainContext ctx)
Description copied from class: HttpCodecFilter

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

Specified by:
onHttpContentEncoded in class HttpCodecFilter
Parameters:
content - HttpContent, which represents HTTP packet header
ctx - processing context.

clearResponse

protected final void clearResponse(Connection connection)

encodeHttpPacket

protected Buffer encodeHttpPacket(FilterChainContext ctx,
                                  HttpPacket input)
Overrides:
encodeHttpPacket in class HttpCodecFilter


Copyright © 2012 Oracle Corporation. All Rights Reserved.