The example use springboot 3.0 is normal, but use springboot 3.3 have exception. Maybe it is different from #31902

detail error: org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://someurl/api/": insufficient data written 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:830) at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:691)

Comment From: automvc

    try {
        URI uri = getUri(request, method);

        HttpHeaders headers = new HttpHeaders();
        Enumeration<String> headerNames = request.getHeaderNames();
        //set head from request 
        HttpEntity httpEntity = new HttpEntity<>(body, headers);
        ClientHttpRequestFactory clientHttpRequestFactory = (new SimpleClientHttpRequestFactory() {
             //... 
        });

        ClientHttpRequestFactory factory = new BufferingClientHttpRequestFactory(clientHttpRequestFactory); // already use BufferingClientHttpRequestFactory

        RestTemplate restTemplate = new RestTemplate(factory);
        ResponseEntity serverResponse = null;

        serverResponse = restTemplate.exchange(uri, method, httpEntity, String.class); //this line have ResourceAccessException : insufficient data written

        // ... other
    } catch (Exception e) {
        logger.error("", e);
    }
    return ResponseEntity.badRequest().build();

Comment From: poutsma

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: snicoll

@automvc please stop creating duplicate issues. Can you provide the sample that we requested?

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: spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

Comment From: rajukosna

Sample code is like:

@Autowired RestTemplate restTemplate;

try { URI uri = getUri(request, method);

    HttpHeaders headers = new HttpHeaders();
    Enumeration<String> headerNames = request.getHeaderNames();
    //set head from request 
    HttpEntity httpEntity = new HttpEntity<>(body, headers);

    ResponseEntity serverResponse = null;

    serverResponse = restTemplate.exchange(uri, method, httpEntity, String.class); //this line have ResourceAccessException : insufficient data written

    // ... other
} catch (Exception e) {
    logger.error("", e);
}

Comment From: ericdriggs

Additional information from me duplicating on a service under test:

Exception is being thrown here: SimpleClientHttpRequest::executeInternal#L88

this.connection.getResponseCode(); //throws java.io.IOException ("Incomplete output stream")

after the connection.connect(), the body and status code are empty

response works fine using curl/postman

errors with all of the following factory attempts * new RestTemplate() * ClientHttpRequestFactory factory = new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()); RestTemplate restTemplate = new RestTemplate(factory); * HttpComponentsClientHttpRequestFactory (returns different 500)

spring boot version 3.4

Response information:

Content-Type: application/json Content-Length: 219 status: 400 body: {"error": {"status": "400 Bad Request", "message": "..."}} (Content length verified to be correct using postman)

Comment From: bclozel

@ericdriggs unfortunately this doesn't help much. We can revisit this if you open a new issue with a minimal sample application we can run that reproduces the problem.

Comment From: gearkim0614

restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory()); fixed it for me