|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.grizzly.tcp.StaticResourcesAdapter
public class StaticResourcesAdapter
Simple Adapter that map the Request URI to a local file. The
file is send synchronously using the NIO send file mechanism
(@link File#transfertTo}.
This class doesn't not decode the Request uri and just do
basic security check. If you need more protection, use the GrizzlyAdapter
class instead or extend the StaticResourcesAdapter#service()
and use HttpRequestURIDecoder to protect against security attack.
| Field Summary | |
|---|---|
protected ConcurrentHashMap<String,File> |
cache
|
protected boolean |
commitErrorResponse
Commit the 404 response automatically. |
protected ConcurrentLinkedQueue<File> |
fileFolders
|
protected Logger |
logger
|
protected String |
resourcesContextPath
|
| Constructor Summary | |
|---|---|
StaticResourcesAdapter()
|
|
StaticResourcesAdapter(String rootFolder)
|
|
| Method Summary | |
|---|---|
boolean |
addRootFolder(String rootFolder)
Add a folder to the list of folders this Adapter can serve file from. |
void |
afterService(Request req,
Response res)
Finish the Response and recycle the Request and the
Response. |
protected void |
customizedErrorPage(Request req,
Response res)
Customize the error pahe |
String |
getDefaultContentType()
If the content-type of the request cannot be determined, used the default value. |
String |
getResourcesContextPath()
Return the context path used for servicing resources. |
String |
getRootFolder()
Deprecated. - use getRootFolders() |
ConcurrentLinkedQueue<String> |
getRootFolders()
Return the list of folders the adapter can serve file from. |
protected void |
initWebDir()
Initialize. |
boolean |
isUseSendFile()
True if File#transfertTo to send a static resources. |
void |
service(Request req,
Response res)
Based on the Request URI, try to map the file from the
StaticResourcesAdapter#rootFolder, and send it synchronously using send file. |
protected void |
service(String uri,
Request req,
Response res)
Lookup a resource based on the request URI, and send it using send file. |
void |
setDefaultContentType(String defaultContentType)
Set the default content-type if we can't determine it. |
void |
setLogger(Logger logger)
|
void |
setResourcesContextPath(String resourcesContextPath)
Set the context path used for servicing resource. |
void |
setRootFolder(String rootFolder)
Deprecated. - use #addRootFolders |
void |
setUseSendFile(boolean useSendFile)
True if File#transfertTo to send a static resources, false if
the File needs to be loaded in memory and flushed using ByteBuffer |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected String resourcesContextPath
protected final ConcurrentLinkedQueue<File> fileFolders
protected ConcurrentHashMap<String,File> cache
protected Logger logger
protected boolean commitErrorResponse
| Constructor Detail |
|---|
public StaticResourcesAdapter()
public StaticResourcesAdapter(String rootFolder)
| Method Detail |
|---|
public void service(Request req,
Response res)
throws Exception
Request URI, try to map the file from the
StaticResourcesAdapter#rootFolder, and send it synchronously using send file.
service in interface Adapterreq - the Requestres - the Response
Exception
protected void service(String uri,
Request req,
Response res)
throws Exception
uri - The request URIreq - the Requestres - the Response
Exception
protected void customizedErrorPage(Request req,
Response res)
throws Exception
req - The Request objectres - The Response object
Exception
public void afterService(Request req,
Response res)
throws Exception
Response and recycle the Request and the
Response. If the commitErrorResponse
is set to false, this method does nothing.
afterService in interface Adapterreq - Requestres - Response
Exceptionpublic String getRootFolder()
getRootFolders()
public void setRootFolder(String rootFolder)
#addRootFolders
addRootFolder(java.lang.String).
rootFolder - the directory from where files will be serviced.public ConcurrentLinkedQueue<String> getRootFolders()
ConcurentLinkedList of the folders this Adapter can
serve file from.public boolean addRootFolder(String rootFolder)
rootFolder -
protected void initWebDir()
throws IOException
IOExceptionpublic void setLogger(Logger logger)
public boolean isUseSendFile()
File#transfertTo to send a static resources.
File#transfertTo to send a static resources.public void setUseSendFile(boolean useSendFile)
File#transfertTo to send a static resources, false if
the File needs to be loaded in memory and flushed using ByteBuffer
useSendFile - True if File#transfertTo to send a static resources, false if
the File needs to be loaded in memory and flushed using ByteBufferpublic String getResourcesContextPath()
public void setResourcesContextPath(String resourcesContextPath)
resourcesContextPath - the context pathpublic String getDefaultContentType()
public void setDefaultContentType(String defaultContentType)
defaultContentType - the defaultContentType to set
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||