Class HttpServerFilter

java.lang.Object
org.glassfish.grizzly.filterchain.BaseFilter
All Implemented Interfaces:
org.glassfish.grizzly.filterchain.Filter, org.glassfish.grizzly.monitoring.MonitoringAware<HttpProbe>

public class HttpServerFilter extends HttpCodecFilter
Server side HttpCodecFilter implementation, which is responsible for decoding HttpRequestPacket and encoding HttpResponsePacket messages. This Filter is usually used, when we build an asynchronous HTTP server connection.
Author:
Alexey Stashok
See Also:
  • Field Details

    • HTTP_SERVER_REQUEST_ATTR_NAME

      public static final String HTTP_SERVER_REQUEST_ATTR_NAME
    • RESPONSE_COMPLETE_EVENT

      public static final org.glassfish.grizzly.filterchain.FilterChainEvent RESPONSE_COMPLETE_EVENT
  • Constructor Details

    • HttpServerFilter

      @Deprecated public HttpServerFilter()
      Deprecated.
      Next major release will include builders for filters requiring configuration. Constructors will be hidden.
      Constructor, which creates HttpServerFilter instance
    • HttpServerFilter

      @Deprecated public HttpServerFilter(boolean chunkingEnabled, int maxHeadersSize, KeepAlive keepAlive, org.glassfish.grizzly.utils.DelayedExecutor executor)
      Deprecated.
      Next major release will include builders for filters requiring configuration. Constructors will be hidden.
      Constructor, which creates HttpServerFilter instance, with the specific max header size parameter.
      Parameters:
      chunkingEnabled - flag indicating whether or not chunking should be allowed or not.
      maxHeadersSize - the maximum size of an inbound HTTP message header.
      keepAlive - keep-alive configuration for this filter instance.
      executor - DelayedExecutor for handling keep-alive.
    • HttpServerFilter

      @Deprecated public HttpServerFilter(boolean chunkingEnabled, int maxHeadersSize, String defaultResponseContentType, KeepAlive keepAlive, org.glassfish.grizzly.utils.DelayedExecutor executor)
      Deprecated.
      Next major release will include builders for filters requiring configuration. Constructors will be hidden.
      Constructor, which creates HttpServerFilter instance, with the specific max header size parameter.
      Parameters:
      chunkingEnabled - flag indicating whether or not chunking should be allowed or not.
      maxHeadersSize - the maximum size of an inbound HTTP message header.
      defaultResponseContentType - the content type that the response should use if no content had been specified at the time the response is committed.
      keepAlive - keep-alive configuration for this filter instance.
      executor - DelayedExecutor for handling keep-alive. If null - keep-alive idle connections should be managed outside HttpServerFilter.
    • HttpServerFilter

      @Deprecated public HttpServerFilter(boolean chunkingEnabled, int maxHeadersSize, String defaultResponseContentType, KeepAlive keepAlive, org.glassfish.grizzly.utils.DelayedExecutor executor, int maxRequestHeaders, int maxResponseHeaders)
      Deprecated.
      Next major release will include builders for filters requiring configuration. Constructors will be hidden.
      Constructor, which creates HttpServerFilter instance, with the specific max header size parameter.
      Parameters:
      chunkingEnabled - flag indicating whether or not chunking should be allowed or not.
      maxHeadersSize - the maximum size of an inbound HTTP message header.
      defaultResponseContentType - the content type that the response should use if no content had been specified at the time the response is committed.
      keepAlive - keep-alive configuration for this filter instance.
      executor - DelayedExecutor for handling keep-alive. If null - keep-alive idle connections should be managed outside HttpServerFilter.
      maxRequestHeaders - maximum number of request headers allowed for a single request.
      maxResponseHeaders - maximum number of response headers allowed for a single response.
      Since:
      2.2.11
  • Method Details

    • getDefaultResponseContentType

      public String getDefaultResponseContentType()
    • setDefaultResponseContentType

      public final void setDefaultResponseContentType(String contentType)
    • isAllowPayloadForUndefinedHttpMethods

      public boolean isAllowPayloadForUndefinedHttpMethods()
      The flag, which enables/disables payload support for HTTP methods, for which HTTP spec doesn't clearly state whether they support payload. Known "undefined" methods are: GET, HEAD, DELETE.
      Returns:
      true if "undefined" methods support payload, or false otherwise
      Since:
      2.3.12
    • setAllowPayloadForUndefinedHttpMethods

      public void setAllowPayloadForUndefinedHttpMethods(boolean allowPayloadForUndefinedHttpMethods)
      The flag, which enables/disables payload support for HTTP methods, for which HTTP spec doesn't clearly state whether they support payload. Known "undefined" methods are: GET, HEAD, DELETE.
      Parameters:
      allowPayloadForUndefinedHttpMethods - true if "undefined" methods support payload, or false otherwise
      Since:
      2.3.12
    • handleRead

      public org.glassfish.grizzly.filterchain.NextAction handleRead(org.glassfish.grizzly.filterchain.FilterChainContext ctx) throws IOException
      The method is called, once we have received a Buffer, which has to be transformed into HTTP request packet part. Filter gets Buffer, which represents a part or complete HTTP request message. As the result of "read" transformation - we will get HttpContent message, which will represent HTTP request packet content (might be zero length content) and reference to a HttpHeader, which contains HTTP request message header.
      Specified by:
      handleRead in interface org.glassfish.grizzly.filterchain.Filter
      Overrides:
      handleRead in class org.glassfish.grizzly.filterchain.BaseFilter
      Parameters:
      ctx - Request processing context
      Returns:
      NextAction
      Throws:
      IOException
    • onHttpHeaderParsed

      protected boolean onHttpHeaderParsed(HttpHeader httpHeader, org.glassfish.grizzly.Buffer buffer, org.glassfish.grizzly.filterchain.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.
    • onHttpPacketParsed

      protected final boolean onHttpPacketParsed(HttpHeader httpHeader, org.glassfish.grizzly.filterchain.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
    • onInitialLineParsed

      protected void onInitialLineParsed(HttpHeader httpHeader, org.glassfish.grizzly.filterchain.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.
    • onHttpHeadersParsed

      protected void onHttpHeadersParsed(HttpHeader httpHeader, MimeHeaders headers, org.glassfish.grizzly.filterchain.FilterChainContext ctx)
      Description copied from class: HttpCodecFilter

      Invoked when HTTP headers portion comes for HttpHeader message. 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
      headers - the headers portion, that has been parsed
      ctx - processing context.
    • onHttpContentParsed

      protected void onHttpContentParsed(HttpContent content, org.glassfish.grizzly.filterchain.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.
    • onHttpHeaderError

      protected void onHttpHeaderError(HttpHeader httpHeader, org.glassfish.grizzly.filterchain.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, org.glassfish.grizzly.filterchain.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
    • encodeHttpPacket

      protected org.glassfish.grizzly.Buffer encodeHttpPacket(org.glassfish.grizzly.filterchain.FilterChainContext ctx, HttpPacket input)
      Overrides:
      encodeHttpPacket in class HttpCodecFilter
    • onInitialLineEncoded

      protected void onInitialLineEncoded(HttpHeader header, org.glassfish.grizzly.filterchain.FilterChainContext ctx)
      Description copied from class: HttpCodecFilter

      Invoked when the initial 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.
    • onHttpHeadersEncoded

      protected void onHttpHeadersEncoded(HttpHeader httpHeader, org.glassfish.grizzly.filterchain.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.
    • onHttpContentEncoded

      protected void onHttpContentEncoded(HttpContent content, org.glassfish.grizzly.filterchain.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.
    • handleEvent

      public org.glassfish.grizzly.filterchain.NextAction handleEvent(org.glassfish.grizzly.filterchain.FilterChainContext ctx, org.glassfish.grizzly.filterchain.FilterChainEvent event) throws IOException
      Specified by:
      handleEvent in interface org.glassfish.grizzly.filterchain.Filter
      Overrides:
      handleEvent in class org.glassfish.grizzly.filterchain.BaseFilter
      Throws:
      IOException
    • handleClose

      public org.glassfish.grizzly.filterchain.NextAction handleClose(org.glassfish.grizzly.filterchain.FilterChainContext ctx) throws IOException
      Specified by:
      handleClose in interface org.glassfish.grizzly.filterchain.Filter
      Overrides:
      handleClose in class org.glassfish.grizzly.filterchain.BaseFilter
      Throws:
      IOException
    • customizeErrorResponse

      protected HttpContent customizeErrorResponse(HttpResponsePacket response)