Affects: Spring Framework version: 6.1.4
Previously, I was using Spring Boot 3.1.8 (Spring Framework Version: 6.0.16) with Apache HttpClient5 and RestTemplate. When I upgraded to Spring Boot 3.2.3 (Spring Framework Version: 6.1.4) to use the JDK HttpClient with Rest Template, I was seeing SSLTube(SocketTube(2)) [SimpleAsyncTaskExecutor-2] Too few bytes returned by the publisher (2204/2994)
org.springframework.web.client.ResourceAccessException: I/O error on POST request for <url>: SSLTube(SocketTube(2)) [SimpleAsyncTaskExecutor-2] Too few bytes returned by the publisher (2204/2994)
at org.springframework.web.client.RestTemplate.createResourceAccessException(RestTemplate.java:915)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:895)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:730)
...
...
Caused by: java.io.IOException: SSLTube(SocketTube(2)) [SimpleAsyncTaskExecutor-2] Too few bytes returned by the publisher (2204/2994)
at java.net.http/jdk.internal.net.http.Http1Request$FixedContentSubscriber.onComplete(Http1Request.java:462)
at org.springframework.http.client.OutputStreamPublisher$OutputStreamSubscription.invokeHandler(OutputStreamPublisher.java:338)
The change I made was in buiding the RestTemplate from
@Bean
RestTemplate restTemplate(final RestTemplateBuilder builder) {
return builder
.requestFactory(settings -> ClientHttpRequestFactories.get(settings))
.build();
}
to
@Bean
RestTemplate restTemplate(final RestTemplateBuilder builder) {
return builder
.requestFactory(settings -> ClientHttpRequestFactories.get(JdkClientHttpRequestFactory.class,settings))
.build();
}
and removed the Apache HttpClient5 dependency from pom.xml
I reverted back to Apache HttpClient5 instead of JdkClientHttpRequestFactory with Spring Boot 3.2.3, now I don't see the request going to backend api and it is failing with org.springframework.web.client.ResourceAccessException: I/O error on POST request for <url>: Read timed out
as I configured 1 minute of connect and read timeout. But, if downgrade to 3.1.8 version, it is working and got the response in 3 secs
Comment From: margamraviteja
The issue is from my side.. I was setting content-length which was not correct. I fixed it.. Its working now..