2017-02-08 98 views
2

你好我正在使用camel(2.17.0)cxf端點與dataformat =有效載荷。我有一個處理器來處理響應:駱駝CXF cxfPayload StaxSource響應

.to("cxf://...) 
.process(new responseProcessor); 

我得到一個帶有StaxSource的CxfPayload作爲正文。由於staxSource正文,任何轉換爲​​字符串都會失敗。我在responseProcessor中嘗試了convertBodyTo(String.class)和getIn.getBody(String.class)。我如何將它轉換爲String XML?

+0

駱駝支持在其駱駝CxfPayloadConverter轉換。該問題通過消除camel-cache依賴性得以解決,因爲它與camel轉換器存在依賴性「衝突」。它使用變壓器的舊版xalan。 – TXdev

回答

0

駱駝支持在其駱駝CxfPayloadConverter轉換。該問題通過消除camel-cache依賴性得以解決,因爲它與camel轉換器存在依賴性「衝突」。它使用變壓器的老版本xalan

0

一個CXF StaxSourceJAXP Source所以它轉換爲String會使用轉換API(TrAX的)的標準方式:

Source source = // your CXF StaxSource; 
StringWriter stringResult = new StringWriter(); 
TransformerFactory.newInstance().newTransformer().transform(source, new StreamResult(stringResult)); 
String message = stringResult.toString(); 

這是一個慣用JAXP方式序列化的XML字符串的。

+0

這裏有一個這種轉換的例子:https://github.com/FuseByExample/cxf-webinars/blob/master/customer-ws-camel-cxf-payload/src/main/java/com/fusesource/customerwscamelcxfpayload/如GPI所說,附加CxfPayloadConverters.java –

+0

可以通過編寫提供的代碼來完成。但是Camel支持Camel CxfPayloadConverter中的轉換。這個問題通過去除我的pom.xml中的camel-cache依賴項解決,因爲它與CxfPayloadConverter之間存在依賴關係「衝突」。它使用舊版xalan進行轉換。看起來像駱駝臭蟲! – TXdev