Class ResourceRegistryExceptionMapper

java.lang.Object
org.gcube.informationsystem.resourceregistry.rest.providers.ResourceRegistryExceptionMapper
All Implemented Interfaces:
jakarta.ws.rs.ext.ExceptionMapper<org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException>

@Provider public class ResourceRegistryExceptionMapper extends Object implements jakarta.ws.rs.ext.ExceptionMapper<org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException>
Global JAX-RS ExceptionMapper that maps every ResourceRegistryException thrown by the service into an HTTP error Response.

The mapped status code is derived from the exception's concrete subtype (e.g. NotFoundException → 404, AlreadyPresentException/ ContextLifecycleException/SchemaViolationException → 409, AvailableInAnotherContextException/ContextVisibilityException → 403), defaulting to 400 Bad Request for any other subtype and 500 Internal Server Error for a bare ResourceRegistryException. Every response body follows the unified {"message": "..."} JSON error contract (see 07-api-foundations-and-roles.md).

The stack trace is always logged server-side. The wire body, however, differs by caller: a request originating from one of this project's own Java client libraries (identified by User-Agent, see JAVA_USER_AGENTS) receives the fully marshalled exception (stack trace stripped) for backward-compatible client-side unmarshalling; any other caller receives only the generic {"message": "..."} body, never the marshalled exception shape.

Author:
Luca Frosini (ISTI - CNR)
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    jakarta.ws.rs.core.Response
    toResponse(org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException exception)
    Maps the given exception to an HTTP error Response: selects the status code from the exception's concrete subtype (see the class Javadoc), always logs the stack trace, and builds a {"message": "..."} JSON body — or, for a caller identified as one of this project's own Java client libraries, the fully marshalled exception instead.

    Methods inherited from class java.lang.Object

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

    • ResourceRegistryExceptionMapper

      public ResourceRegistryExceptionMapper()
  • Method Details

    • toResponse

      public jakarta.ws.rs.core.Response toResponse(org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException exception)
      Maps the given exception to an HTTP error Response: selects the status code from the exception's concrete subtype (see the class Javadoc), always logs the stack trace, and builds a {"message": "..."} JSON body — or, for a caller identified as one of this project's own Java client libraries, the fully marshalled exception instead.
      Specified by:
      toResponse in interface jakarta.ws.rs.ext.ExceptionMapper<org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException>
      Parameters:
      exception - the exception to map
      Returns:
      the mapped HTTP error response