Skip to content

Springboot 3.2.4 : restTemplate.exchange throws exception "Premature end of chunk coded message body: closing chunk expected" #42391

@abhupadh

Description

@abhupadh

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions