org.openqa.jetty.http.handler
Class ResourceHandler

java.lang.Object
  extended by org.openqa.jetty.http.handler.AbstractHttpHandler
      extended by org.openqa.jetty.http.handler.ResourceHandler
All Implemented Interfaces:
Serializable, HttpHandler, LifeCycle
Direct Known Subclasses:
SeleniumDriverResourceHandler, SingleTestSuiteResourceHandler, StaticContentHandler

public class ResourceHandler
extends AbstractHttpHandler

Handler to serve files and resources. Serves files from a given resource URL base and implements the GET, HEAD, DELETE, OPTIONS, PUT, MOVE methods and the IfModifiedSince and IfUnmodifiedSince header fields. A simple memory cache is also provided to reduce file I/O. HTTP/1.1 ranges are supported.

Version:
$Id: ResourceHandler.java,v 1.66 2005/08/24 08:18:17 gregwilkins Exp $
Author:
Nuno PreguiƁa, Greg Wilkins
See Also:
Serialized Form

Constructor Summary
ResourceHandler()
          Construct a ResourceHandler.
 
Method Summary
 String[] getAllowedMethods()
           
 String getAllowedString()
           
 int getMinGzipLength()
          Get minimum content length for GZIP encoding.
 boolean getRedirectWelcome()
           
protected  Resource getResource(String pathInContext)
          get Resource to serve.
 void handle(String pathInContext, String pathParams, HttpRequest request, HttpResponse response)
          Handle a request.
 void handleGet(HttpRequest request, HttpResponse response, String pathInContext, String pathParams, Resource resource)
           
 boolean isAcceptRanges()
           
 boolean isDirAllowed()
           
 boolean isMethodAllowed(String method)
           
 void sendData(HttpRequest request, HttpResponse response, String pathInContext, Resource resource, boolean writeHeaders)
           
 void setAcceptRanges(boolean ar)
          Set if the handler accepts range requests.
 void setAllowedMethods(String[] methods)
           
 void setDirAllowed(boolean dirAllowed)
           
 void setMinGzipLength(int minGzipLength)
          Set minimum content length for GZIP encoding.
 void setRedirectWelcome(boolean redirectWelcome)
           
 void start()
          Start the LifeCycle.
 void stop()
          Stop the LifeCycle.
 void writeHeaders(HttpResponse response, Resource resource, long count)
           
 
Methods inherited from class org.openqa.jetty.http.handler.AbstractHttpHandler
getHttpContext, getName, handleTrace, initialize, isStarted, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ResourceHandler

public ResourceHandler()
Construct a ResourceHandler.

Method Detail

start

public void start()
           throws Exception
Description copied from interface: LifeCycle
Start the LifeCycle.

Specified by:
start in interface LifeCycle
Overrides:
start in class AbstractHttpHandler
Throws:
Exception - An arbitrary exception may be thrown.

stop

public void stop()
          throws InterruptedException
Description copied from interface: LifeCycle
Stop the LifeCycle. The LifeCycle may wait for current activities to complete normally, but it can be interrupted.

Specified by:
stop in interface LifeCycle
Overrides:
stop in class AbstractHttpHandler
Throws:
InterruptedException - Stopping a lifecycle is rarely atomic and may be interrupted by another thread. If this happens InterruptedException is throw and the component will be in an indeterminant state and should probably be discarded.

getAllowedMethods

public String[] getAllowedMethods()

setAllowedMethods

public void setAllowedMethods(String[] methods)

isMethodAllowed

public boolean isMethodAllowed(String method)

getAllowedString

public String getAllowedString()

isDirAllowed

public boolean isDirAllowed()

setDirAllowed

public void setDirAllowed(boolean dirAllowed)

isAcceptRanges

public boolean isAcceptRanges()

getRedirectWelcome

public boolean getRedirectWelcome()
Returns:
True if welcome files are redirected to. False if forward is used.

setRedirectWelcome

public void setRedirectWelcome(boolean redirectWelcome)
Parameters:
redirectWelcome - True if welcome files are redirected to. False if forward is used.

setAcceptRanges

public void setAcceptRanges(boolean ar)
Set if the handler accepts range requests. Default is false;

Parameters:
ar - True if the handler should accept ranges

getMinGzipLength

public int getMinGzipLength()
Get minimum content length for GZIP encoding.

Returns:
Minimum length of content for gzip encoding or -1 if disabled.

setMinGzipLength

public void setMinGzipLength(int minGzipLength)
Set minimum content length for GZIP encoding.

Parameters:
minGzipLength - If set to a positive integer, then static content larger than this will be served as gzip content encoded if a matching resource is found ending with ".gz"

getResource

protected Resource getResource(String pathInContext)
                        throws IOException
get Resource to serve. Map a path to a resource. The default implementation calls HttpContext.getResource but derived handers may provide their own mapping.

Parameters:
pathInContext - The path to find a resource for.
Returns:
The resource to serve.
Throws:
IOException

handle

public void handle(String pathInContext,
                   String pathParams,
                   HttpRequest request,
                   HttpResponse response)
            throws HttpException,
                   IOException
Description copied from interface: HttpHandler
Handle a request. Note that Handlers are tried in order until one has handled the request. i.e. until request.isHandled() returns true. In broad terms this means, either a response has been commited or request.setHandled(true) has been called.

Parameters:
pathInContext - The context path
pathParams - Path parameters such as encoded Session ID
request - The HttpRequest request
response - The HttpResponse response
Throws:
HttpException
IOException

handleGet

public void handleGet(HttpRequest request,
                      HttpResponse response,
                      String pathInContext,
                      String pathParams,
                      Resource resource)
               throws IOException
Throws:
IOException

writeHeaders

public void writeHeaders(HttpResponse response,
                         Resource resource,
                         long count)
                  throws IOException
Throws:
IOException

sendData

public void sendData(HttpRequest request,
                     HttpResponse response,
                     String pathInContext,
                     Resource resource,
                     boolean writeHeaders)
              throws IOException
Throws:
IOException


Copyright © 2012. All Rights Reserved.