CXF/MessageFactory accepts malformed XML due to MessageFactory

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

CXF/MessageFactory accepts malformed XML due to MessageFactory

Bhun Kho
Hi [hidden email],

Is there anyway I can get the MessageFactory used by CXF to behave properly and reject
malformed XML?

I have a SOAP-service implemented as a @WebServiceProvider JAX-WS Provider (see [1] for the 'skeleton'),
somehow the webservice accepts malformed XML, when it's missing 'uninteresting' end-tags,
such as </Envelope> [2].

This seems to be caused by the usage of MessageFactory somewhere in the ws-stack.

I gutted one of the unittests from the cxf that shows the same behavior:
- [ see testSOAPMessage-method]
- malformed xml in the test due to removal of the last 'Envelope'-closing tag
  - path: systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/resources/GreetMeDocLiteralReq.xml
  - expected outcome for the test is that fails earlier (instead of the fail()-I added)

Thanks in advance for any help,


[1] skeleton implementation:

public class MySoapService implements<Source> {

    public Source invoke(javax.xml.transform.Source source) {



[2] basically this is the bug 'somewhere in the stack':

import org.junit.Assert;
import org.junit.Test;

import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPException;

public class MessageTest {

    public void malformedXml() throws SOAPException, IOException {
        var  messageFactory = MessageFactory.newInstance();
        var message = messageFactory.createMessage(null, new ByteArrayInputStream((
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?><z:Envelope xmlns:z=\"\" xmlns:u=\"\" xmlns:wsse=\"\" xmlns:x=\"urn:nl-gdi-eid:1.0:webservices\">\n" +
                        "<z:Header>\n" +
                        "</z:Header>\n" +

        ).getBytes()));; //<--- should not be reaching this??