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

Gateway MVC: space character in POSTed JSON leads to IOException: insufficient data written #3401

Open
mindhaq opened this issue May 17, 2024 · 1 comment

Comments

@mindhaq
Copy link

mindhaq commented May 17, 2024

Describe the bug

I'm using spring-boot 3.2.5 with spring cloud 2023.0.1 and JDK 21

I'm using Proxy Exchange Gateway with Spring MVC.

When I POST JSON data to a proxy controller that contains a space character, the proxy exchange fails with the exception in the title:

java.io.IOException: insufficient data written
	at java.base/sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.close(HttpURLConnection.java:3848) ~[na:na]
	at org.springframework.http.client.SimpleClientHttpRequest.executeInternal(SimpleClientHttpRequest.java:84) ~[spring-web-6.1.6.jar:6.1.6]
	at org.springframework.http.client.AbstractStreamingClientHttpRequest.executeInternal(AbstractStreamingClientHttpRequest.java:70) ~[spring-web-6.1.6.jar:6.1.6]
	at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:66) ~[spring-web-6.1.6.jar:6.1.6]
	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:889) ~[spring-web-6.1.6.jar:6.1.6]
	at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:740) ~[spring-web-6.1.6.jar:6.1.6]
	at org.springframework.cloud.gateway.mvc.ProxyExchange.exchange(ProxyExchange.java:347) ~[spring-cloud-gateway-mvc-4.1.2.jar:4.1.2]
	at org.springframework.cloud.gateway.mvc.ProxyExchange.post(ProxyExchange.java:308) ~[spring-cloud-gateway-mvc-4.1.2.jar:4.1.2]
	at com.mindhaq.demogatewayproxy.GatewayController.handlePost(GatewayController.kt:17) ~[main/:na]

       ....

With everything being the same, but not having any space characters in the JSON, there is no problem.

This was found while migrating a spring-boot monolith running on boot 2.2.x with netflix zuul which was updated to spring boot 3.2.x, cloud gateway, latest JDK etc. It took quite some time to reduce the error scenario to this.

Sample

I created a sample repository which proxies requests to httpbin.org

https://github.com/mindhaq/spring-demo-gateway-proxyexchange-mvc

This request fails with the exception above:

curl -X POST -H "Content-Type: application/json" -d '{"foo": "bar"}' http://localhost:8080/post 

This one works just fine:

curl -X POST -H "Content-Type: application/json" -d '{"foo":"bar"}' http://localhost:8080/post 

Going directly to httpbin.org works in both cases, so that is not the problem.

Do I miss any configuration or is this some deeper lying bug which got revealed by that space character?

@mindhaq
Copy link
Author

mindhaq commented May 18, 2024

It might be related to #3154

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

No branches or pull requests

1 participant