Skip to content

RestTemplate throws IllegalArgumentException when HTTP status is not in the HttpStatus enum [SPR-6752] #11418

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
spring-projects-issues opened this issue Jan 22, 2010 · 5 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 22, 2010

Justin Mills opened SPR-6752 and commented

Using RestTemplate to connect to a server that occasionally throws HTTP Status of 420, I am getting IllegalArgumentExceptions when accessing the HttpStatus object in my implementation of the ResponseErrorHandler interface. When I removed that, and started pulling the status from the Headers directly, RestTemplate started throwing errors due to the logger.warn call in RestTemplate.handleResponseError(). I've gotten around this by not using the HttpStatus enum (getting status from the HttpHeaders directly) and by turning up the log level for RestTemplate to ERROR. Shouldn't this support any HTTP status value?


Affects: 3.0 GA

Issue Links:

Referenced from: commits 68b4c7d

Backported to: 3.0.1

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

I've updated the HttpStatus enum with all codes found in the offical IANA status code registry (http://www.iana.org/assignments/http-status-codes), and also included deprecated codes from earlier WebDAV specs, such as the 420 status you ran into.

@spring-projects-issues
Copy link
Collaborator Author

Wallace Wadge commented

Hi,

I think this bug should be reopened for there is no way to manually get the raw code. I'm currently running into the same problem due to receiving status 308 (this comes from google's document list api: http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html).

Just exposing the raw statusline/status code should be sufficient.

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

I've added both the missing status codes in the enum, as well as a getRawStatusCode() method to ClientHttpResponse that returns an int.

@spring-projects-issues
Copy link
Collaborator Author

harish commented

Hi,
I think we should reconsider limiting HTTP status codes to only the ones that have associated messages. All 1xx,2xx,3xx,4xx,5xx are legal and valid response codes. RestTempllate should treat them as legal and not throw IllegalArgumentException or ignore message body when any of them are passed. Both code and body should be preserved and passed to caller as such. That would help services and clients make use of flexibility provided by HTTP specifications in using existing status codes and adding their own if no suitable status exists for their needs.

@spring-projects-issues
Copy link
Collaborator Author

Chris Beams commented

Harish,

Since this issue is resolved, your last comment will probably be ignored. If you wish, you can open a new JIRA issue for allowing user-defined status codes with RestTemplate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants