Class OslcWebApplicationException

  • All Implemented Interfaces:
    Serializable

    public class OslcWebApplicationException
    extends WebApplicationException
    A WebApplicationException thats provides a message containing the HTTP status code and OSLC Error message, if any. The super class WebApplicationException doesn't provide any message on its own, which doesn't help debugging. This subclass is introduced to work around this.
    Since:
    1.3.0
    See Also:
    Serialized Form
    • Constructor Detail

      • OslcWebApplicationException

        @Deprecated(since="1.13.0",
                    forRemoval=false)
        public OslcWebApplicationException​(int status)
        Deprecated.
        Use OslcWebApplicationException(Response) for enhanced error reporting.
        Construct a new instance with a blank message and specified HTTP status code.
        Parameters:
        status - the HTTP status code that will be returned to the client.
      • OslcWebApplicationException

        public OslcWebApplicationException​(Response response)
        Construct a new instance using the supplied response.

        Rather than directly instantiating this exception, developer is recommended to use OslcResponses.of(OslcError, org.slf4j.Logger):

         OslcError error = OslcErrors.serverError(errorId, errorMessage).build();
         throw OslcResponses.error(error, LOGGER).buildException();
         

        The entity of the given response, if any, is kept locally in this instance and not communicated to super class. This enables an exception mapper (contributed by OslcServerProviderRegistry) to be involved to stream the error entity with OslcStreams, rather than trusting the JAX-RS framework for this. The getResponseEntity() method may be used to retrieve the entity, if necessary, before it is serialized in the response stream.

        Parameters:
        response - the response that will be returned to the client.
        See Also:
        getResponseEntity(), OslcResponses.of(OslcError, org.slf4j.Logger)
    • Method Detail

      • getMessage

        public String getMessage()
        Returns a message that contains the HTTP status code and OSLC Error message, if any.
        Overrides:
        getMessage in class Throwable
      • getResponseEntity

        public Object getResponseEntity()
        The entity of the response, null if none. The entity was detached from given response in constructor to control its serialization in actual response stream.
        Returns:
        the response entity.
        Since:
        1.13.0
      • getResponseError

        public Optional<OslcError> getResponseError()
        The OslcError entity of the response, null if no entity is set or it is not an OslcError. This method is convenient on server side when a specific condition is to verify for an OSLC error resource used in this exception.
        Returns:
        the response error.
        Since:
        1.14.0
        See Also:
        getResponseEntity()
      • getResponseCauses

        public List<OslcError> getResponseCauses()
        The list of causes of the OslcError entity of the response, or an empty list if no entity is set or it is not an OslcError. This method is convenient on server side when a specific condition is to verify for an OSLC error reported by an OSLC remote application.
        Returns:
        the list of causes of the response error.
        Since:
        1.14.0
        See Also:
        getResponseError(), OslcError.getCauses()