简体   繁体   English

骆驼CXF cxfPayload StaxSource响应

[英]Camel CXF cxfPayload StaxSource response

Hello I am using a camel(2.17.0) cxf endpoint with dataformat = Payload. 您好,我正在使用骆驼(2.17.0)cxf端点,其数据格式=有效负载。 I have a processor to handle the response: 我有一个处理器来处理响应:

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

I get a CxfPayload with a StaxSource as a body. 我得到一个带有StaxSource作为主体的CxfPayload。 Any convertion to String fails because of the staxSource body. 由于staxSource主体,任何到String的转换都会失败。 I tried convertBodyTo(String.class) and getIn.getBody(String.class) in the responseProcessor. 我在responseProcessor中尝试了convertBodyTo(String.class)和getIn.getBody(String.class)。 How can I convert it to a String XML? 如何将其转换为String XML?

A CXF StaxSource is a JAXP Source so the standard way of converting it to a String would be to use the transformation API (TrAX) : 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();

Which is a the idiomatic JAXP way of serializing XML to a String. 这是将XML序列化为String的惯用JAXP方法。

Camel supports the conversion in its Camel CxfPayloadConverter. Camel在其Camel CxfPayloadConverter中支持转换。 The problem was solved by removing camel-cache dependency as it had a dependency "clash" with the camel converter. 通过删除骆驼缓存的依赖关系解决了该问题,因为它与骆驼转换器有依赖关系“冲突”。 It uses an older version of xalan for transformer 它使用较旧版本的xalan进行变压器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM