我們目前在Jboss EAP 6.2上使用CXF 2.7.3時遇到了自定義SoapFault異常問題。CXF webservice:攔截器未觸發
子碼和它的價值,當我們發送自定義的SOAPFault不顯示:
這是我們希望從CXF什麼:
<?xml version="1.0" encoding="UTF-8"?>
<tns:Fault
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tns="http://www.w3.org/2003/05/soap-envelope">
<tns:Code>
<tns:Value>tns:Sender</tns:Value>
<tns:Subcode>
<tns:Value>value</tns:Value>
</tns:Subcode>
</tns:Code>
<tns:Reason>
<tns:Text xml:lang="fr">
****
</tns:Text>
</tns:Reason>
<tns:Detail>
**Custom fault***
</tns:Detail>
</tns:Fault>
這裏是我們至今:
<?xml version="1.0" encoding="UTF-8"?>
<tns:Fault
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tns="http://www.w3.org/2003/05/soap-envelope">
<tns:Code>
<tns:Value>tns:Sender</tns:Value>
</tns:Code>
<tns:Reason>
<tns:Text xml:lang="fr">
****
</tns:Text>
</tns:Reason>
<tns:Detail>
**Custom fault***
</tns:Detail>
</tns:Fault>
子代碼完全丟失。
我們試圖使用自定義攔截器從CXF像這樣(從LoggingOutInterceptor或AbstractInterceptor延伸)攔截定製故障:
public class SoapRequestInterceptor extends LoggingOutInterceptor {
private static Logger log = Logger.getLogger(SoapRequestInterceptor.class);
public SoapRequestInterceptor() {
super(Phase.MARSHAL);
}
public void handleMessage(SoapMessage message) throws Fault{
SoapMessage soapMessage = message.getContent(SoapMessage.class);
if (soapMessage != null) {
log.info("request intercepted:" + soapMessage.toString());
}
}
}
攔截,當我們他要麼添加到CXF總線甚至不叫或到jaxws攔截器(它在應用程序的開始時添加,雖然它通過構造函數獲取)。 我們如何攔截一個自定義的肥皂故障信息並在CXF中進行編輯?
非常感謝!
至於問這裏是我們宣告春天的applicationContext.xml攔截方式:
<cxf:bus>
<cxf:outFaultInterceptors>
<ref bean="soapRequestInterceptor" />
</cxf:outFaultInterceptors>
</cxf:bus>
<bean id="soapRequestInterceptor" class="fr.test.SoapRequestInterceptor" />
<jaxws:server serviceClass="fr.test.PriseEnChargeB2ServiceSP"
address="" serviceBean="#service">
<jaxws:binding>
<soap:soapBinding version="1.2" mtomEnabled="true" />
</jaxws:binding>
</jaxws:server>
注:攔截器以及instancied,但是從我們的WS
的肥皂斷層落差後不叫在我們的WS結尾拋出的異常是這樣的:
public class PecSoapFaultException extends SoapFault {
private static final long serialVersionUID = 1L;
public TypeErreur erreur;
public PecSoapFaultException(String message, TypeErreur structure) {
super(message, new QName(""));
this.erreur = structure;
}
public PecSoapFaultException(String message, TypeErreur structure, QName faultcode) {
super(message, faultcode);
this.erreur = structure;
}
public PecSoapFaultException(String message, TypeErreur structure, QName faultcode,
QName subcode) {
super(message, faultcode);
this.setSubCode(subcode);
this.erreur = structure;
}
public TypeErreur getFaultInfo() {
return erreur;
}
你能發佈你已經試圖添加攔截器嗎? – Frank
以這種方式編輯,所以您確認Interceptor是我們需求的良策? – Sid
看起來很對。我會擴展AbstractPhaseInterceptor而不是LoggingOutInterceptor,但這不是必需的。你怎麼知道你的攔截器沒有被調用?您是否在'SoapMessage soapMessage = message.getContent(SoapMessage.class);'?中設置了斷點?如果你喜歡處理一個錯誤,你應該有'Fault fault =(Fault)message.getContent(Exception.class);'而不是在發生錯誤的情況下得到SoapMessage爲null。 – Frank