tree: 0418eb26c428101629d37004fd8499d59ee31a04 [path history] [tgz]
  1. src/
  2. pom.xml
  3. README.MD
examples/exception-mapping/README.MD

Exception Mapping Example

This example demonstrates how to create a custom exception mapping. There are described several common use-cases such as WebApplicationException, custom exceptions and an exception mapper inheritance.

The full description how to handle exception and map them to Response object can be found in Jersey User Guide, chapter WebApplicationException and Mapping Exceptions to Responses.

Contents

The mapping of the URI path space is presented in the following table:

URI pathHTTP methodsAllowed ValuesDescription
/exceptionGET---returns “ping!”
/exception/webapplication_entityPOSTtwo numbers delimited by colons e.g. 1:201not handled by WebApplicationExceptionMapper (already has an entity in the exception)
/exception/webapplication_noentityPOSTe.g. 1:201handled by WebApplicationExceptionMapper
/exception/myPOSTe.g. 1:201handled by MyExceptionMapper
/exception/mysubPOSTe.g. 1:201handled by MySubExceptionMapper
/exception/mysubsubPOSTe.g. 1:201handled by MySubExceptionMapper
/exception/request_exceptionPOSTString “Request Exception”not reached a resource method, processed by ContainerRequestFilter
/exception/response_exceptionGET---response handled and changed by ContainerResponseFilter

Application is based on Grizzly container (see App). Everything needed (resources/providers) is registered in ExceptionResource and custom exceptions along with mappers can be found in Exceptions class.

Running the Example

Run the example as follows:

mvn clean compile exec:java

This deploys the example using Grizzly container.