Search code examples
javaxmlspringjax-wscdata

JAX-WS + Spring : force CDATA on some inputs


I currently have a problem using Spring + JAX-WS. I have a method with @Webmethod, which returns a custom object. In this object, there are some String fields that may contain some HTML...

The XML produced is good, except when there is HTML in one of the fields, so I'm trying to add a cdata node to prevent escaping, but it doesn't succeed :(

I tried adding @XmlCDATA using EclipseLink JAXB (MOXy), but it seems to have no effects.

There is also a strange thing, sometimes a CDATA node is added automatically, without changing anything, but with the same string duplicated twice and concatened, or with a part of the string (eg "The sentence" => "The sentence The sentence"), the CDATA node is not present anymore. I can't determine when the CDATA is added, or why it is'nt added every time, it seems to be random (but of course I think it's not).

Anyone has a suggestion on how to force the CDATA node in Spring (annotations, xml config, other...) ? Thanks


Solution

  • You can either add CDATA or properly encode your HTML before adding it to the XML.

    I'd wonder why you need to send HTML (client side stuff) to a SOAP service. Could be a bad design.