Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2022 the original author or authors.
* Copyright 2013-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,7 +27,7 @@

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;

/**
Expand All @@ -36,6 +36,7 @@
*
* @author chad jaros
* @author Olga Maciaszek-Sharma
* @author Maksym Pasichenko
*/
public class ResponseEntityDecoder implements Decoder {

Expand Down Expand Up @@ -84,7 +85,7 @@ private <T> ResponseEntity<T> createResponse(Object instance, Response response)
headers.put(key, new LinkedList<>(response.headers().get(key)));
}

return new ResponseEntity<>((T) instance, headers, HttpStatus.valueOf(response.status()));
return new ResponseEntity<>((T) instance, headers, HttpStatusCode.valueOf(response.status()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.client.HttpMessageConverterExtractor;
Expand All @@ -42,6 +42,7 @@
/**
* @author Spencer Gibb
* @author Olga Maciaszek-Sharma
* @author Maksym Pasichenko
*/
public class SpringDecoder implements Decoder {

Expand Down Expand Up @@ -82,8 +83,8 @@ private FeignResponseAdapter(Response response) {
}

@Override
public HttpStatus getStatusCode() {
return HttpStatus.valueOf(response.status());
public HttpStatusCode getStatusCode() {
return HttpStatusCode.valueOf(response.status());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.springframework.context.annotation.Import;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext;
Expand All @@ -49,6 +50,7 @@
* @author Spencer Gibb
* @author Olga Maciaszek-Sharma
* @author Szymon Linowski
* @author Maksym Pasichenko
*/
@SpringBootTest(classes = SpringDecoderIntegrationTests.Application.class, webEnvironment = WebEnvironment.RANDOM_PORT,
value = { "spring.application.name=springdecodertest", "spring.jmx.enabled=false" })
Expand Down Expand Up @@ -152,11 +154,21 @@ void testResponseEntityHeaders() {
assertThat(response.getHeaders().getContentType()).isEqualTo(MediaType.APPLICATION_JSON);
}

@Test
// Issue: https://github.com/spring-cloud/spring-cloud-openfeign/issues/1010
void testResponseEntityWithCustomHttpStatusCode() {
ResponseEntity<Hello> response = testClient().getCustomHttpStatusCodeResponse();
assertThat(response.getStatusCode()).isEqualTo(HttpStatusCode.valueOf(245));
}

protected interface TestClient {

@GetMapping("/helloresponse")
ResponseEntity<Hello> getHelloResponse();

@GetMapping("/hellocustomhttpstatuscode")
ResponseEntity<Hello> getCustomHttpStatusCodeResponse();

@GetMapping("/hellovoid")
ResponseEntity<Void> getHelloVoid();

Expand Down Expand Up @@ -229,6 +241,11 @@ public ResponseEntity<Hello> getHelloResponse() {
return ResponseEntity.ok(new Hello("hello world via response"));
}

@Override
public ResponseEntity<Hello> getCustomHttpStatusCodeResponse() {
return ResponseEntity.status(245).body(new Hello("hello world via response with custom HTTP status code"));
}

@Override
public ResponseEntity<Void> getHelloVoid() {
return ResponseEntity.noContent().header("X-test-header", "myval").build();
Expand Down