org.eclipse.jetty.server.handler

## Class ResourceHandler

- java.lang.Object
- - org.eclipse.jetty.util.component.AbstractLifeCycle
  - - org.eclipse.jetty.util.component.AggregateLifeCycle
    - - org.eclipse.jetty.server.handler.AbstractHandler
      - - org.eclipse.jetty.server.handler.AbstractHandlerContainer
        - - org.eclipse.jetty.server.handler.HandlerWrapper
          - - org.eclipse.jetty.server.handler.ResourceHandler

- All Implemented Interfaces:
    Handler, HandlerContainer, Destroyable, Dumpable, LifeCycle

      public class ResourceHandler
      extends HandlerWrapper

  Resource Handler. This handle will serve static content and handle If-Modified-Since headers. No caching is done. Requests for resources that do not exist are let pass (Eg no 404's).
  Apache XBean:

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

      `AbstractLifeCycle.AbstractLifeCycleListener`

    - ### Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle

      `LifeCycle.Listener`

  - ### Field Summary

    - ### Fields inherited from class org.eclipse.jetty.server.handler.HandlerWrapper

      `_handler`

    - ### Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

      `_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ResourceHandler()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `doDirectory(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Resource resource)`
    `protected void` | `doResponseHeaders(javax.servlet.http.HttpServletResponse response, Resource resource, String mimeType)` Set the response headers.
    `void` | `doStart()` Start the managed lifecycle beans in the order they were added.
    `Resource` | `getBaseResource()`
    `String` | `getCacheControl()`
    `MimeTypes` | `getMimeTypes()`
    `protected Resource` | `getResource(javax.servlet.http.HttpServletRequest request)`
    `Resource` | `getResource(String path)`
    `String` | `getResourceBase()`
    `Resource` | `getStylesheet()`
    `protected Resource` | `getWelcome(Resource directory)`
    `String[]` | `getWelcomeFiles()`
    `void` | `handle(String target, Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)` Handle a request.
    `boolean` | `isAliases()`
    `boolean` | `isDirectoriesListed()` Get the directory option.
    `boolean` | `isEtags()`
    `void` | `setAliases(boolean aliases)` Set if resource aliases (eg symlink, 8.3 names, case insensitivity) are allowed.
    `void` | `setBaseResource(Resource base)`
    `void` | `setCacheControl(String cacheControl)`
    `void` | `setDirectoriesListed(boolean directory)` Set the directory.
    `void` | `setEtags(boolean etags)`
    `void` | `setMimeTypes(MimeTypes mimeTypes)`
    `void` | `setResourceBase(String resourceBase)`
    `void` | `setStylesheet(String stylesheet)`
    `void` | `setWelcomeFiles(String[] welcomeFiles)`

    - ### Methods inherited from class org.eclipse.jetty.server.handler.HandlerWrapper

      `destroy, doStop, expandChildren, getHandler, getHandlers, getNestedHandlerByClass, setHandler, setServer`

    - ### Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandlerContainer

      `dump, expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass`

    - ### Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandler

      `dumpThis, getServer`

    - ### Methods inherited from class org.eclipse.jetty.util.component.AggregateLifeCycle

      `addBean, addBean, contains, dump, dump, dump, dump, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, unmanage`

    - ### Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

      `addLifeCycleListener, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle

      `addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

- - ### Constructor Detail

    - #### ResourceHandler

          public ResourceHandler()

  - ### Method Detail

    - #### getMimeTypes

          public MimeTypes getMimeTypes()

    - #### setMimeTypes

          public void setMimeTypes(MimeTypes mimeTypes)

    - #### isAliases

          public boolean isAliases()

      Returns:
        True if resource aliases are allowed.

    - #### setAliases

          public void setAliases(boolean aliases)

      Set if resource aliases (eg symlink, 8.3 names, case insensitivity) are allowed. Allowing aliases can significantly increase security vulnerabilities. If this handler is deployed inside a ContextHandler, then the `ContextHandler.isAliases()` takes precedent.
      Parameters:
        `aliases` - True if aliases are supported.

    - #### isDirectoriesListed

          public boolean isDirectoriesListed()

      Get the directory option.
      Returns:
        true if directories are listed.

    - #### setDirectoriesListed

          public void setDirectoriesListed(boolean directory)

      Set the directory.
      Parameters:
        `directory` - true if directories are listed.

    - #### isEtags

          public boolean isEtags()

      Returns:
        True if ETag processing is done

    - #### setEtags

          public void setEtags(boolean etags)

      Parameters:
        `etags` - True if ETag processing is done

    - #### doStart

          public void doStart()
                       throws Exception

      Description copied from class: `AggregateLifeCycle`
      Start the managed lifecycle beans in the order they were added.
      Overrides:
        `doStart` in class `HandlerWrapper`
      Throws:
        `Exception`
      See Also:
        `AbstractLifeCycle.doStart()`

    - #### getBaseResource

          public Resource getBaseResource()

      Returns:
        Returns the resourceBase.

    - #### getResourceBase

          public String getResourceBase()

      Returns:
        Returns the base resource as a string.

    - #### setBaseResource

          public void setBaseResource(Resource base)

      Parameters:
        `base` - The resourceBase to set.

    - #### setResourceBase

          public void setResourceBase(String resourceBase)

      Parameters:
        `resourceBase` - The base resource as a string.

    - #### getStylesheet

          public Resource getStylesheet()

      Returns:
        Returns the stylesheet as a Resource.

    - #### setStylesheet

          public void setStylesheet(String stylesheet)

      Parameters:
        `stylesheet` - The location of the stylesheet to be used as a String.

    - #### getCacheControl

          public String getCacheControl()

      Returns:
        the cacheControl header to set on all static content.

    - #### setCacheControl

          public void setCacheControl(String cacheControl)

      Parameters:
        `cacheControl` - the cacheControl header to set on all static content.

    - #### getResource

          public Resource getResource(String path)
                               throws MalformedURLException

      Throws:
        `MalformedURLException`

    - #### getResource

          protected Resource getResource(javax.servlet.http.HttpServletRequest request)
                                  throws MalformedURLException

      Throws:
        `MalformedURLException`

    - #### getWelcomeFiles

          public String[] getWelcomeFiles()

    - #### setWelcomeFiles

          public void setWelcomeFiles(String[] welcomeFiles)

    - #### getWelcome

          protected Resource getWelcome(Resource directory)
                                 throws MalformedURLException,
                                        IOException

      Throws:
        `MalformedURLException`
        `IOException`

    - #### handle

          public void handle(String target,
                    Request baseRequest,
                    javax.servlet.http.HttpServletRequest request,
                    javax.servlet.http.HttpServletResponse response)
                      throws IOException,
                             javax.servlet.ServletException

      Description copied from interface: `Handler`
      Handle a request.
      Specified by:
        `handle` in interface `Handler`
      Overrides:
        `handle` in class `HandlerWrapper`
      Parameters:
        `target` - The target of the request - either a URI or a name.
        `baseRequest` - The original unwrapped request object.
        `request` - The request either as the `Request` object or a wrapper of that request. The `AbstractHttpConnection.getCurrentConnection()` method can be used access the Request object if required.
        `response` - The response as the `Response` object or a wrapper of that request. The `AbstractHttpConnection.getCurrentConnection()` method can be used access the Response object if required.
      Throws:
        `IOException`
        `javax.servlet.ServletException`

    - #### doDirectory

          protected void doDirectory(javax.servlet.http.HttpServletRequest request,
                         javax.servlet.http.HttpServletResponse response,
                         Resource resource)
                              throws IOException

      Throws:
        `IOException`

    - #### doResponseHeaders

          protected void doResponseHeaders(javax.servlet.http.HttpServletResponse response,
                               Resource resource,
                               String mimeType)

      Set the response headers. This method is called to set the response headers such as content type and content length. May be extended to add additional headers.
      Parameters:
        `response` -
        `resource` -
        `mimeType` -

Copyright © 1995-2016 Mort Bay Consulting. All Rights Reserved.