我必须将版本更新为 camel-core-2.16.0 &来自 camel-core-2.15.3 &的 CXF-core-3.1.3.jar CXF-core-3.0.6.jar ,以避免类似于此 Apache Camel - Receiving SOAP response with empty body 的问题,这已解决了我的搜索目的。
但是现在即使我正确地得到了响应主体,在我的日志中我得到了一个unmarshall异常,当我使用以前版本的jar时我没有遇到过。
这是代码片段,它给出了异常:
public static Object getPojoFromCXFPayload(CxfPayload payload, Class pojoClass) throws Exception {
List<Source> outElements = payload.getBodySources();
XmlConverter converter = new XmlConverter();
DOMSource domsource = null;
Object pojo = null;
if (outElements != null && outElements.size() > 0) {
if(DEBUG)
logger.debug("outElements size is " + outElements.size());
domsource = converter.toDOMSource(outElements.get(0));
//JAXBContext context = JAXBContext.newInstance(pojoClass);
JAXBContext context = JaxContextInitilizer.getContext();
Unmarshaller m = context.createUnmarshaller();
if (domsource.getNode().getNodeType() == Node.ELEMENT_NODE) {
if(DEBUG){
logger.debug("This is element node");
}
} else if (domsource.getNode().getNodeType() == Node.DOCUMENT_NODE) {
if(DEBUG){
logger.debug("this is document node");
}
((Document) domsource.getNode()).getDocumentElement();
if(DEBUG){
logger.debug(((Document) domsource.getNode()).getDocumentElement());
}
}
pojo = m.unmarshal(domsource.getNode()); //I could see the exception pointing to this line
}
return pojo;
}