What may be happening is that you have a sequence of writeCharacters events - you may need to buffer them and flush as a single CData block upon receiving the endofelement event, something like that

Cheers, Sergey
On 19/09/16 15:27, xavi.dive.kite wrote:
I'm consuming a web service using CXF, the thing is that I need to send and
XML inside a CDATA tag. To do it I created an interceptor

public class CDATAInterceptor extends AbstractPhaseInterceptor<Message>

    public CDATAInterceptor() {

    public void handleMessage(Message message) {
        message.put("disable.outputstream.optimization", Boolean.TRUE);
        XMLStreamWriter writer = (XMLStreamWriter)
        if (writer != null && !(writer instanceof CDataXMLStreamWriter)) {
            message.setContent(XMLStreamWriter.class, new

    public void handleFault(Message messageParam) {
I am using a custom CDATAXMLStreamWriter defined as follows:

public class CDataXMLStreamWriter extends DelegatingXMLStreamWriter {

    private static final Pattern XML_CHARS = Pattern.compile( "[&<>]" );

    public CDataXMLStreamWriter(XMLStreamWriter del) {

    public void writeCharacters(String text) throws XMLStreamException {
        boolean useCData = XML_CHARS.matcher( text ).find();
        if (useCData) {
        }else {

    public void writeStartElement(String local) throws XMLStreamException {
I configured this CDATA interceptor as follows

protected void configureCDataInterceptor() {
    CDATAInterceptor inter = new CDATAInterceptor();
The issue I have is that the xml inside CDATA is splitted in multiple parts,
somthing like this

I tried getting the XML and removing all the newline characters and the XML
gets inside one CDATA block, but the issue with this is that this XML is
signed, and removing the characters breaks the signature.

I hope this was clear enough, and sorry if the post is hard to understand.
If you can give me one clue to solve this problem it would be great!


View this message in context: 
Sent from the cxf-user mailing list archive at Nabble.com.

Sergey Beryozkin

Talend Community Coders

Reply via email to