Skip to content

restTemplate.exchange have exception "insufficient data written" with springboot 3.3 #41087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
automvc opened this issue Jun 12, 2024 · 10 comments
Labels
for: external-project For an external project and not something we can fix status: duplicate A duplicate of another issue

Comments

@automvc
Copy link

automvc commented Jun 12, 2024

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)

example code:

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();
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 12, 2024
@bclozel
Copy link
Member

bclozel commented Jun 12, 2024

Duplicates spring-projects/spring-framework#33015

@bclozel bclozel closed this as not planned Won't fix, can't repro, duplicate, stale Jun 12, 2024
@bclozel bclozel added status: duplicate A duplicate of another issue for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 12, 2024
@rajukosna
Copy link

Hi .
I am getting the bellow error using springboot3.3 and java 17.
ERROR: insufficient data written : I/O error on POST request for http://some.com

@rajukosna
Copy link

please help on this

@rajukosna
Copy link

insufficient data written : I/O error on POST request for http://some.com/ this error is coming in using RestTemplate in springboot3.3 version

@bclozel
Copy link
Member

bclozel commented Dec 18, 2024

@rajukosna we never got the sample we requested.
If you can reproduce the problem with a minimal sample application (something we can git clone or unzip) please create a new issue here: https://github.com/spring-projects/spring-framework/issues

Note: if you cannot reproduce the problem with a minimal sample application this is likely to be a problem specific to your application. In this case please ask a question on StackOverflow.

@rajukosna
Copy link

@bclozel Thank you for your quick response

@rajukosna
Copy link

rajukosna commented Dec 19, 2024

@bclozel
Example code:

ResponseEntity<ResponseDTO> responseEntity = null;
		try {
			LOGGER.info(REST_CALL_FOR_URL);
			if (headers == null) {
				headers = new HttpHeaders();
			}
			headers.add(HEADER_NAME, getFullContextInJson());
			
			HttpEntity<?> httpEntity = new HttpEntity<>(body, headers);
			responseEntity = restTemplate.exchange(UriComponentsBuilder.fromHttpUrl(url).build(true).toUriString(), 
					httpMethod, httpEntity, ResponseDTO.class);
						
			return responseEntity;
		} catch (RestClientException restClientException) {
			logger(restClientException);
			return new ResponseEntity<>(restClientException.getMessage(), HttpStatus.BAD_REQUEST);
		}

ERROR: insufficient data written : I/O error on POST request for "http://localhost:8083/api/o......... ": insufficient data

@bclozel
Copy link
Member

bclozel commented Dec 19, 2024

Thanks for the code snippet but I can't reproduce this issue.

@rajukosna
Copy link

rajukosna commented Dec 19, 2024

Thanks you
we are using spring boot 3.3.4 and java17 with this version I am getting this error.

@philwebb
Copy link
Member

@rajukosna We need a complete sample application to be able to help you. That way we know exactly what library versions you're using and how your application is configured. You should also upgrade to 3.3.7 or 3.4.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

5 participants