Details
Description
We are using camel-cxf component and building it from the sources. Also we have slightly modified CxfPayloadConverterTest.testCxfPayloadToNode test, added some additional checks. Here are the changes that were made to the test:
Index: CxfPayloadConverterTest.java =================================================================== --- CxfPayloadConverterTest.java (revision 6644) +++ CxfPayloadConverterTest.java (revision 6686) @@ -49,6 +49,7 @@ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); document = documentBuilder.parse(file); document.getDocumentElement().normalize(); @@ -118,5 +119,13 @@ exchange.getIn().setBody(payload); node = exchange.getIn().getBody(Node.class); assertNotNull(node); + Element root = (Element) node; + assertEquals("root element name", "root", root.getNodeName()); + assertEquals("root element namespace", "http://www.test.org/foo", + root.getNamespaceURI()); + Element bar = (Element) root.getElementsByTagName("bar").item(0); + assertEquals("child element name", "bar", bar.getNodeName()); + assertEquals("child element namespace", "http://www.test.org/foo", + bar.getNamespaceURI()); } }
Since there is no explicit converter from CxfPayload to Node the fallback converter from CxfPayloadConverter is used for this conversion. Fallback converter from CxfPayloadConverter under the hood uses converters from XmlConverter. There are two suitable converters in XmlConverter class which are randomly selected. Some times public Element toDOMElement(Node node) converter is used and some times public Document toDOMDocument(final Node node) converter is used. If public Document toDOMDocument(final Node node) converter is used then test fails with ClassCastException. To avoid this, explicit converter from CxfPayload to Node should be added. Patch that adds CxfPayload to Node converter is provided.