Running with Spring Boot v3.2.4, Spring v6.1.5.

After upgrading Spring Boot 2.x -> 3.2.4, our integration test using RestTemplate is failing with the below errors when executed requests using restTemplate.exchange(url, HttpMethod.POST, entity, responseType) .

org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:61267/csm/v2/internal/pipeline/jUnit_pipeline_region_code/jUnit_topic": Premature end of chunk coded message body: closing chunk expected

    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.execute(RestTemplate.java:790)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:672)
    at org.springframework.boot.test.web.client.TestRestTemplate.exchange(TestRestTemplate.java:711)
    at com.adobe.csm.util.EndpointTest.postAndAcceptHal(EndpointTest.java:203)
    at com.adobe.csm.api.internal.PipelinePublishEndpointTest.testPostAcceptHal(PipelinePublishEndpointTest.java:51)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    .....
    .....
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by: org.apache.hc.core5.http.ConnectionClosedException: Premature end of chunk coded message body: closing chunk expected

This is how the RestTemplate was configured and nothing has changed, still the upgrade is causing such issues

MappingJackson2HttpMessageConverter messageConverter =
        new MappingJackson2HttpMessageConverter();
    messageConverter.setObjectMapper(new HALMapper());
    restTemplate
        .getRestTemplate()
        .getMessageConverters()
        .removeIf(
            httpMessageConverter ->
                httpMessageConverter instanceof MappingJackson2HttpMessageConverter);

restTemplate.getRestTemplate().getMessageConverters().add(messageConverter);

Comment From: philwebb

The exception itself if coming from org.apache.hc.core5.http.ConnectionClosedException so it's possible that in the process of upgrading Spring Boot, the related upgrade of Apache HTTP Client is causing you issues. Unfortunately it's very hard to say what's causing the problem from the limited information in this report.

If you'd like us to spend some time investigating, please take the time to provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: abhupadh

fixed it by explicitly setting HttpHeaders.CONTENT_LENGTH, 0 in the Response header of the original resource endpoint being tested.