-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Description
Carl Harris opened SPR-7911 and commented
Some REST web services return 204 No Content as the result for a GET in certain circumstances. With this status, the response has no entity body and thus no Content-Type header.
RestTemplate.getForEntity throws an exception when receiving such a response:
org.springframework.web.client.RestClientException: Cannot extract response: no Content-Type found
An improvement for RestTemplate.getForEntity would be to return a ResponseEntity instance with the statusCode property set as appropriate for 204 No Content, and null values for the body and contentType properties.
I considered trying to extend RestTemplate to make it behave in this manner. Unfortunately, the extensive use of private static classes in the implementation makes it difficult to override the behavior of getForEntity -- can't just replace the ResponseEntityResponseExtractor implementation without also replacing other unrelated collaborators (e.g. AcceptHeaderRequestCallback). It's possible to do it, it would just require a lot more code duplication than really seems warranted.
If you don't wish to change the behavior of RestTemplate.getForEntity, perhaps you might consider relaxing the access modifiers on these collaborator classes so that a subclass could make use of them?
Affects: 3.1 M1
Issue Links:
- RestTemplate - support response mapping to entity with potentially empty response body. [SPR-8016] #12671 RestTemplate - support response mapping to entity with potentially empty response body. ("is duplicated by")
Referenced from: commits c42671a, 9887025
1 votes, 1 watchers