Class ExceptionHandling
- All Implemented Interfaces:
de.aristaflow.adept2.base.communication.rest.ExceptionHandler
ExceptionHandler an thus provides the means for handling
exceptions appropriately. This is, exceptions are wrapped the status of stack suppression is set
and server log IDs are created as required.
Suppression of server stacks is set via configuration of the communication service and can be
overridden per request which is retrieved from the RequestHandler.
UUIDs identifying the log messages for a specific exception will have the current timestamp as
most significant bytes. This should also be used as time for the log messages to allow for easily
finding a log message.
Since unexpected exceptions are logged before they are wrapped (and the logging class cannot wrap
them), the created server log ID needs to be stored until these exceptions are wrapped. This is
done using a Cache. Although each created server log ID eventually gets used when
wrapping the corresponding exceptions, exceptions occurring while handling such an exception may
prevent this. The usage of Cache ensures that no UUID is kept forever.
-
Nested Class Summary
Nested classes/interfaces inherited from interface de.aristaflow.adept2.base.communication.rest.ExceptionHandler
de.aristaflow.adept2.base.communication.rest.ExceptionHandler.ExpectedException -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final LoggerThe logger with which to log exceptions that have not been logged before.protected final RandomA random for generating the least significant bytes for the unique server log ID.protected de.aristaflow.adept2.base.communication.rest.RequestHandlerThe request handler to get the header data whether to keep the server stack even if the communication service should suppress the stacks.The cache keeping the created server log IDs for unexpected exceptions until these exceptions are wrapped eventually.protected final booleanWhether the communication service is set to suppress the exception stacks so that they do not reach the caller. -
Constructor Summary
ConstructorsConstructorDescriptionExceptionHandling(boolean suppressServerStack, de.aristaflow.adept2.base.communication.rest.RequestHandler reqHandler, LogService logService) Creates a new exception handling with the designated fields. -
Method Summary
Modifier and TypeMethodDescriptionprotected UUIDCreates a unique ID to be set in the message log and in the exception that is sent to the client.getServerLogId(Throwable cause) de.aristaflow.adept2.base.communication.rest.ExceptionHandler.ExpectedExceptionwrapExpectedException(Throwable cause, jakarta.ws.rs.core.Response.Status status) wrapUnexpectedException(Throwable cause)
-
Field Details
-
logger
The logger with which to log exceptions that have not been logged before. -
random
A random for generating the least significant bytes for the unique server log ID. -
serverLogIds
The cache keeping the created server log IDs for unexpected exceptions until these exceptions are wrapped eventually. -
suppressServerStack
protected final boolean suppressServerStackWhether the communication service is set to suppress the exception stacks so that they do not reach the caller. -
reqHandler
protected de.aristaflow.adept2.base.communication.rest.RequestHandler reqHandlerThe request handler to get the header data whether to keep the server stack even if the communication service should suppress the stacks.
-
-
Constructor Details
-
ExceptionHandling
public ExceptionHandling(boolean suppressServerStack, de.aristaflow.adept2.base.communication.rest.RequestHandler reqHandler, LogService logService) Creates a new exception handling with the designated fields.- Parameters:
suppressServerStack- Whether the communication service is set to suppress the exception stacks so that they do not reach the caller.reqHandler- The request handler to get the header data whether to keep the server stack even if the communication service should suppress the stacks.logService- The log service to retrieve the logger with which to log exceptions that have not been logged before.
-
-
Method Details
-
wrapExpectedException
public de.aristaflow.adept2.base.communication.rest.ExceptionHandler.ExpectedException wrapExpectedException(Throwable cause, jakarta.ws.rs.core.Response.Status status) - Specified by:
wrapExpectedExceptionin interfacede.aristaflow.adept2.base.communication.rest.ExceptionHandler
-
wrapUnexpectedException
- Specified by:
wrapUnexpectedExceptionin interfacede.aristaflow.adept2.base.communication.rest.ExceptionHandler
-
getServerLogId
- Specified by:
getServerLogIdin interfacede.aristaflow.adept2.base.communication.rest.ExceptionHandler
-
createServerLogId
Creates a unique ID to be set in the message log and in the exception that is sent to the client. For easier finding a message, the most significant bytes of the UUID correspond to the time of the corresponding log message.- Returns:
- A unique ID to be set in the message log and in the exception that is sent to the client.
-