【发布时间】:2015-08-18 11:54:31
【问题描述】:
我使用 Apache CXF 开发了 Rest 应用程序 (JAX RS)。
CXF 配置:
<jaxrs:server id="InternalRS" address="/V1">
<jaxrs:serviceBeans>
<ref bean="InternalService" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jsonProvider" />
</jaxrs:providers>
<jaxrs:inInterceptors>
<bean id="CustomInterceptor"
class="com.test.web.interceptor.CustomInterceptor">
</bean>
</jaxrs:inInterceptors>
</jaxrs:server>
入站拦截器:
public class CustomInterceptor extends AbstractPhaseInterceptor<Message> {
public CustomInterceptor() {
super(Phase.READ);
}
@Override
public void handleMessage(Message message) throws Fault {
HttpServletRequest request = (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST);
Transaction transaction = new Transaction();
String id = request.getHeader("id");
transaction.setId(id);
message.getExchange().put("transaction", transaction);
}
}
有什么方法可以通过使用出站拦截器修改 JSON 响应,将我的应用程序抛出的业务异常转换为其等效的 HTTP 状态代码。
【问题讨论】: