Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lmedinar-va opened this issue Mar 16, 2023 · 1 comment

Comments

@lmedinar-va
Copy link

lmedinar-va commented Mar 16, 2023

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?

@corneil
Copy link
Contributor

corneil commented May 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants