Hi

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() {
        super(Phase.MARSHAL);
        //addAfter(AttachmentOutInterceptor.class.getName());
    }

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

    public void handleFault(Message messageParam) {
        System.out.println(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) {
        super(del);
    }

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

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

protected void configureCDataInterceptor() {
    CDATAInterceptor inter = new CDATAInterceptor();
    ClientProxy.getClient(this.clientProxy).getOutInterceptors().add(inter);
}
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!

Thanks,



--
View this message in context: 
http://cxf.547215.n5.nabble.com/Include-signed-XML-into-a-single-CDATA-tp5772863.html
Sent from the cxf-user mailing list archive at Nabble.com.



--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Reply via email to