public class ClasspathStaticHttpHandler
extends org.glassfish.grizzly.http.server.HttpHandler
HttpHandler
, which processes requests to a static resources.Modifier and Type | Field and Description |
---|---|
protected org.glassfish.grizzly.utils.ArraySet<org.springframework.core.io.Resource> |
docRoots |
Constructor and Description |
---|
ClasspathStaticHttpHandler()
Create HttpHandler, which, by default, will handle requests to
the static resources located in the current directory.
|
ClasspathStaticHttpHandler(Set<String> docRoots)
Create a new instance which will look for static pages located under the
docRoot.
|
ClasspathStaticHttpHandler(String... docRoots)
Create a new instance which will look for static pages located under the
docRoot.
|
Modifier and Type | Method and Description |
---|---|
void |
addDocRoot(org.springframework.core.io.Resource docRoot)
Add the directory to the list of directories where files will be serviced
from.
|
org.springframework.core.io.Resource |
addDocRoot(String docRoot)
Add the directory to the list of directories where files will be serviced
from.
|
org.springframework.core.io.Resource |
getDefaultDocRoot()
Return the default directory from where files will be serviced.
|
org.glassfish.grizzly.utils.ArraySet<org.springframework.core.io.Resource> |
getDocRoots()
Return the list of directories where files will be serviced from.
|
protected String |
getRelativeURI(org.glassfish.grizzly.http.server.Request request) |
protected boolean |
handle(String uri,
org.glassfish.grizzly.http.server.Request req,
org.glassfish.grizzly.http.server.Response res)
Lookup a resource based on the request URI, and send it using send file.
|
protected void |
onMissingResource(org.glassfish.grizzly.http.server.Request request,
org.glassfish.grizzly.http.server.Response response)
The method will be called, if the static resource requested by the
Request wasn't found, so StaticHttpHandler implementation
may try to workaround this situation. |
void |
removeDocRoot(File docRoot)
Removes the directory from the list of directories where static files
will be serviced from.
|
static void |
sendFile(org.glassfish.grizzly.http.server.Response response,
org.springframework.core.io.Resource file) |
void |
service(org.glassfish.grizzly.http.server.Request request,
org.glassfish.grizzly.http.server.Response response)
Based on the
Request URI, try to map the file from the
getDocRoots() , and send it back to a client. |
customizedErrorPage, destroy, doHandle, getName, getRequestURIEncoding, isAllowCustomStatusMessage, isAllowEncodedSlash, sendAcknowledgment, setAllowCustomStatusMessage, setAllowEncodedSlash, setDecodeUrl, setDispatcherHelper, setRequestURIEncoding, setRequestURIEncoding, start, updateContextPath
protected final org.glassfish.grizzly.utils.ArraySet<org.springframework.core.io.Resource> docRoots
public ClasspathStaticHttpHandler()
public ClasspathStaticHttpHandler(String... docRoots)
docRoots
- the folder(s) where the static resource are located. If the
docRoot is null - static pages won't be
served by this HttpHandlerpublic ClasspathStaticHttpHandler(Set<String> docRoots)
docRoots
- the folders where the static resource are located. If the
docRoot is empty - static pages won't be served by
this HttpHandlerpublic org.springframework.core.io.Resource getDefaultDocRoot()
public org.glassfish.grizzly.utils.ArraySet<org.springframework.core.io.Resource> getDocRoots()
public final org.springframework.core.io.Resource addDocRoot(String docRoot)
docRoot
- the directory to be added to the list of directories where
files will be serviced from.File
representation of the passed
docRoot
.public final void addDocRoot(org.springframework.core.io.Resource docRoot)
docRoot
- the directory to be added to the list of directories where
files will be serviced from.public void removeDocRoot(File docRoot)
docRoot
- the directory to remove.public void service(org.glassfish.grizzly.http.server.Request request, org.glassfish.grizzly.http.server.Response response) throws Exception
Request
URI, try to map the file from the
getDocRoots()
, and send it back to a client.service
in class org.glassfish.grizzly.http.server.HttpHandler
request
- the Request
response
- the Response
Exception
protected String getRelativeURI(org.glassfish.grizzly.http.server.Request request)
protected void onMissingResource(org.glassfish.grizzly.http.server.Request request, org.glassfish.grizzly.http.server.Response response) throws Exception
Request
wasn't found, so StaticHttpHandler
implementation
may try to workaround this situation. The default implementation - sends
a 404 response page by calling
HttpHandler.customizedErrorPage(Request, Response)
.request
- the Request
response
- the Response
Exception
protected boolean handle(String uri, org.glassfish.grizzly.http.server.Request req, org.glassfish.grizzly.http.server.Response res) throws Exception
uri
- The request URIreq
- the Request
res
- the Response
Exception
public static void sendFile(org.glassfish.grizzly.http.server.Response response, org.springframework.core.io.Resource file) throws IOException
IOException
Copyright © 2013. All Rights Reserved.