0

We have been very successful to carry out POJO to/from XML conversion within Camel. The following code exemplifies a typical case how we use Camel. Our application listens to an Oracle AQ. The queue entry is an xml String. The xml is then converted to POJO class (MyClass), we then do some transformation on the MyClass with data from other source. After this transformation, POJO object is converted back to a string and sent to other system (here we save to a file)

<route id="testing">

<from uri="oracleaq:queue:FUSEQUEUE"/>  

<convertBodyTo type="generated.MyClass"/>

<bean ref="mainReqprocessor" method="Modify"/>
<convertBodyTo type="java.lang.String"/>
<setHeader headerName="Exchange.FILE_NAME">
    <simple>output.xml</simple>
 </setHeader>
 <to uri="file:C:\\Temp\\OUT"/>
</route>

Everything works fine until yesterday when we introduced html tags into one of the text field of the POJO class. We wrapped the text with CData "<![CDATA[" + str + "]]>". But, when the POJO is converted to string, the encoding still occurred on the starting and ending brackets of CGata section, such as the following. Because of this, the resulting xml string is not valid xml any more, and therefore can not be converted back to MyClass for other application. This is not the desired behavior. How can I avoid the encoding on CDATA starting and ending brackets?[Notes: the first < and the last > in the cdata are encoded.]

<TEXT>

&amp;lt;![CDATA[&amp;lt;html&amp;gt;&amp;lt;div&amp;gt;&amp;lt;pre&amp;gt;COMPONENT PARTS.&amp;lt;/br&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/pre&amp;gt;&amp;lt;/html&amp;gt;]]&amp;gt;

<\/TEXT>
Chris W
  • 21
  • 1
  • 9

1 Answers1

1

Although you have a marshalling/unmarshalling problem, you don't mention how you convert the XML to POJO and back. This would be a very important information to help.

If you are using JAXB for the conversion, this Q/A could perhaps help you: JAXB Marshalling Unmarshalling with CDATA

burki
  • 6,741
  • 1
  • 15
  • 31
  • the link you mentioned has very interesting and useful discussion. After a POJO object is setup , for example by a processor, a in blueprint.xml will convert POJO to xml String. I also tried to marshall the POJO within a processor using JAXB, same result is obtained. I decide not to include html tags in xml elements. – Chris W Jun 16 '18 at 11:21