org.mortbay.http.handler

Class ResourceHandler

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 Preguiga Greg Wilkins

Constructor Summary
ResourceHandler()
Construct a ResourceHandler.
Method Summary
String[]getAllowedMethods()
StringgetAllowedString()
intgetMinGzipLength()
Get minimum content length for GZIP encoding.
booleangetRedirectWelcome()
protected ResourcegetResource(String pathInContext)
get Resource to serve.
voidhandle(String pathInContext, String pathParams, HttpRequest request, HttpResponse response)
voidhandleGet(HttpRequest request, HttpResponse response, String pathInContext, String pathParams, Resource resource)
booleanisAcceptRanges()
booleanisDirAllowed()
booleanisMethodAllowed(String method)
voidsendData(HttpRequest request, HttpResponse response, String pathInContext, Resource resource, boolean writeHeaders)
voidsetAcceptRanges(boolean ar)
Set if the handler accepts range requests.
voidsetAllowedMethods(String[] methods)
voidsetDirAllowed(boolean dirAllowed)
voidsetMinGzipLength(int minGzipLength)
Set minimum content length for GZIP encoding.
voidsetRedirectWelcome(boolean redirectWelcome)
voidstart()
voidstop()
voidwriteHeaders(HttpResponse response, Resource resource, long count)

Constructor Detail

ResourceHandler

public ResourceHandler()
Construct a ResourceHandler.

Method Detail

getAllowedMethods

public String[] getAllowedMethods()

getAllowedString

public String getAllowedString()

getMinGzipLength

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

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

getRedirectWelcome

public boolean getRedirectWelcome()

Returns: True if welcome files are redirected to. False if forward is used.

getResource

protected Resource getResource(String pathInContext)
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.

handle

public void handle(String pathInContext, String pathParams, HttpRequest request, HttpResponse response)

handleGet

public void handleGet(HttpRequest request, HttpResponse response, String pathInContext, String pathParams, Resource resource)

isAcceptRanges

public boolean isAcceptRanges()

isDirAllowed

public boolean isDirAllowed()

isMethodAllowed

public boolean isMethodAllowed(String method)

sendData

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

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

setAllowedMethods

public void setAllowedMethods(String[] methods)

setDirAllowed

public void setDirAllowed(boolean dirAllowed)

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"

setRedirectWelcome

public void setRedirectWelcome(boolean redirectWelcome)

Parameters: redirectWelcome True if welcome files are redirected to. False if forward is used.

start

public void start()

stop

public void stop()

writeHeaders

public void writeHeaders(HttpResponse response, Resource resource, long count)
Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.