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

RestTemplate POST and PUT don't work with Netty4ClientHttpRequestFactory [SPR-14860] #19426

spring-projects-issues opened this issue Oct 29, 2016 · 2 comments


Copy link

@spring-projects-issues spring-projects-issues commented Oct 29, 2016

Emanuel Seidinger opened SPR-14860 and commented

When configuring the RestTemplateBuilder using the Netty4ClientHttpRequestFactory I get an error message when making PUT or POST requests with the built RestTemplate:

Failed to read HTTP message:... HttpMessageNotReadableException: Required request body is missing
When I use SimpleClientHttpRequestFactory everything works fine.

I use the following Netty dependency:
compile 'io.netty:netty-all:4.1.6.Final'

A sample project illustrating the problem can be found here:

I first thought it's a Spring Boot issue with the TestRestTemplate only, because creating a RestTemplate using its constructor worked. But it turned out that the TestRestTemplate was automatically configured to use the Netty4ClientHttpRequestFactory when it finds Netty on the classpath and configuring the RestTemplate with the Netty4ClientHttpRequestFactory resulted in the same problem. The issue can be found here:

Affects: 4.3.3

Reference URL: spring-projects/spring-boot#7240

Issue Links:

  • #17232 Netty4ClientHttpRequestFactory buffers (aggregates) all requests/responses
  • #19310 Netty4ClientHttpRequestFactory should configure a default SslContext
  • #19806 RestTemplate with Netty produces two Content-Length headers
  • #19507 Support for Jetty 9.4 (and 9.3.15+)

Referenced from: commits ec8391a, 9d37472

2 votes, 7 watchers

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 4, 2016

Juergen Hoeller commented

Probably the same cause: Our RestTemplateIntegrationTests all pass against HttpComponentsClientHttpRequestFactory as well as OkHttp3ClientHttpRequestFactory, but the jsonPostForObject* tests fail against Netty4ClientHttpRequestFactory.

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 7, 2016

Juergen Hoeller commented

Experimenting a bit further with RestTemplateIntegrationTests, our Netty client adapter seems to simply not send a request body for POST requests. Enforcing a content length header through nettyRequest.headers().set(HttpHeaders.CONTENT_LENGTH, nettyRequest.content().readableBytes()) (in createFullHttpRequest) seems to work that case work but we're not really doing that in any other client adapter...

Let's leave this as a known issue for the time being and sort it out properly for 4.3.5.

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.