在ExceptionMapper创建响应时,不会遍历RestEasy Post Process Interceptor链 [英] RestEasy Post Process Interceptor chain not traversed when response created by ExceptionMapper

查看:103
本文介绍了在ExceptionMapper创建响应时,不会遍历RestEasy Post Process Interceptor链的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用RestEasy构建我的Restful Web服务。我已经实现了ExceptionMappers来准备特定的异常响应。

I am using RestEasy to build up my Restful web services. I have implemented ExceptionMappers to prepare specific exception responses.

我还实现了MessageBodyWriterInterceptors和几个PostProcessorInterceptors。

I have also implemented MessageBodyWriterInterceptors and a couple of PostProcessorInterceptors.

问题:当任何资源没有抛出任何异常时,一切正常。我的实现按预期工作。调用所有后处理器拦截器和消息体编写器拦截器。

Issue: All works fine when any resource does not throw any exception. My implementation works as expected. All the post processor interceptors and the message body writer interceptors are called.

但是当从任何资源方法抛出异常时,将调用已注册的ExceptionMappers并且它是创建响应。但在这种情况下,不会遍历后处理器拦截器链。它们没有被调用。

But when an exception is thrown from any of the resource methods, the registered ExceptionMappers are called and it is creating the response. But in this case the post processor interceptor chain is not traversed. They are not getting called.

在这种情况下我该怎么做。在我的异常映射器中写入该拦截器逻辑,或者是否有可用的解决方案?

What should I do in this case. Write that interceptor logic in my exception mapper or is there is solution available?

推荐答案

如果异常是,则不会调用后处理器抛出。它们位于不同的并行分辨率路径上:

Post processors do not get called if an exception is thrown. They are on different, parallel resolution paths:


           / 'Normal' JAX-RS response -> Post Processors -> Message Body Writers
Processing
           \  Exception -> Exception Mappers

如果你的逻辑需要在两个后处理器中运行然后你需要将它合并到两者中(最好通过一个普通的实用类)。

If you have logic that needs to be run in both your post processors and exception mappers then you will need to incorporate it in both (preferably through a common, utility class).

这篇关于在ExceptionMapper创建响应时,不会遍历RestEasy Post Process Interceptor链的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆