|
||||||||||
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 ConcurrentHashMap<String,File> |
cache
|
protected boolean |
commitErrorResponse
Commit the 404 response automatically. |
protected Queue<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() |
Queue<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(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 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 String resourcesContextPath
protected final Queue<File> fileFolders
protected final 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 rootFolder, and send it synchronously using send file.
service
in interface Adapter
req
- the Request
res
- the Response
Exception
protected void service(String uri, Request req, Response res) throws Exception
uri
- The request URIreq
- the Request
res
- 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 Adapter
req
- Request
res
- Response
Exception
public String getRootFolder()
getRootFolders()
public void setRootFolder(String rootFolder)
addRootFolder(java.lang.String)
addRootFolder(java.lang.String)
.
rootFolder
- the directory from where files will be serviced.public Queue<String> getRootFolders()
Queue
of the folders this Adapter can
serve file from.public boolean addRootFolder(String rootFolder)
rootFolder
-
protected void initWebDir() throws IOException
IOException
public void setLogger(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 ByteBuffer
public 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 |