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 implements 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

    Fields
    Modifier and Type
    Field
    Description
    protected final Logger
    The logger with which to log exceptions that have not been logged before.
    protected final Random
    A random for generating the least significant bytes for the unique server log ID.
    protected de.aristaflow.adept2.base.communication.rest.RequestHandler
    The request handler to get the header data whether to keep the server stack even if the communication service should suppress the stacks.
    protected final Cache<Throwable,UUID>
    The cache keeping the created server log IDs for unexpected exceptions until these exceptions are wrapped eventually.
    protected final boolean
    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

    Modifier and Type
    Method
    Description
    protected UUID
    Creates a unique ID to be set in the message log and in the exception that is sent to the client.
     
    de.aristaflow.adept2.base.communication.rest.ExceptionHandler.ExpectedException
    wrapExpectedException(Throwable cause, jakarta.ws.rs.core.Response.Status status)
     
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • 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 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:
      wrapExpectedException in interface de.aristaflow.adept2.base.communication.rest.ExceptionHandler
    • wrapUnexpectedException

      public IlmException wrapUnexpectedException(Throwable cause)
      Specified by:
      wrapUnexpectedException in interface de.aristaflow.adept2.base.communication.rest.ExceptionHandler
    • getServerLogId

      public UUID getServerLogId(Throwable cause)
      Specified by:
      getServerLogId in interface de.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.