使用cxf覆盖http状态 [英] override http status with cxf

查看:104
本文介绍了使用cxf覆盖http状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将CXF用于网络服务。
由于某些客户端限制,我需要所有网络错误来返回代码200而不是500。
我尝试使用拦截器,具体取决于我能够覆盖状态的阶段,然后响应是为空或响应充满故障,但状态不会被覆盖。
有什么想法怎么做?
使用拦截器,正确的相位是什么?
我是这样注册拦截器的:

I'm using CXF for web services. Because of some client restrictions, I need all web faults to return code 200 instead of 500. I tried to use interceptors, depends on the phase I was able to either override the status and then the response is empty or the response is full with the fault but then the status is not overridden. Any ideas how to do that? Using interceptors, what would be the right phase? I registered the interceptor like this:

@org.apache.cxf.interceptor.OutFaultInterceptors(interceptors = { "com.my.prod.core.service.itercept.HttpStatusInterceptor" })

这是拦截器:

public class HttpStatusInterceptor extends AbstractSoapInterceptor {

public HttpStatusInterceptor(){
    super(Phase.POST_STREAM_ENDING);
}

@Override public void handleMessage(org.apache.cxf.binding.soap.SoapMessage msg) throws org.apache.cxf.interceptor.Fault{
    msg.put(SoapMessage.RESPONSE_CODE, "200");
}}


推荐答案

可以尝试

msg.put(SoapMessage.RESPONSE_CODE, 200);

因此它最终以as和Integer对象而不是String结束。我认为这是整数。

so it ends up as and Integer object instead of a String. I think it's expecting the integer.

这篇关于使用cxf覆盖http状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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