public class DefaultTAPErrorWriter extends java.lang.Object implements ServiceErrorWriter
Default implementation of ServiceErrorWriter
for a TAP service.
On the contrary to the UWS standard, all errors must be formatted in VOTable.
So, all errors given to this ServiceErrorWriter
are formatted in VOTable using the structure defined by the IVOA.
To do that, this class will use the function VOTableFormat.writeError(String, java.util.Map, java.io.PrintWriter)
.
The VOTableFormat
will be got from the ServiceConnection
using ServiceConnection.getOutputFormat(String)
with "votable" as parameter. If the returned formatter is not a direct instance or an extension of VOTableFormat
,
a default instance of this class will be always used.
UWSException
s and TAPException
s may precise the HTTP error code to apply,
which will be used to set the HTTP status of the response. If it is a different kind of exception,
the HTTP status 500 (INTERNAL SERVER ERROR) will be used.
Besides, all exceptions except UWSException
and TAPException
will be logged as FATAL in the TAP context
(with no event and no object). Thus the full stack trace is available to the administrator so that the error can
be understood as easily and quickly as possible.
Modifier and Type | Field and Description |
---|---|
protected VOTableFormat |
formatter
Object to use to format an error message into VOTable.
|
protected TAPLog |
logger
Logger to use to report any unexpected error.
|
protected ServiceConnection |
service
Description of the TAP service using this
ServiceErrorWriter . |
Constructor and Description |
---|
DefaultTAPErrorWriter(ServiceConnection service)
Build an error writer for TAP.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getErrorDetailsMIMEType()
Get the MIME type of the error details written by
ServiceErrorWriter.writeError(Throwable, ErrorSummary, UWSJob, OutputStream) in the error summary. |
protected VOTableFormat |
getFormatter()
Get the
VOTableFormat to use in order to format errors. |
protected TAPLog |
getLogger()
Get the logger to use inside this
ServiceErrorWriter . |
protected void |
putExceptionInfos(java.lang.Throwable t,
java.util.Map<java.lang.String,java.lang.String> addInfos)
Add all interesting additional information about the given exception inside the given map.
|
boolean |
writeError(java.lang.String message,
ErrorType type,
int httpErrorCode,
javax.servlet.http.HttpServletResponse response,
javax.servlet.http.HttpServletRequest request,
java.lang.String reqID,
JobOwner user,
java.lang.String action)
Write the described error in the given response.
|
void |
writeError(java.lang.Throwable t,
ErrorSummary error,
UWSJob job,
java.io.OutputStream output)
Write the given error in the given output stream.
|
boolean |
writeError(java.lang.Throwable t,
javax.servlet.http.HttpServletResponse response,
javax.servlet.http.HttpServletRequest request,
java.lang.String reqID,
JobOwner user,
java.lang.String action)
Write the given exception in the given response.
|
protected final ServiceConnection service
ServiceErrorWriter
.protected TAPLog logger
getLogger()
.protected VOTableFormat formatter
getFormatter()
.public DefaultTAPErrorWriter(ServiceConnection service) throws java.lang.NullPointerException
Build an error writer for TAP.
On the contrary to the UWS standard, TAP standard defines a format for error reporting.
Errors should be reported as VOTable document with a defined structure. This one is well
managed by VOTableFormat
which is actually called by this class when an error must
be written.
service
- Description of the TAP service.java.lang.NullPointerException
- If no service description is provided.protected VOTableFormat getFormatter()
Get the VOTableFormat
to use in order to format errors.
Note:
If not yet set, the formatter of this ServiceErrorWriter
is set to the formatter of VOTable results returned by the ServiceConnection
.
However this formatter should be a VOTableFormat
instance or an extension (because the function VOTableFormat.writeError(String, java.util.Map, PrintWriter)
is needed).
Otherwise a default VOTableFormat
instance will be created and always used by this ServiceErrorWriter
.
protected TAPLog getLogger()
Get the logger to use inside this ServiceErrorWriter
.
Note:
If not yet set, the logger of this ServiceErrorWriter
is set to the logger used by the ServiceConnection
.
If none is returned by the ServiceConnection
, a default TAPLog
instance writing logs in System.err
will be created and always used by this ServiceErrorWriter
.
public boolean writeError(java.lang.Throwable t, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpServletRequest request, java.lang.String reqID, JobOwner user, java.lang.String action)
ServiceErrorWriter
Write the given exception in the given response.
Note: If this function is called without at least an exception and an HTTP response, nothing should be done. No error may be thrown.
IMPORTANT:
If any IOException
occurs while writing the error in the given HttpServletResponse
output stream,
this function should stop and return false
. In such case, the error which was supposed to be written
may be logged.
writeError
in interface ServiceErrorWriter
t
- Exception to write/format.response
- Response in which the given exception must be written.request
- Request at the origin of the error (MAY BE NULL).reqID
- ID of the request (which let the user and the administrator identify the failed request). (MAY BE NULL if the request is not provided)user
- User which sends the given request (which generates the error) (MAY BE NULL).action
- Type/Name of the action which generates the error (MAY BE NULL).HttpServletResponse
,
false otherwise.public boolean writeError(java.lang.String message, ErrorType type, int httpErrorCode, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpServletRequest request, java.lang.String reqID, JobOwner user, java.lang.String action)
ServiceErrorWriter
Write the described error in the given response.
Note: If this function is called without at least a message and an HTTP response, nothing should be done. No error may be thrown.
IMPORTANT:
If any IOException
occurs while writing the error in the given HttpServletResponse
output stream,
this function should stop and return false
. In such case, the error which was supposed to be written
may be logged.
writeError
in interface ServiceErrorWriter
message
- Message to display.type
- Type of the error: FATAL or TRANSIENT.httpErrorCode
- HTTP error code (i.e. 404, 500).response
- Response in which the described error must be written.request
- Request which causes this error.reqID
- ID of the request (which let the user and the administrator identify the failed request).user
- User which sends the HTTP request.action
- Action corresponding to the given request.HttpServletResponse
,
false otherwise.public void writeError(java.lang.Throwable t, ErrorSummary error, UWSJob job, java.io.OutputStream output) throws java.io.IOException
ServiceErrorWriter
Write the given error in the given output stream.
This function is used only for the error summary of a job (that's to say to report in the ../error/details parameter any error which occurs while executing a job).
Important note:
The error details written in the given output MUST always have the same MIME type.
This latter MUST be returned by ServiceErrorWriter.getErrorDetailsMIMEType()
.
writeError
in interface ServiceErrorWriter
t
- Error to write. If error is not null, it will be displayed instead of the message of this throwable.error
- Summary of the error. It may particularly contain a message different from the one of the given exception. In this case, it will displayed instead of the exception's message.job
- The job which fails.output
- Stream in which the error must be written.java.io.IOException
- If there an error while writing the error in the given stream.ServiceErrorWriter.getErrorDetailsMIMEType()
protected void putExceptionInfos(java.lang.Throwable t, java.util.Map<java.lang.String,java.lang.String> addInfos)
t
- Exception whose some details must be added inside the given map.addInfos
- Map of all additional information.public java.lang.String getErrorDetailsMIMEType()
ServiceErrorWriter
Get the MIME type of the error details written by ServiceErrorWriter.writeError(Throwable, ErrorSummary, UWSJob, OutputStream)
in the error summary.
Important note: If NULL is returned, the MIME type will be considered as text/plain.
getErrorDetailsMIMEType
in interface ServiceErrorWriter
ServiceErrorWriter.writeError(Throwable, ErrorSummary, UWSJob, OutputStream)