我創建爲CXF docs描述的SOAP攔截器:的Apache CXF攔截器配置
public class SoapMessageInterceptor extends AbstractSoapInterceptor {
public SoapMessageInterceptor() {
super(Phase.USER_PROTOCOL);
}
public void handleMessage(SoapMessage soapMessage) throws Fault {
// ...
}
}
,並在Spring的應用程序上下文中有公交註冊吧:
<cxf:bus>
<cxf:inInterceptors>
<ref bean="soapMessageInterceptor"/>
</cxf:inInterceptors>
</cxf:bus>
<jaxws:endpoint id="customerWebServiceSoap"
implementor="#customerWebServiceSoapEndpoint"
address="/customerService"/>
所有工作正常,直到我添加了一個REST服務:
<jaxrs:server id="customerWebServiceRest" address="/rest">
<jaxrs:serviceBeans>
<ref bean="customerWebServiceRestEndpoint" />
</jaxrs:serviceBeans>
</jaxrs:server>
問題在於SOAP攔截器現在也在REST請求上被觸發,這導致REST服務被調用時出現類轉換異常。
<ns1:XMLFault xmlns:ns1="http://cxf.apache.org/bindings/xformat">
<ns1:faultstring xmlns:ns1="http://cxf.apache.org/bindings/xformat">
java.lang.ClassCastException: org.apache.cxf.message.XMLMessage
cannot be cast to org.apache.cxf.binding.soap.SoapMessage
</ns1:faultstring>
</ns1:XMLFault>
有什麼方法可以通過配置將攔截器限制爲SOAP消息嗎?
更新
看起來像我錯過了頁面描述這個文檔。 向下滾動到Difference between JAXRS filters and CXF interceptors
但是如果我想在端點之間共享攔截器配置?將它們添加到cxf:bus或jaxws:server不會產生與將它們添加到端點的行爲相同的行爲。 – Dormouse