Class JaxrsExceptionMapper
- java.lang.Object
-
- org.kiwiproject.jaxrs.exception.JaxrsExceptionMapper
-
- All Implemented Interfaces:
javax.ws.rs.ext.ExceptionMapper<JaxrsException>
@Provider public class JaxrsExceptionMapper extends Object implements javax.ws.rs.ext.ExceptionMapper<JaxrsException>
Map aJaxrsExceptionto aResponse.The mapped response has the status of the given
JaxrsExceptionand media type JSON.
-
-
Field Summary
Fields Modifier and Type Field Description static StringKEY_ERRORSThe map key under which the list ofErrorMessageobjects resides.
-
Constructor Summary
Constructors Constructor Description JaxrsExceptionMapper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static javax.ws.rs.core.ResponsebuildResponse(JaxrsException exception)Convert the givenJaxrsExceptionto a JSON response.static javax.ws.rs.core.Response.ResponseBuilderbuildResponseBuilder(JaxrsException exception)Convert the givenJaxrsExceptionto a JSON response builder.static Map<String,Object>buildResponseEntity(JaxrsException exception)Convert the givenJaxrsExceptionto a map that can be used as a JSON response entity.static JaxrsExceptiontoJaxrsException(int status, Map<String,Object> entity)Convert the given HTTP status code and an entity into aJaxrsException.static JaxrsExceptiontoJaxrsException(javax.ws.rs.core.Response response)Convert the givenResponseto aJaxrsException.javax.ws.rs.core.ResponsetoResponse(JaxrsException exception)Convert the givenJaxrsExceptionto a response containing a JSON entity.
-
-
-
Field Detail
-
KEY_ERRORS
public static final String KEY_ERRORS
The map key under which the list ofErrorMessageobjects resides.- See Also:
- Constant Field Values
-
-
Method Detail
-
toResponse
public javax.ws.rs.core.Response toResponse(JaxrsException exception)
Convert the givenJaxrsExceptionto a response containing a JSON entity.- Specified by:
toResponsein interfacejavax.ws.rs.ext.ExceptionMapper<JaxrsException>- Parameters:
exception- the exception to convert- Returns:
- a response
- See Also:
buildResponse(JaxrsException)
-
buildResponse
public static javax.ws.rs.core.Response buildResponse(JaxrsException exception)
Convert the givenJaxrsExceptionto a JSON response.The response entity contains the information in the JaxrsException.
- Parameters:
exception- the exception to convert- Returns:
- a response
- See Also:
buildResponseEntity(JaxrsException)
-
buildResponseBuilder
public static javax.ws.rs.core.Response.ResponseBuilder buildResponseBuilder(JaxrsException exception)
Convert the givenJaxrsExceptionto a JSON response builder.The response entity contains the information in the JaxrsException.
- Parameters:
exception- the exception to convert- Returns:
- a response builder
- See Also:
buildResponseEntity(JaxrsException)
-
buildResponseEntity
public static Map<String,Object> buildResponseEntity(JaxrsException exception)
Convert the givenJaxrsExceptionto a map that can be used as a JSON response entity.The response entity will contain an "errors" key containing the
ErrorMessageobjects. If the exception contains any other data (JaxrsException.getOtherData()), those key/value pairs are also included in the response entity. See the note inJaxrsException.setOtherData(Map)regarding the behavior ifotherDatacontains an "errors" key.- Parameters:
exception- the exception to convert- Returns:
- a map that can be used as a response entity
- See Also:
JaxrsException.getOtherData(),JaxrsException.setOtherData(Map)
-
toJaxrsException
public static JaxrsException toJaxrsException(javax.ws.rs.core.Response response)
Convert the givenResponseto aJaxrsException.Attempts to convert a response entity into errors and other data in the resulting exception using
toJaxrsException(int, Map).- Parameters:
response- the response to convert- Returns:
- a new exception instance, or null if the response is null
- See Also:
toJaxrsException(int, Map)
-
toJaxrsException
public static JaxrsException toJaxrsException(int status, Map<String,Object> entity)
Convert the given HTTP status code and an entity into aJaxrsException.Looks for an entry with key "errors" and a list of objects, and attempts to convert them into
ErrorMessageobjects. The conversion from a generic map to anErrorMessageis done usingErrorMessage.valueOf(Map).Any other entries in the map are converted to "other data" in the exception.
- Parameters:
status- the HTTP statusentity- the entity as a map- Returns:
- a new exception instance
- See Also:
JaxrsException.setErrors(List),JaxrsException.setOtherData(Map)
-
-