2013-10-04 21 views
1

當REST調用完成時,我想調用一些自定義方法,查找有關原始方法和生成的響應的註釋。RestEasy對每個請求的自定義操作

我知道你可以使用此任務的PostProcessInterceptorMessageBodyWriterInterceptor但他們得到一個異常的情況下調用。

我目前的解決方案是每個方法都拋出一個特殊的異常,然後由自定義的ExceptionMapper處理,但是我沒有關於原始請求的信息以及它來自哪裏。

是否有全局範圍的處理程序可以綁定到以獲取有關原始請求的信息以防萬一出現異常?

是的,我知道這個問題:RestEasy Post Process Interceptor chain not traversed when response created by ExceptionMapper

回答

3

要回答我的問題。

可以將原始請求注入ExceptionMapper並相應地作出反應或執行自定義操作。

@Provider 
public class MyExceptionMapper implements ExceptionMapper<Throwable> { 


    @Context 
    private HttpServletRequest request; 

    @Override 
    public Response toResponse(Throwable exception) 
    { 

     // trigger event 
     triggerOnExceptionEvent(request, exception); 
    } 
... 
}