spring-projects/spring-ws

Using WebServiceTemplate.marshalSendAndReceive with a field that contains "\b" results in an empty generated field

lmedinar-va opened this issue · 1 comments

In my application, we expose a REST interface, generate SOAP requests, and send those to a backend SOAP service.

In this special case, whenever an user passes the "\b" sequence in their JSON request (lets call the field "text"), the resulting XML message field (lets call it a <text> element) ends up being empty.

Here's the original text in the request:

Test 1 No backslash characters Test 4 Test either \b both different backslash character

Sample logs, here we see the string as read from the text field in the request with the backspace sequence working as expected:

2023-03-16 15:06:26.002  INFO 18168 --- [nio-8080-exec-2] g.v.a.v.s.c.v.Controller    : Test 1 No backslash characters Test 4 Test either both different backslash character

I have a Jaxb generated class, the following log is from using the getter for the text field after it has been set:

2023-03-16 15:06:26.002  INFO 18168 --- [nio-8080-exec-2] g.v.a.v.s.c.v.Controller    : Test 1 No backslash characters Test 4 Test either /b both different backslash character

Both log entries are the same as expected

Then I use the standard javax.xml.bind.Marshaller to see the resulting XML, this one works as expected:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<writeNote xmlns="http://somenamespace">
	<text>Test 1 No backslash characters Test 4 Test either \b both different backslash character</text>
</writeNote>

This XML is generated like so (uses javax.xml.bind.Marshaller and its impl):

    StringWriter writer = new StringWriter();
    JAXBContext context = JAXBContext.newInstance(WriteNote.class);
    Marshaller marshaller = context.createMarshaller();
    marshaller.marshal(writeNoteSoapRequest, writer);
    log.info(writer.toString());

However, the MessageTracing logs show that the outbound request has an empty element. The following is what's shown when the application runs the marshalSendAndReceive().

2023-03-16 15:04:08.722 TRACE 7016 --- [nio-8080-exec-1] o.s.ws.client.MessageTracing.sent        : Sent request [
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
	<SOAP-ENV:Body>
		<ns2:writeNote xmlns:ns2="http://somenamespace">
			<ns2:text/>
		</ns2:writeNote>
	</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
] (prettyprinted and certain fields omitted)

Is this the expected behavior? Is this a limitation of the marshaller, XML as a format, or maybe a missing configuration in the marshaller and the WebServiceTemplate?

@lmedinar-va A Java String containing \b should be encoded as &x08;