Skip to content
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

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

Closed
spring-issuemaster opened this issue Jan 22, 2010 · 5 comments
Assignees
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster 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:

  • #13707 Implementation of HttpStatus as an enumeration precludes other status codes ("is duplicated by")
  • #13949 In order to handle non standard HTTP Status codes returned by services in RestTemplate, I would like to add support for handling non standard status codes and passing on responses for these responses to callers ("is duplicated by")
  • #14042 Unknown status codes (i.e. not in HttpStatus enum) prevent HttpClientErrorException and HttpServerErrorExceptions from being raised
  • #20529 RestTemplate doesn't consistently tolerate unknown HTTP status codes

Referenced from: commits 68b4c7d

Backported to: 3.0.1

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Feb 17, 2010

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-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jan 22, 2012

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-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jan 23, 2012

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-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Apr 17, 2012

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-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented May 14, 2012

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
Projects
None yet
2 participants
You can’t perform that action at this time.