我正在使用Apache CXF和Spring開發Web服務。我的界面和配置已配置好,以便我擁有REST和SOAP服務。 Apache CXF沒有把XML文檔啓動:<?xml version="1.0" encoding="UTF-8"?>
Apache CXF JAX-RS服務缺少XML文檔啓動
對於SOAP服務,我實現了一個攔截器,它的工作原理完美。下面的代碼:
public class CustomHeaderInterceptor extends AbstractPhaseInterceptor<Message> {
public CustomHeaderInterceptor() {
super(Phase.PRE_STREAM);
addBefore(StaxOutInterceptor.class.getName());
}
@Override
public void handleMessage(Message message) throws Fault {
message.put(Message.ENCODING, "UTF-8");
message.put(StaxOutInterceptor.FORCE_START_DOCUMENT, Boolean.TRUE);
}
}
攔截器與以下配置增加:
<bean id="customHeader" class="com.minervanetworks.xtv.stb.utils.CustomHeaderInterceptor" />
<cxf:bus>
<cxf:inInterceptors>
<ref bean="logInbound" />
</cxf:inInterceptors>
<cxf:outInterceptors>
<ref bean="customHeader" />
<ref bean="logOutbound" />
</cxf:outInterceptors>
<cxf:inFaultInterceptors>
<ref bean="logInbound" />
</cxf:inFaultInterceptors>
<cxf:outFaultInterceptors>
<ref bean="logOutbound" />
</cxf:outFaultInterceptors>
</cxf:bus>
不幸的是這不適合我的JAX-RS服務器的工作。 「StaxOutInterceptor.FORCE_START_DOCUMENT」由StaxOutInterceptor處理,當我使用JAX-RS時它不在鏈中。它不能手動添加,因爲它依賴於處於*結束階段的StaxOutEndingInterceptor,並在JAXRSOutInterceptor之後調用。
我也嘗試實現處理程序爲同一目的,但沒有任何成功。
這裏是我的JAXRS服務器配置:
<jaxrs:server id="restServer" address="/rest">
<jaxrs:providers>
<ref bean="systemExceptionMapper" />
<ref bean="jaxbProvider" />
</jaxrs:providers>
<jaxrs:serviceBeans>
...
</jaxrs:serviceBeans>
<jaxrs:extensionMappings>
<entry key="json" value="application/json" />
<entry key="xml" value="application/xml" />
<entry key="feed" value="application/atom+xml" />
<entry key="html" value="text/html" />
</jaxrs:extensionMappings>
</jaxrs:server>
任何形式的幫助 - 意見,建議,無論將appriciated!
+1與社區分享您的解決方案。你還應該將自己的問題標記爲答案。 – sra