org.glassfish.grizzly.http.server
Class StaticResourcesHandler

java.lang.Object
  extended by org.glassfish.grizzly.http.server.StaticResourcesHandler

public class StaticResourcesHandler
extends Object

Static resources handler, which handles static resources requests made to a HttpService. This class doesn't not decode the Request uri and just do basic security check. If you need more protection, use the HttpService.

Author:
Jeanfrancois Arcand, Alexey Stashok

Field Summary
protected  File docRoot
           
protected  String resourcesContextPath
           
 
Constructor Summary
StaticResourcesHandler()
           
StaticResourcesHandler(File rootFolder)
           
StaticResourcesHandler(String rootFolder)
           
 
Method Summary
 boolean addToFileCache(Request req, File resource)
           
 File getDocRoot()
          Return the directory from where files will be serviced.
 String getResourcesContextPath()
          Return the context path used for servicing resources.
 boolean handle(Request req, Response res)
          Based on the Request URI, try to map the file from the getDocRoot(), and send it synchronously using send file.
protected  boolean handle(String uri, Request req, Response res)
          Lookup a resource based on the request URI, and send it using send file.
 void setDocRoot(File docRoot)
          Set the directory from where files will be serviced.
 void setDocRoot(String docRoot)
          Set the directory from where files will be serviced.
 void setResourcesContextPath(String resourcesContextPath)
          Set the context path used for servicing resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

docRoot

protected volatile File docRoot

resourcesContextPath

protected String resourcesContextPath
Constructor Detail

StaticResourcesHandler

public StaticResourcesHandler()

StaticResourcesHandler

public StaticResourcesHandler(String rootFolder)

StaticResourcesHandler

public StaticResourcesHandler(File rootFolder)
Method Detail

handle

public boolean handle(Request req,
                      Response res)
               throws Exception
Based on the Request URI, try to map the file from the getDocRoot(), and send it synchronously using send file.

Parameters:
req - the Request
res - the Response
Throws:
Exception

handle

protected boolean handle(String uri,
                         Request req,
                         Response res)
                  throws Exception
Lookup a resource based on the request URI, and send it using send file.

Parameters:
uri - The request URI
req - the Request
res - the Response
Throws:
Exception

getDocRoot

public File getDocRoot()
Return the directory from where files will be serviced.

Returns:
the directory from where file will be serviced.

setDocRoot

public void setDocRoot(String docRoot)
Set the directory from where files will be serviced.

Parameters:
docRoot - the directory from where files will be serviced.

setDocRoot

public void setDocRoot(File docRoot)
Set the directory from where files will be serviced.

Parameters:
docRoot - the directory from where files will be serviced.

getResourcesContextPath

public String getResourcesContextPath()
Return the context path used for servicing resources. By default, "" is used so request taking the form of http://host:port/index.html are serviced directly. If set, the resource will be available under http://host:port/context-path/index.html

Returns:
the context path.

setResourcesContextPath

public void setResourcesContextPath(String resourcesContextPath)
Set the context path used for servicing resource. By default, "" is used so request taking the form of http://host:port/index.html are serviced directly. If set, the resource will be available under http://host:port/context-path/index.html

Parameters:
resourcesContextPath - the context path

addToFileCache

public final boolean addToFileCache(Request req,
                                    File resource)


Copyright © 2010 Oracle Corpration. All Rights Reserved.