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

Introduce HttpStatusCode interface #28214

Closed
poutsma opened this issue Mar 22, 2022 · 0 comments
Closed

Introduce HttpStatusCode interface #28214

poutsma opened this issue Mar 22, 2022 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@poutsma
Copy link
Contributor

poutsma commented Mar 22, 2022

According to the HTTP specification, the HTTP response status can be any 3-digit integer.

In Spring Framework, the HTTP status codes are enumerated in HttpStatus. Because this type is a Java enum, we need to have workarounds to allow for status codes not in the enum. For instance, the ClientHttpResponse interfaces offers both getStatusCode as well as getRawStatusCode, as does WebClient's ClientResponse, and we have similar workarounds in other places.

We cannot change HttpStatus from a enum to a class like we did for HttpMethod in #27697, because HttpStatus is used in the ResponseStatus annotation, where class instances can not be used as values.

@philwebb suggested that we can introduce a new interface HttpStatusCode, which is implemented by HttpStatus. Code that currently returns a HttpStatus will return this new HttpStatusCode instead, and we will deprecate the methods that return the raw status codes. All methods that accepts the raw integer values will still be available, we will only deprecate the integer returning methods.

Instances of the HttpStatusCode are obtained via static valueOf(int) factory method, which returns a HttpStatus enum entry if one is available for the given integer, and a default implementation otherwise. This way, we can assure that HttpStatus instance comparisons (i.e. if (statusCode == HttpStatus.OK)) will keep working as they currently do.

@poutsma poutsma added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement labels Mar 22, 2022
@poutsma poutsma added this to the 6.0.0-M4 milestone Mar 22, 2022
@poutsma poutsma self-assigned this Mar 22, 2022
poutsma added a commit that referenced this issue Mar 23, 2022
This commit contains changes made because of the introduction of
HttpStatusCode. In general, methods that used to return a HttpStatus
now return HttpStatusCode instead, and methods that returned raw status
codes are now deprecated.

See gh-28214
rahul-chekuri added a commit to rahul-chekuri/orca that referenced this issue Jan 5, 2025
…s object.

In Spring framework 6, HttpStatusCode has been introduced which is implemented by HttpStatus.

```
> Task :orca-webhook:compileJava
orca/orca-webhook/src/main/java/com/netflix/spinnaker/orca/webhook/tasks/MonitorWebhookTask.java:130: error: incompatible types: HttpStatusCode cannot be converted to HttpStatus
      if (shouldRetry(statusCode, stageData)) {
                      ^
orca/orca-webhook/src/main/java/com/netflix/spinnaker/orca/webhook/tasks/MonitorWebhookTask.java:175: error: incompatible types: HttpStatusCode cannot be converted to HttpStatus
    monitor.setStatusCode(response.getStatusCode());
                                                ^
orca/orca-webhook/src/main/java/com/netflix/spinnaker/orca/webhook/tasks/WebhookResponseProcessor.java:85: error: incompatible types: HttpStatusCode cannot be converted to HttpStatus
    webhookOutput.setStatusCode(e.getStatusCode());
                                               ^
orca/orca-webhook/src/main/java/com/netflix/spinnaker/orca/webhook/tasks/WebhookResponseProcessor.java:93: error: incompatible types: HttpStatusCode cannot be converted to HttpStatus
    TaskResult result = processReceivedFailureStatusCode(e.getStatusCode(), webhookOutput);
                                                                        ^
orca/orca-webhook/src/main/java/com/netflix/spinnaker/orca/webhook/tasks/WebhookResponseProcessor.java:165: error: incompatible types: HttpStatusCode cannot be converted to HttpStatus
    webhookOutput.setStatusCode(response.getStatusCode());
                                                      ^
orca/orca-webhook/src/main/java/com/netflix/spinnaker/orca/webhook/tasks/WebhookResponseProcessor.java:174: error: incompatible types: HttpStatusCode cannot be converted to HttpStatus
    HttpStatus status = response.getStatusCode();
```

Reference:
spring-projects/spring-framework#28214
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) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant