如果给定的 SOAP 标头元素具有给定值(例如,如果标头标记“response”的值为“0”),我根本不希望 Apache CXF 返回响应。
我怎样才能做到这一点? CXF 似乎假设所有呼叫都会收到响应。
(我知道这在 Web 服务上下文中看起来很奇怪,但如果您的传输是 JMS,则似乎不那么奇怪)。
我已经能够使用中止拦截器链的拦截器来做到这一点。
我已经使用 HTTP 配置(WebSphere 返回空的 200)和 ActiveMQ 配置(没有响应返回到响应队列)对此进行了测试。
package my.super.interceptor;
public final class Suppressor extends AbstractSoapInterceptor {
public Suppressor() { super(Phase.SETUP); }
@Override
public void handleMessage(final SoapMessage message) throws Fault
{
final boolean suppressResponse = this.suppressResponse(message);
if(suppressResponse) {
log.debug("-> Suppressing response");
message.getInterceptorChain().abort();
}
//if you want to suppress both responses and faults, you need
//to check them separately.
//Change this code to check headers for whatever criteria you want
//(Note you may need to change the super(Phase...) )
//The code's a bit messy here - just sketching out the idea for the answer
private boolean suppressResponse(final Message message) {
final Fault fault = (Fault)message.getContent(Exception.class);
if(fault != null) {
final String faultMessage = fault.getMessage();
return faultMessage.indexOf("Something-you-want-to-match") > 0;
} else {
final MessageInfo messageInfo = (MessageInfo)message.get("org.apache.cxf.service.model.MessageInfo");
final String operation = messageInfo.getOperation().getOutputName();
return operation.indexOf("Something-you-want-to-match") > 0;
}
}
和你的applicationContext.xml:
<jaxws:endpoint ...>
<jaxws:outInterceptors>
<bean class="my.super.interceptor.Suppressor"/>
</jaxws:outInterceptors>
<jaxws:outFaultInterceptors>
<bean class="my.super.interceptor.Suppressor"/>
</jaxws:outFaultInterceptors>
</jaxws:endpoint>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)