3 Replies Latest reply on Oct 10, 2013 7:31 AM by arun.parihar

    JAXB Marshalling and Character Escape Hander

    rodders-miller

      I have a JAX-B annotated class that contains an String element that has the contents of a CDATA section

       

      e.g.

       

      <![CDATA[ SOME CDATA HERE ]]>

       

      When utilising the JAX-B marshalling availible in camel via

       

      JaxbDataFormat jaxbFormatter = new JaxbDataFormat( "location of schema");

       

      from("some URI").marshal(jaxbFormatter);

       

      The output appears as character escaped e.g.:

       

      &lt;![CDATA[SOME CDATA HERE]] ]]&gt;

       

      Previously in plain java I have got round the problem by using a charater escape handler:

       

      JAXBContext context = JAXBContext.newInstance(myClass.class);     

       

      Marshaller marshaller = context.createMarshaller();               

                                          

      // Add an handler to prevent the CDATA section from being removed

      marshaller.setProperty( "com.sun.xml.bind.characterEscapeHandler", new CdataCharacterEscapeHandle());  

       

      java.io.StringWriter sw = new StringWriter();

      marshaller.marshal(alarm, sw);

       

      Is there a mechanism to set properties on the marshaller used in Camel, or is there an alternative sollution that I can utilised in Camel to marshall my CDATA?

        • 1. Re: JAXB Marshalling and Character Escape Hander
          davsclaus

          Hi

           

          I dont think we have this easily support out of the box in camel-jaxb component.

           

          Is the class CdataCharacterEscapeHandle a handler you write yourself or where is the class provided if not?

          • 2. Re: JAXB Marshalling and Character Escape Hander
            rodders-miller

            Thanks for the response -

             

            The handler is a custmer handler I wrote myself - it is very simple and basically leaves the content unchange.

             

            This handler therefore only works if I assume that no content needs escaping - obviosuly not something that would work in general.

             

            My scheme also assumes the use of the Sun implementation of Jax-b and I beleive other implementations have different mechanism for handling the same - so I guess it would be difficult to support in Camel.

             

            Is there a way of inserting the CDATA section after the marshalling into the XML using XPATH or similar within the Camel route?

            • 3. Re: JAXB Marshalling and Character Escape Hander
              arun.parihar

              I am using 7.1.0.fuse-047 version of Fuse ESB and Camel 2.10.4 and am facing same issue of character encoding of CDATA section in a String element while camel-jaxb unmarshalling.

              Does camel-jaxb component has now support for the String element with CDATA section?

               

              Thanks in advance