Class ResourceService
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final record
A welcome target paired with how to process it.static interface
static enum
How welcome targets should be processed. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
doGet
(Request request, Response response, Callback callback, HttpContent content) Get the cacheControl header to set on all static content..getContent
(String path, Request request) int
protected void
handleWelcomeAction
(Request request, Response response, Callback callback, ResourceService.WelcomeAction welcomeAction) boolean
boolean
boolean
isEtags()
protected boolean
passConditionalHeaders
(Request request, Response response, HttpContent content, Callback callback) protected void
putHeaders
(Response response, HttpContent content, long contentLength) protected void
redirectWelcome
(Request request, Response response, Callback callback, String welcomeTarget) Redirects to the given welcome target.protected void
rehandleWelcome
(Request request, Response response, Callback callback, String welcomeTarget) Rehandles the given welcome target.protected void
sendRedirect
(Request request, Response response, Callback callback, String target) protected void
sendWelcome
(HttpContent content, String pathInContext, boolean endsWithSlash, Request request, Response response, Callback callback) protected void
serveWelcome
(Request request, Response response, Callback callback, String welcomeTarget) Serves the given welcome target.void
setAcceptRanges
(boolean acceptRanges) void
setCacheControl
(String cacheControl) Set the cacheControl header to set on all static content..void
setDirAllowed
(boolean dirAllowed) void
setEncodingCacheSize
(int encodingCacheSize) void
setEtags
(boolean etags) void
setGzipEquivalentFileExtensions
(List<String> gzipEquivalentFileExtensions) Set file extensions that signify that a file is gzip compressed.void
setHttpContentFactory
(HttpContent.Factory contentFactory) void
setPrecompressedFormats
(List<CompressedContentFormat> precompressedFormats) void
setWelcomeFactory
(ResourceService.WelcomeFactory welcomeFactory) void
setWelcomeMode
(ResourceService.WelcomeMode welcomeMode) toString()
protected void
writeHttpContent
(Request request, Response response, Callback callback, HttpContent content) protected void
writeHttpError
(Request request, Response response, Callback callback, int status) protected void
writeHttpError
(Request request, Response response, Callback callback, int status, String msg, Throwable cause) protected void
writeHttpError
(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
- Returns:
- file extensions that signify that a file is gzip compressed. Eg ".svgz"
-
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
protected void sendWelcome(HttpContent content, String pathInContext, boolean endsWithSlash, Request request, Response response, Callback callback) throws Exception - Throws:
Exception
-
handleWelcomeAction
protected void handleWelcomeAction(Request request, Response response, Callback callback, ResourceService.WelcomeAction welcomeAction) throws Exception - Throws:
Exception
-
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 aHandler
that may handle the welcome target differently from the original request.For example, a request for
/ctx/
may be rewritten as/ctx/index.jsp
and rehandled from theServer
. In this example, the rehandling of/ctx/index.jsp
may 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
-
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
Set file extensions that signify that a file is gzip compressed. Eg ".svgz".- Parameters:
gzipEquivalentFileExtensions
- file extensions that signify that a file is gzip compressed. Eg ".svgz"
-
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
-