【问题标题】:RestEasy custom action on every request针对每个请求的 RestEasy 自定义操作
【发布时间】:2013-10-04 07:22:23
【问题描述】:

我想在 REST 调用完成后调用一些自定义方法,查找原始方法的注释和生成的响应。

我知道您可以使用 PostProcessInterceptorMessageBodyWriterInterceptor 来执行此任务,但它们不会在出现异常时被调用。

我目前的解决方案是,每个方法都会引发一个特殊异常,然后由自定义 ExceptionMapper 处理,但我没有关于原始请求及其来源的信息。

您是否可以绑定一个全局范围的处理程序,以便在发生异常时获取有关原始请求的信息?

是的,我知道这个问题:RestEasy Post Process Interceptor chain not traversed when response created by ExceptionMapper

【问题讨论】:

    标签: java resteasy


    【解决方案1】:

    回答我自己的问题。

    可以将原始请求注入ExceptionMapper 并做出相应的反应或执行自定义操作。

    @Provider
    public class MyExceptionMapper implements ExceptionMapper<Throwable> {
    
    
        @Context
        private HttpServletRequest request;
    
        @Override
        public Response toResponse(Throwable exception)
        {
    
             // trigger event
             triggerOnExceptionEvent(request, exception);
        }
    ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-30
      • 1970-01-01
      • 2012-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多