Previously, I was using Apache HttpClient5 with RestTemplate. When I upgraded to Spring Boot 3.2.2 version 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
Comment From: margamraviteja
I tried hitting the same request with the JDK HttpClient, I was getting response without any issue.
Comment From: margamraviteja
I reverted back to Apache HttpClient5 instead of JdkClientHttpRequestFactory with Spring Boot 3.2.2, 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: wilkinsona
The code that you are asking about is not part of Spring Boot – all of Spring Boot's code is in an org.springframework.boot package. org.springframework.web is part of Spring Framework so please open a Spring Framework issue.
Comment From: margamraviteja
Sure, Thanks for the info. I will raise with Spring Framework