|
45 | 45 | import org.springframework.http.HttpInputMessage;
|
46 | 46 | import org.springframework.http.HttpOutputMessage;
|
47 | 47 | import org.springframework.http.MediaType;
|
| 48 | +import org.springframework.http.HttpStatus; |
48 | 49 | import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
49 | 50 | import org.springframework.http.converter.FormHttpMessageConverter;
|
50 | 51 | import org.springframework.http.converter.HttpMessageConverter;
|
|
56 | 57 | import org.springframework.util.ClassUtils;
|
57 | 58 | import org.springframework.util.ObjectUtils;
|
58 | 59 | import org.springframework.util.ReflectionUtils;
|
| 60 | +import org.springframework.util.StringUtils; |
59 | 61 | import org.springframework.web.bind.annotation.ExceptionHandler;
|
60 | 62 | import org.springframework.web.bind.annotation.ResponseBody;
|
61 | 63 | import org.springframework.web.bind.annotation.ResponseStatus;
|
@@ -347,10 +349,16 @@ private Object doInvokeMethod(Method method, Object target, Object[] args) throw
|
347 | 349 | private ModelAndView getModelAndView(Method handlerMethod, Object returnValue, ServletWebRequest webRequest)
|
348 | 350 | throws Exception {
|
349 | 351 |
|
350 |
| - ResponseStatus responseStatus = AnnotationUtils.findAnnotation(handlerMethod, ResponseStatus.class); |
351 |
| - if (responseStatus != null) { |
352 |
| - HttpServletResponse response = webRequest.getResponse(); |
353 |
| - response.setStatus(responseStatus.value().value()); |
| 352 | + ResponseStatus responseStatusAnn = AnnotationUtils.findAnnotation(handlerMethod, ResponseStatus.class); |
| 353 | + if (responseStatusAnn != null) { |
| 354 | + HttpStatus responseStatus = responseStatusAnn.value(); |
| 355 | + String reason = responseStatusAnn.reason(); |
| 356 | + if (!StringUtils.hasText(reason)) { |
| 357 | + webRequest.getResponse().setStatus(responseStatus.value()); |
| 358 | + } |
| 359 | + else { |
| 360 | + webRequest.getResponse().sendError(responseStatus.value(), reason); |
| 361 | + } |
354 | 362 | }
|
355 | 363 |
|
356 | 364 | if (returnValue != null && AnnotationUtils.findAnnotation(handlerMethod, ResponseBody.class) != null) {
|
|
0 commit comments