2017-01-02 55 views
0

我想了解JAX-RS的逻辑与ExceptionMapperExceptionMapper如何在EVAX中使用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

这是逻辑吗?

谁打电话给这个方法?其中是从

interface ExceptionMapper 

回答

1

该方法toResponse呼叫的JAX-RS框架并自动调用此当指定类型(此处为:ApiException)的异常传播出去的资源的方法。

+0

它如何与everrest合作? – user1365697

+1

“everrest”是指SerfJ(http://serfj.sourceforge.net/),对不对?它确实实现了JAX-RS标准,所以它的行为方式相同,因为异常映射器是由JAX-RS定义的。 – gsl