Package com.sodius.oslc.server
Class OslcWebApplicationException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- javax.ws.rs.WebApplicationException
-
- com.sodius.oslc.server.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 Summary
Constructors Constructor Description OslcWebApplicationException(int status)
Deprecated.UseOslcWebApplicationException(Response)
for enhanced error reporting.OslcWebApplicationException(Response response)
Construct a new instance using the supplied response.OslcWebApplicationException(Response.Status status)
Deprecated.UseOslcWebApplicationException(Response)
for enhanced error reporting.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getMessage()
Returns a message that contains the HTTP status code and OSLC Error message, if any.List<OslcError>
getResponseCauses()
The list of causes of theOslcError
entity of the response, or an empty list if no entity is set or it is not anOslcError
.Object
getResponseEntity()
The entity of the response,null
if none.Optional<OslcError>
getResponseError()
TheOslcError
entity of the response,null
if no entity is set or it is not anOslcError
.-
Methods inherited from class javax.ws.rs.WebApplicationException
getResponse
-
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
-
-
-
Constructor Detail
-
OslcWebApplicationException
@Deprecated(since="1.13.0", forRemoval=false) public OslcWebApplicationException(int status)
Deprecated.UseOslcWebApplicationException(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
@Deprecated(since="1.13.0", forRemoval=false) public OslcWebApplicationException(Response.Status status)
Deprecated.UseOslcWebApplicationException(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 withOslcStreams
, rather than trusting the JAX-RS framework for this. ThegetResponseEntity()
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 classThrowable
-
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()
TheOslcError
entity of the response,null
if no entity is set or it is not anOslcError
. 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 theOslcError
entity of the response, or an empty list if no entity is set or it is not anOslcError
. 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()
-
-