Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-4143

CxfPayload to Node conversion is not working properly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.8.0
    • 2.7.3, 2.8.0
    • camel-cxf
    • None
    • Patch Available
    • Unit Test Broken

    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.

      Attachments

        1. CxfPayloadConverter.patch
          0.8 kB
          Alexey Venderov

        Activity

          People

            njiang Willem Jiang
            avenderov Alexey Venderov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: