override http status with cxf

心不动则不痛 提交于 2020-01-05 03:30:13

问题


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" })

and this is the interceptor:

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");
}}

回答1:


Can you try

msg.put(SoapMessage.RESPONSE_CODE, 200);

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



来源:https://stackoverflow.com/questions/6800473/override-http-status-with-cxf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!