Skip to content

Commit f49de92

Browse files
committed
refactor(http): Using HttpStatus.valueOf method to populate HttpStatus 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
1 parent f10998b commit f49de92

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

orca-core/src/main/java/com/netflix/spinnaker/orca/config/TaskOverrideConfigurationProperties.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
package com.netflix.spinnaker.orca.config
22

33
import org.springframework.boot.context.properties.ConfigurationProperties
4-
import org.springframework.boot.context.properties.ConstructorBinding
54

65
/**
76
* Task override configuration to use while planning stages.
87
*/
98
@ConfigurationProperties("task-overrides")
10-
@ConstructorBinding
119
public class TaskOverrideConfigurationProperties(
1210
/**
1311
* list of task overrides.
1412
*/
1513
public var overrideDefinitions: List<TaskOverrideDefinition> = listOf()
1614
) {
1715

18-
@ConstructorBinding
1916
public class TaskOverrideDefinition(
2017
/**
2118
* Candidate stage in which we are looking to replace task definition

orca-webhook/src/main/java/com/netflix/spinnaker/orca/webhook/tasks/MonitorWebhookTask.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
import com.netflix.spinnaker.orca.webhook.config.WebhookProperties;
2828
import com.netflix.spinnaker.orca.webhook.pipeline.WebhookStage;
2929
import com.netflix.spinnaker.orca.webhook.service.WebhookService;
30+
import jakarta.annotation.Nonnull;
3031
import java.net.SocketTimeoutException;
3132
import java.net.UnknownHostException;
3233
import java.time.Duration;
3334
import java.util.*;
3435
import java.util.concurrent.TimeUnit;
3536
import java.util.function.Function;
3637
import java.util.stream.Collectors;
37-
import javax.annotation.Nonnull;
3838
import lombok.extern.slf4j.Slf4j;
3939
import org.apache.commons.lang3.StringUtils;
4040
import org.springframework.beans.factory.annotation.Autowired;
@@ -127,7 +127,7 @@ public TaskResult execute(StageExecution stage) {
127127
} catch (HttpStatusCodeException e) {
128128
var statusCode = e.getStatusCode();
129129

130-
if (shouldRetry(statusCode, stageData)) {
130+
if (shouldRetry(HttpStatus.valueOf(statusCode.value()), stageData)) {
131131
log.warn(
132132
"Failed to get webhook status from {} with statusCode={}, will retry",
133133
stageData.statusEndpoint,
@@ -172,7 +172,7 @@ public TaskResult execute(StageExecution stage) {
172172
}
173173

174174
monitor.setBody(response.getBody());
175-
monitor.setStatusCode(response.getStatusCode());
175+
monitor.setStatusCode(HttpStatus.valueOf(response.getStatusCode().value()));
176176
monitor.setStatusCodeValue(response.getStatusCode().value());
177177

178178
if (!response.getHeaders().isEmpty()) {

orca-webhook/src/main/java/com/netflix/spinnaker/orca/webhook/tasks/WebhookResponseProcessor.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,17 @@ public TaskResult process(ResponseEntity<Object> response, Exception exceptionRe
8282
private TaskResult processReceivedHttpStatusException(HttpStatusCodeException e) {
8383
var webhookOutput = new WebhookStage.WebhookResponseStageData();
8484

85-
webhookOutput.setStatusCode(e.getStatusCode());
85+
webhookOutput.setStatusCode(HttpStatus.valueOf(e.getStatusCode().value()));
8686
webhookOutput.setStatusCodeValue(e.getStatusCode().value());
8787
if (e.getResponseHeaders() != null) {
8888
webhookOutput.setHeaders(e.getResponseHeaders().toSingleValueMap());
8989
}
9090
if (!StringUtils.isEmpty(e.getResponseBodyAsString())) {
9191
webhookOutput.setBody(processResponseBodyAsJson(e.getResponseBodyAsString()));
9292
}
93-
TaskResult result = processReceivedFailureStatusCode(e.getStatusCode(), webhookOutput);
93+
TaskResult result =
94+
processReceivedFailureStatusCode(
95+
HttpStatus.valueOf(e.getStatusCode().value()), webhookOutput);
9496
log.warn(webhookOutput.getError(), e);
9597
return result;
9698
}
@@ -162,7 +164,7 @@ private TaskResult processResponse(ResponseEntity response) {
162164
Map<String, Object> stageOutput = new HashMap<>();
163165
var webhookOutput = new WebhookStage.WebhookResponseStageData();
164166
stageOutput.put("webhook", webhookOutput);
165-
webhookOutput.setStatusCode(response.getStatusCode());
167+
webhookOutput.setStatusCode(HttpStatus.valueOf(response.getStatusCode().value()));
166168
webhookOutput.setStatusCodeValue(response.getStatusCode().value());
167169

168170
if (response.getBody() != null) {
@@ -171,7 +173,7 @@ private TaskResult processResponse(ResponseEntity response) {
171173
if (!response.getHeaders().isEmpty()) {
172174
webhookOutput.setHeaders(response.getHeaders().toSingleValueMap());
173175
}
174-
HttpStatus status = response.getStatusCode();
176+
HttpStatus status = HttpStatus.valueOf(response.getStatusCode().value());
175177

176178
if (status.is2xxSuccessful() || status.is3xxRedirection()) {
177179

0 commit comments

Comments
 (0)