Skip to content

Commit

Permalink
Merge branch '2.2.x' into 2.3.x
Browse files Browse the repository at this point in the history
Closes gh-24222
  • Loading branch information
wilkinsona committed Nov 20, 2020
2 parents 0ed7f7f + 12f2529 commit 7efa1e4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
Expand Up @@ -361,8 +361,7 @@ private ResponseEntity<Object> toResponseEntity(Object response) {
return new ResponseEntity<>(response, HttpStatus.OK);
}
WebEndpointResponse<?> webEndpointResponse = (WebEndpointResponse<?>) response;
return new ResponseEntity<>(webEndpointResponse.getBody(),
HttpStatus.valueOf(webEndpointResponse.getStatus()));
return ResponseEntity.status(webEndpointResponse.getStatus()).body(webEndpointResponse.getBody());
}

@Override
Expand Down
Expand Up @@ -367,7 +367,7 @@ private Object handleResult(Object result, HttpMethod httpMethod) {
return result;
}
WebEndpointResponse<?> response = (WebEndpointResponse<?>) result;
return new ResponseEntity<Object>(response.getBody(), HttpStatus.valueOf(response.getStatus()));
return ResponseEntity.status(response.getStatus()).body(response.getBody());
}

}
Expand Down
Expand Up @@ -380,6 +380,12 @@ void userInRoleReturnsTrueWhenUserIsInRole() {
.expectStatus().isOk().expectBody(String.class).isEqualTo("ACTUATOR: true"));
}

@Test
void endpointCanProduceAResponseWithACustomStatus() {
load((context) -> context.register(CustomResponseStatusEndpointConfiguration.class),
(client) -> client.get().uri("/customstatus").exchange().expectStatus().isEqualTo(234));
}

protected abstract int getPort(T context);

protected void validateErrorBody(WebTestClient.BodyContentSpec body, HttpStatus status, String path,
Expand Down Expand Up @@ -624,6 +630,17 @@ UserInRoleEndpoint userInRoleEndpoint() {

}

@Configuration(proxyBeanMethods = false)
@Import(BaseConfiguration.class)
static class CustomResponseStatusEndpointConfiguration {

@Bean
CustomResponseStatusEndpoint customResponseStatusEndpoint() {
return new CustomResponseStatusEndpoint();
}

}

@Endpoint(id = "test")
static class TestEndpoint {

Expand Down Expand Up @@ -850,6 +867,16 @@ String read(SecurityContext securityContext, String role) {

}

@Endpoint(id = "customstatus")
static class CustomResponseStatusEndpoint {

@ReadOperation
WebEndpointResponse<String> read() {
return new WebEndpointResponse<>("Custom status", 234);
}

}

interface EndpointDelegate {

void write();
Expand Down

0 comments on commit 7efa1e4

Please sign in to comment.