SPR-7060 - @ResponseStatus: The reason value is not used.
This commit is contained in:
parent
580dc8e72a
commit
8a1a23af83
|
|
@ -814,9 +814,17 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
|||
ResponseStatus responseStatusAnn = AnnotationUtils.findAnnotation(handlerMethod, ResponseStatus.class);
|
||||
if (responseStatusAnn != null) {
|
||||
HttpStatus responseStatus = responseStatusAnn.value();
|
||||
String reason = responseStatusAnn.reason();
|
||||
if (!StringUtils.hasText(reason)) {
|
||||
webRequest.getResponse().setStatus(responseStatus.value());
|
||||
}
|
||||
else {
|
||||
webRequest.getResponse().sendError(responseStatus.value(), reason);
|
||||
}
|
||||
|
||||
// to be picked up by the RedirectView
|
||||
webRequest.getRequest().setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, responseStatus);
|
||||
webRequest.getResponse().setStatus(responseStatus.value());
|
||||
|
||||
responseArgumentUsed = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1307,6 +1307,7 @@ public class ServletAnnotationControllerTests {
|
|||
servlet.service(request, response);
|
||||
assertEquals("something", response.getContentAsString());
|
||||
assertEquals(201, response.getStatus());
|
||||
assertEquals("It's alive!", response.getErrorMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -2382,7 +2383,7 @@ public class ServletAnnotationControllerTests {
|
|||
public static class ResponseStatusController {
|
||||
|
||||
@RequestMapping("/something")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@ResponseStatus(value = HttpStatus.CREATED, reason = "It's alive!")
|
||||
public void handle(Writer writer) throws IOException {
|
||||
writer.write("something");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue