Class ResourceService
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA welcome target paired with how to process it.static interfacestatic enumHow welcome targets should be processed. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddoGet(Request request, Response response, Callback callback, HttpContent content) Get the cacheControl header to set on all static content..getContent(String path, Request request) intprotected voidhandleWelcomeAction(Request request, Response response, Callback callback, ResourceService.WelcomeAction welcomeAction) booleanbooleanbooleanisEtags()protected booleanpassConditionalHeaders(Request request, Response response, HttpContent content, Callback callback) protected voidputHeaders(Response response) protected voidputHeaders(Response response, HttpContent content, long contentLength) protected voidputNotModifiedHeaders(Response response, HttpContent content) protected voidredirectWelcome(Request request, Response response, Callback callback, String welcomeTarget) Redirects to the given welcome target.protected voidrehandleWelcome(Request request, Response response, Callback callback, String welcomeTarget) Rehandles the given welcome target.protected voidsendRedirect(Request request, Response response, Callback callback, String target) protected voidsendWelcome(HttpContent content, String pathInContext, boolean endsWithSlash, Request request, Response response, Callback callback) protected voidserveWelcome(Request request, Response response, Callback callback, String welcomeTarget) Serves the given welcome target.voidsetAcceptRanges(boolean acceptRanges) voidsetCacheControl(String cacheControl) Set the cacheControl header to set on all static content..voidsetDirAllowed(boolean dirAllowed) voidsetEncodingCacheSize(int encodingCacheSize) voidsetEtags(boolean etags) voidsetGzipEquivalentFileExtensions(List<String> gzipEquivalentFileExtensions) Set file extensions that signify that a file is gzip compressed.voidsetHttpContentFactory(HttpContent.Factory contentFactory) voidsetPrecompressedFormats(List<CompressedContentFormat> precompressedFormats) voidsetWelcomeFactory(ResourceService.WelcomeFactory welcomeFactory) voidsetWelcomeMode(ResourceService.WelcomeMode welcomeMode) toString()protected voidwriteHttpContent(Request request, Response response, Callback callback, HttpContent content) protected voidwriteHttpError(Request request, Response response, Callback callback, int status) protected voidwriteHttpError(Request request, Response response, Callback callback, int status, String msg, Throwable cause) protected voidwriteHttpError(Request request, Response response, Callback callback, Throwable cause)
-
Constructor Details
-
ResourceService
public ResourceService()
-
-
Method Details
-
getContent
- Throws:
IOException
-
getHttpContentFactory
-
setHttpContentFactory
-
getCacheControl
Get the cacheControl header to set on all static content..- Returns:
- the cacheControl header to set on all static content.
-
getGzipEquivalentFileExtensions
-
doGet
-
writeHttpError
-
writeHttpError
-
writeHttpError
-
sendRedirect
-
passConditionalHeaders
protected boolean passConditionalHeaders(Request request, Response response, HttpContent content, Callback callback) throws IOException - Returns:
- true if the request was processed, false otherwise.
- Throws:
IOException
-
sendWelcome
-
handleWelcomeAction
-
redirectWelcome
protected void redirectWelcome(Request request, Response response, Callback callback, String welcomeTarget) throws Exception Redirects to the given welcome target.
Implementations should use HTTP redirect APIs to generate a redirect response whose location is the welcome target.
- Parameters:
request- the request to redirectresponse- the responsecallback- the callback to completewelcomeTarget- the welcome target to redirect to- Throws:
Exception- if the redirection fails
-
serveWelcome
protected void serveWelcome(Request request, Response response, Callback callback, String welcomeTarget) throws Exception Serves the given welcome target.
Implementations should write the welcome target bytes over the network to the client.
- Parameters:
request- the requestresponse- the responsecallback- the callback to completewelcomeTarget- the welcome target to serve- Throws:
Exception- if serving the welcome target fails
-
rehandleWelcome
protected void rehandleWelcome(Request request, Response response, Callback callback, String welcomeTarget) throws Exception Rehandles the given welcome target.
Implementations should call
Request.Handler.handle(Request, Response, Callback)on aHandlerthat may handle the welcome target differently from the original request.For example, a request for
/ctx/may be rewritten as/ctx/index.jspand rehandled from theServer. In this example, the rehandling of/ctx/index.jspmay trigger a different code path so that the rewritten request is handled by a differentHandler, in this example one that knows how to handle JSP resources.- Parameters:
request- the requestresponse- the responsecallback- the callback to completewelcomeTarget- the welcome target to rehandle to- Throws:
Exception- if the rehandling fails
-
writeHttpContent
protected void writeHttpContent(Request request, Response response, Callback callback, HttpContent content) -
putHeaders
-
putNotModifiedHeaders
-
putHeaders
-
isAcceptRanges
public boolean isAcceptRanges()- Returns:
- If true, range requests and responses are supported
-
isDirAllowed
public boolean isDirAllowed()- Returns:
- If true, directory listings are returned if no welcome target is found. Else 403 Forbidden.
-
isEtags
public boolean isEtags()- Returns:
- True if ETag processing is done
-
getPrecompressedFormats
- Returns:
- Precompressed resources formats that can be used to serve compressed variant of resources.
-
getWelcomeMode
-
getWelcomeFactory
-
setAcceptRanges
public void setAcceptRanges(boolean acceptRanges) - Parameters:
acceptRanges- If true, range requests and responses are supported
-
setCacheControl
Set the cacheControl header to set on all static content..- Parameters:
cacheControl- the cacheControl header to set on all static content.
-
setDirAllowed
public void setDirAllowed(boolean dirAllowed) - Parameters:
dirAllowed- If true, directory listings are returned if no welcome target is found. Else 403 Forbidden.
-
setEtags
public void setEtags(boolean etags) - Parameters:
etags- True if ETag processing is done
-
setGzipEquivalentFileExtensions
-
setPrecompressedFormats
- Parameters:
precompressedFormats- The list of precompresed formats to serve in encoded format if matching resource found. For example serve gzip encoded file if ".gz" suffixed resource is found.
-
setEncodingCacheSize
public void setEncodingCacheSize(int encodingCacheSize) -
getEncodingCacheSize
public int getEncodingCacheSize() -
setWelcomeMode
-
toString
-
setWelcomeFactory
-