public abstract class ForwardResource extends java.lang.Object implements TAPResource
A TAPResource
which is able to "forward" an HTTP request toward a specified URI.
In function of the URI shape (i.e. what is the scheme? none/file:/other) and the servlet path,
the HTTP request will be internally forwarded to the Web Application file (using
RequestDispatcher.forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
),
the content of the specified file will be copied in the HTTP response or a redirection toward
the given URL will be performed.
See forward(String, String, HttpServletRequest, HttpServletResponse)
for more details
Modifier and Type | Field and Description |
---|---|
protected TAPLog |
logger
Logger that
forward(String, String, HttpServletRequest, HttpServletResponse) must use
in case of not grave error (e.g. |
Modifier | Constructor and Description |
---|---|
protected |
ForwardResource(TAPLog logger)
Builds a
ForwardResource with a logger to use in case of "small" errors. |
Modifier and Type | Method and Description |
---|---|
boolean |
forward(java.lang.String file,
java.lang.String mimeType,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Write the content of the specified file in the given HTTP response.
|
protected void |
logError(java.lang.String message,
java.lang.Throwable error,
java.lang.String file)
Log the given error as a TAP log message with the
UWSLog.LogLevel ERROR, and the event corresponding to the resource name. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
destroy, executeResource, getName, init, setTAPBaseURL
protected final TAPLog logger
forward(String, String, HttpServletRequest, HttpServletResponse)
must use
in case of not grave error (e.g. the specified Web Application file can not be found).protected ForwardResource(TAPLog logger)
ForwardResource
with a logger to use in case of "small" errors.logger
- A TAP logger.public final boolean forward(java.lang.String file, java.lang.String mimeType, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException
Write the content of the specified file in the given HTTP response.
Three cases are taken into account in this function, in function of the given URI:
Important note:
The 1st option is applied ONLY IF the path of the TAP servlet is NOT the root path of the web application:
that's to say /*
. In the case where a URI without scheme is provided though the servlet path
is /*
, this function will resolve the full path on the local file system and apply the
2nd option: write the file content directly in the response. Note that will work only in cases where the
specified file is not a JSP or does not need any kind of interpretation by the function
RequestDispatcher.forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
.
file
- URI/URL/path of the file to write/forward/redirect in the given HTTP response.mimeType
- MIME type of the specified file.request
- HTTP request which require the specified file.response
- HTTP response in which the specified file must be written/forwarded/redirected.true
if the forward/redirection was successful, false
otherwise.java.io.IOException
- When an error occur while forwarding toward the specified Web application resource,
or while writing the specified local file
or while redirection toward the specified URL
or when the HTTP connection has been aborted.java.lang.IllegalStateException
- If an attempt of resetting the buffer fails.protected void logError(java.lang.String message, java.lang.Throwable error, java.lang.String file)
Log the given error as a TAP log message with the UWSLog.LogLevel
ERROR, and the event corresponding to the resource name.
The logged message starts with: Can not write the specified content ({file})
.
After the specified error message, the following is appended: ! => A default content may be displayed.
.
If the message parameter is missing, the Throwable
message will be taken instead.
And if this latter is also missing, none will be written.
message
- Error message to log.error
- The exception at the origin of the error.