Search code examples
jerseyjax-rscodenvyjavax

How does ExceptionMapper workes in EVERREST with JAX-RS?


I want to understand the logic of JAX-RS with ExceptionMapper

lets assume that I have class

    @Provider
    @Singleton
    public class MyExceptionMapper implements ExceptionMapper<ApiException> {

        /**
         * check the exception type and build Response with the status body and the type of the error
         */
        @Override
        public Response toResponse(ApiException exception) {
            ........
        }
    }

How is call this class ? I saw that there is class ApplicationPrivderBinder that has method getExceptionMapper

Does it is the logic?

Who call to this method ? where is the call to the method toResponse from the

interface ExceptionMapper

Solution

  • The JAX-RS framework does automatically call this when an exception of the specified type (here: ApiException) propagates out of a resource method.