Class ExceptionHandling
- java.lang.Object
-
- de.aristaflow.ilm.ws.rest.base.service.ExceptionHandling
-
- All Implemented Interfaces:
de.aristaflow.adept2.base.communication.rest.ExceptionHandler
public class ExceptionHandling extends Object implements de.aristaflow.adept2.base.communication.rest.ExceptionHandler
This class implementsExceptionHandler
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 aCache
. 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 ofCache
ensures that no UUID is kept forever.
-
-
Field Summary
Fields Modifier and Type Field Description protected Logger
logger
The logger with which to log exceptions that have not been logged before.protected Random
random
A random for generating the least significant bytes for the unique server log ID.protected de.aristaflow.adept2.base.communication.rest.RequestHandler
reqHandler
The request handler to get the header data whether to keep the server stack even if the communication service should suppress the stacks.protected Cache<Throwable,UUID>
serverLogIds
The cache keeping the created server log IDs for unexpected exceptions until these exceptions are wrapped eventually.protected boolean
suppressServerStack
Whether the communication service is set to suppress the exception stacks so that they do not reach the caller.
-
Constructor Summary
Constructors Constructor Description ExceptionHandling(boolean suppressServerStack, de.aristaflow.adept2.base.communication.rest.RequestHandler reqHandler, LogService logService)
Creates a new exception handling with the designated fields.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected UUID
createServerLogId()
Creates a unique ID to be set in the message log and in the exception that is sent to the client.UUID
getServerLogId(Throwable cause)
de.aristaflow.adept2.base.communication.rest.ExceptionHandler.ExpectedException
wrapExpectedException(Throwable cause, javax.ws.rs.core.Response.Status status)
IlmException
wrapUnexpectedException(Throwable cause)
-
-
-
Field Detail
-
logger
protected final Logger logger
The logger with which to log exceptions that have not been logged before.
-
random
protected final Random random
A random for generating the least significant bytes for the unique server log ID.
-
serverLogIds
protected final Cache<Throwable,UUID> serverLogIds
The cache keeping the created server log IDs for unexpected exceptions until these exceptions are wrapped eventually.
-
suppressServerStack
protected final boolean suppressServerStack
Whether 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 reqHandler
The request handler to get the header data whether to keep the server stack even if the communication service should suppress the stacks.
-
-
Constructor Detail
-
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 Detail
-
wrapExpectedException
public de.aristaflow.adept2.base.communication.rest.ExceptionHandler.ExpectedException wrapExpectedException(Throwable cause, javax.ws.rs.core.Response.Status status)
- Specified by:
wrapExpectedException
in interfacede.aristaflow.adept2.base.communication.rest.ExceptionHandler
-
wrapUnexpectedException
public IlmException wrapUnexpectedException(Throwable cause)
- Specified by:
wrapUnexpectedException
in interfacede.aristaflow.adept2.base.communication.rest.ExceptionHandler
-
getServerLogId
public UUID getServerLogId(Throwable cause)
- Specified by:
getServerLogId
in interfacede.aristaflow.adept2.base.communication.rest.ExceptionHandler
-
createServerLogId
protected UUID 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.
-
-