ExceptionMapper如何使用JAX-RS在EVERREST中工作?

时间:2017-01-02 13:49:55

标签: jersey jax-rs codenvy javax

我想了解带有ExceptionMapper的JAX-RS的逻辑

假设我有课

    @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) {
            ........
        }
    }

如何打电话给这堂课? 我看到有类ApplicationPrivderBinder,它有方法getExceptionMapper

这是逻辑吗?

谁打电话给这种方法?从

调用方法toResponse的位置
interface ExceptionMapper

1 个答案:

答案 0 :(得分:1)

当指定类型的异常(此处为:ApiException)传播出资源方法时,JAX-RS框架会自动调用此方法。