|
||||||||||
| 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 service(com.sun.grizzly.tcp.Request, com.sun.grizzly.tcp.Response)
and use HttpRequestURIDecoder to protect against security attack.
| Field Summary | |
|---|---|
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,java.io.File> |
cache
|
protected boolean |
commitErrorResponse
Commit the 404 response automatically. |
protected java.util.Queue<java.io.File> |
fileFolders
|
protected java.util.logging.Logger |
logger
|
protected java.lang.String |
resourcesContextPath
|
| Constructor Summary | |
|---|---|
StaticResourcesAdapter()
|
|
StaticResourcesAdapter(java.lang.String rootFolder)
|
|
| Method Summary | |
|---|---|
boolean |
addRootFolder(java.lang.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 |
java.lang.String |
getDefaultContentType()
If the content-type of the request cannot be determined, used the default value. |
java.lang.String |
getResourcesContextPath()
Return the context path used for servicing resources. |
java.lang.String |
getRootFolder()
Deprecated. - use getRootFolders() |
java.util.Queue<java.lang.String> |
getRootFolders()
Return the list of folders the adapter can serve file from. |
protected void |
initWebDir()
Initialize. |
boolean |
isUseSendFile()
|
void |
service(Request req,
Response res)
Based on the Request URI, try to map the file from the rootFolder, and send it synchronously using send file. |
protected void |
service(java.lang.String uri,
Request req,
Response res)
Lookup a resource based on the request URI, and send it using send file. |
void |
setDefaultContentType(java.lang.String defaultContentType)
Set the default content-type if we can't determine it. |
void |
setLogger(java.util.logging.Logger logger)
|
void |
setResourcesContextPath(java.lang.String resourcesContextPath)
Set the context path used for servicing resource. |
void |
setRootFolder(java.lang.String rootFolder)
Deprecated. - use addRootFolder(java.lang.String) |
void |
setUseSendFile(boolean useSendFile)
true if FileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel)
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 java.lang.String resourcesContextPath
protected final java.util.Queue<java.io.File> fileFolders
protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,java.io.File> cache
protected java.util.logging.Logger logger
protected boolean commitErrorResponse
| Constructor Detail |
|---|
public StaticResourcesAdapter()
public StaticResourcesAdapter(java.lang.String rootFolder)
| Method Detail |
|---|
public void service(Request req,
Response res)
throws java.lang.Exception
Request URI, try to map the file from the rootFolder, and send it synchronously using send file.
service in interface Adapterreq - the Requestres - the Response
java.lang.Exception
protected void service(java.lang.String uri,
Request req,
Response res)
throws java.lang.Exception
uri - The request URIreq - the Requestres - the Response
java.lang.Exception
protected void customizedErrorPage(Request req,
Response res)
throws java.lang.Exception
req - The Request objectres - The Response object
java.lang.Exception
public void afterService(Request req,
Response res)
throws java.lang.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
java.lang.Exceptionpublic java.lang.String getRootFolder()
getRootFolders()
public void setRootFolder(java.lang.String rootFolder)
addRootFolder(java.lang.String)
addRootFolder(java.lang.String).
rootFolder - the directory from where files will be serviced.public java.util.Queue<java.lang.String> getRootFolders()
Queue of the folders this Adapter can
serve file from.public boolean addRootFolder(java.lang.String rootFolder)
rootFolder -
protected void initWebDir()
throws java.io.IOException
java.io.IOExceptionpublic void setLogger(java.util.logging.Logger logger)
public boolean isUseSendFile()
true if FileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel)
to send a static resources.public void setUseSendFile(boolean useSendFile)
true if FileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel)
to send a static resources, false if the File needs to be loaded in
memory and flushed using ByteBuffer.
useSendFile - True if FileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel)
to send a static resources, false if the File needs to be loaded in
memory and flushed using ByteBufferpublic java.lang.String getResourcesContextPath()
public void setResourcesContextPath(java.lang.String resourcesContextPath)
resourcesContextPath - the context pathpublic java.lang.String getDefaultContentType()
public void setDefaultContentType(java.lang.String defaultContentType)
defaultContentType - the defaultContentType to set
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||