[SPR-15978] RestTemplate doesn't consistently tolerate unknown HTTP status codes Created: 19/Sep/17  Updated: 15/Jan/19  Resolved: 24/Oct/17

Status: Closed
Project: Spring Framework
Component/s: Web:Client
Affects Version/s: 4.3.11
Fix Version/s: 4.3.12, 5.0 GA

Type: Bug Priority: Major
Reporter: Darija Radchenko Assignee: Juergen Hoeller
Resolution: Complete Votes: 0
Labels: custom, resttemplate, statuscodes
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
relates to SPR-6752 RestTemplate throws IllegalArgumentEx... Closed
relates to SPR-9406 Unknown status codes (i.e. not in Htt... Closed
relates to SPR-14205 ResponseEntity should allow the usage... Closed
is related to SPR-16108 DefaultResponseErrorHandler.hasError ... Closed
is related to SPR-16371 RestTemplate.ResponseEntityResponseEx... Closed
is related to SPR-17439 RestTemplate does not throw exception... Closed
is related to SPR-16073 Returning non-standard HTTP status co... Closed
is related to SPR-16604 DefaultResponseErrorHandler wastes th... Closed
is related to SPR-16819 Improve handling of unknown status co... Closed
Days since last comment: 44 weeks, 4 days ago
Last commented by a User: true
Last updater: Spring Issuemaster


I'm really sorry, I fill confused about this, but as listed here we are enable to handle custom http status codes already... But I'm still getting
IllegalArgumentException: no matching constant for [230] caused in MessageBodyClientHttpResponseWrapper.hasEmptyMessageBody().
I'm using API that responses 230, 240 codes etc... Can you please provide some example or guide me somewhere I can find the solution?

Spring Framework version 4.3.11

Comment by Juergen Hoeller [ 19/Sep/17 ]

I've extended the scope of this issue a bit since it's not just MessageBodyClientHttpResponseWrapper but also ResponseEntityResponseExtractor and DefaultResponseErrorHandler which are not entirely tolerant towards unknown HTTP status codes.

Comment by Darija Radchenko [ 20/Sep/17 ]

Maybe I can configure RestTemplate to use some body extractor that will let me avoid these errors?

Comment by Juergen Hoeller [ 20/Sep/17 ]

I've done a full revision of the affected code for 5.0 (introducing a lenient HttpStatus.resolve method and will backport a more minimal version for 4.3.12 (calling getRawStatusCode and/or defensively catching HttpStatus.valueOf exceptions where necessary). This should hopefully work for your purposes out of the box then.

Comment by Darija Radchenko [ 30/Sep/17 ]

Thank you very much! I tested it on a Spring 5 and it works without any additional configuration. Cheers!

Comment by Patrik Steuer [ 24/Oct/17 ]

Will this fix be available for 4.3.1x aswell?

Comment by Juergen Hoeller [ 24/Oct/17 ]

This should work fine in 4.3.12 already. Have you encountered any recent issues there?

Comment by Patrik Steuer [ 24/Oct/17 ]

It didn't work for me. The related DefaultResponseErrorHandler in the relaese tag does also not contain your change, atleast what I see on github https://github.com/spring-projects/spring-framework/blob/85aab388f0a8f3464fb85030faf45e3deb22a094/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java

Comment by Juergen Hoeller [ 24/Oct/17 ]

Ouch, indeed. The backport included the MessageBodyClientHttpResponseWrapper etc changes but only minor refinements to DefaultResponseErrorHandler, not treating hasError properly... While we cannot do a full backport of 5.0's variant here, we should at least leniently handle unknown status codes in hasError there.

Could you please create a separate JIRA issue for this? I'll sort it out for 4.3.13 then.

Comment by Juergen Hoeller [ 24/Oct/17 ]

I've created SPR-16108 myself, specifically for DefaultResponseErrorHandler.hasError. The fix will be in the upcoming 4.3.13.BUILD-SNAPSHOT; please give it a try if you have the chance...

Comment by Anika Solanka [ 12/Jan/18 ]

Hi, I'm using version 4.3.13 and it seems that the ResponseEntityResponseExtractor in this version also has a problem with unknown HTTP status codes. It is calling response.getStatusCode() which throws IllegalArgumentException for unknown status codes.

Comment by Juergen Hoeller [ 12/Jan/18 ]

Anika Solanka, indeed, this looks like one more case that we need to backport to 4.3.x there. This seems to work fine in 5.0.2, so let's simply backport that ResponseEntityResponseExtractor variant to 4.3.14. Could you please create a separate JIRA issue against 4.3.13 for your particular case?

Comment by Anika Solanka [ 12/Jan/18 ]

@Juergen Hoeller I've created https://jira.spring.io/browse/SPR-16371

Comment by Spring Issuemaster [ 14/Jan/19 ]

The Spring Framework has migrated to GitHub Issues. This issue corresponds to spring-projects/spring-framework#20529.

Generated at Sat Nov 23 02:31:54 UTC 2019 using Jira 7.13.8#713008-sha1:1606a5c1e7006e1ab135aac81f7a9566b2dbc3a6.