Class ClientDownloadFilter

java.lang.Object
org.glassfish.grizzly.filterchain.BaseFilter
org.glassfish.grizzly.samples.http.download.ClientDownloadFilter
All Implemented Interfaces:
org.glassfish.grizzly.filterchain.Filter

public class ClientDownloadFilter extends org.glassfish.grizzly.filterchain.BaseFilter
HTTP client download filter. This Filter is responsible for asynchronous downloading of a HTTP resource and saving its content in a local file.
Author:
Alexey Stashok
  • Constructor Summary

    Constructors
    Constructor
    Description
    ClientDownloadFilter(URI uri, org.glassfish.grizzly.impl.FutureImpl<String> completeFuture)
    ClientDownloadFilter constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    org.glassfish.grizzly.filterchain.NextAction
    handleClose(org.glassfish.grizzly.filterchain.FilterChainContext ctx)
    The method is called, when the client connection will get closed.
    org.glassfish.grizzly.filterchain.NextAction
    handleConnect(org.glassfish.grizzly.filterchain.FilterChainContext ctx)
    The method is called, when a client connection gets connected to a web server.
    org.glassfish.grizzly.filterchain.NextAction
    handleRead(org.glassfish.grizzly.filterchain.FilterChainContext ctx)
    The method is called, when we receive a HttpContent from a server.

    Methods inherited from class org.glassfish.grizzly.filterchain.BaseFilter

    createContext, exceptionOccurred, handleAccept, handleEvent, handleWrite, onAdded, onFilterChainChanged, onRemoved, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ClientDownloadFilter

      public ClientDownloadFilter(URI uri, org.glassfish.grizzly.impl.FutureImpl<String> completeFuture)
      ClientDownloadFilter constructor
      Parameters:
      uri - URI of a remote resource to download
      completeFuture - download completion handler (FutureImpl)
  • Method Details

    • handleConnect

      public org.glassfish.grizzly.filterchain.NextAction handleConnect(org.glassfish.grizzly.filterchain.FilterChainContext ctx) throws IOException
      The method is called, when a client connection gets connected to a web server. When this method gets called by a framework - it means that client connection has been established and we can send HTTP request to the web server.
      Specified by:
      handleConnect in interface org.glassfish.grizzly.filterchain.Filter
      Overrides:
      handleConnect in class org.glassfish.grizzly.filterchain.BaseFilter
      Parameters:
      ctx - Client connect processing context
      Returns:
      NextAction
      Throws:
      IOException
    • handleRead

      public org.glassfish.grizzly.filterchain.NextAction handleRead(org.glassfish.grizzly.filterchain.FilterChainContext ctx) throws IOException
      The method is called, when we receive a HttpContent from a server. Once we receive one - we save the content chunk to a local file.
      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
    • handleClose

      public org.glassfish.grizzly.filterchain.NextAction handleClose(org.glassfish.grizzly.filterchain.FilterChainContext ctx) throws IOException
      The method is called, when the client connection will get closed. Intercepting this method let's use release resources, like local FileChannel, if it wasn't released before.
      Specified by:
      handleClose in interface org.glassfish.grizzly.filterchain.Filter
      Overrides:
      handleClose in class org.glassfish.grizzly.filterchain.BaseFilter
      Parameters:
      ctx - Request processing context
      Returns:
      NextAction
      Throws:
      IOException