Introduce alias for 'value' attribute in @ResponseStatus
Issue: SPR-11393
This commit is contained in:
@@ -372,7 +372,7 @@ public class WebMvcConfigurationSupportTests {
|
||||
}
|
||||
|
||||
|
||||
@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "exception.user.exists")
|
||||
@ResponseStatus(code = HttpStatus.BAD_REQUEST, reason = "exception.user.exists")
|
||||
@SuppressWarnings("serial")
|
||||
public static class UserAlreadyExistsException extends RuntimeException {
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -166,7 +166,7 @@ public class AnnotationMethodHandlerExceptionResolverTests {
|
||||
}
|
||||
|
||||
@ExceptionHandler(SocketException.class)
|
||||
@ResponseStatus(value = HttpStatus.NOT_ACCEPTABLE, reason = "This is simply unacceptable!")
|
||||
@ResponseStatus(code = HttpStatus.NOT_ACCEPTABLE, reason = "This is simply unacceptable!")
|
||||
public String handleSocketException(Exception ex, HttpServletResponse response) {
|
||||
return "Y:" + ClassUtils.getShortName(ex.getClass());
|
||||
}
|
||||
|
||||
@@ -110,19 +110,16 @@ public class ResponseStatusExceptionResolverTests {
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@SuppressWarnings("serial")
|
||||
private static class StatusCodeException extends Exception {
|
||||
|
||||
}
|
||||
|
||||
@ResponseStatus(value = HttpStatus.GONE, reason = "You suck!")
|
||||
@ResponseStatus(code = HttpStatus.GONE, reason = "You suck!")
|
||||
@SuppressWarnings("serial")
|
||||
private static class StatusCodeAndReasonException extends Exception {
|
||||
|
||||
}
|
||||
|
||||
@ResponseStatus(value = HttpStatus.GONE, reason = "gone.reason")
|
||||
@ResponseStatus(code = HttpStatus.GONE, reason = "gone.reason")
|
||||
@SuppressWarnings("serial")
|
||||
private static class StatusCodeAndReasonMessageException extends Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -2992,7 +2992,7 @@ public class ServletAnnotationControllerTests {
|
||||
public static class ResponseStatusController {
|
||||
|
||||
@RequestMapping("/something")
|
||||
@ResponseStatus(value = HttpStatus.CREATED, reason = "It's alive!")
|
||||
@ResponseStatus(code = HttpStatus.CREATED, reason = "It's alive!")
|
||||
public void handle(Writer writer) throws IOException {
|
||||
writer.write("something");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -353,14 +353,14 @@ public class RequestMappingHandlerAdapterIntegrationTests {
|
||||
return "viewName";
|
||||
}
|
||||
|
||||
@ResponseStatus(value=HttpStatus.ACCEPTED)
|
||||
@ResponseStatus(HttpStatus.ACCEPTED)
|
||||
@ResponseBody
|
||||
public String handleRequestBody(@RequestBody byte[] bytes) throws Exception {
|
||||
String requestBody = new String(bytes, "UTF-8");
|
||||
return "Handled requestBody=[" + requestBody + "]";
|
||||
}
|
||||
|
||||
@ResponseStatus(value=HttpStatus.ACCEPTED)
|
||||
@ResponseStatus(code = HttpStatus.ACCEPTED)
|
||||
@ResponseBody
|
||||
public String handleAndValidateRequestBody(@Valid TestBean modelAttr, Errors errors) throws Exception {
|
||||
return "Error count [" + errors.getErrorCount() + "]";
|
||||
|
||||
@@ -2657,7 +2657,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
public static class ResponseStatusController {
|
||||
|
||||
@RequestMapping("/something")
|
||||
@ResponseStatus(value = HttpStatus.CREATED, reason = "It's alive!")
|
||||
@ResponseStatus(code = HttpStatus.CREATED, reason = "It's alive!")
|
||||
public void handle(Writer writer) throws IOException {
|
||||
writer.write("something");
|
||||
}
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.springframework.web.servlet.mvc.method.annotation;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -26,7 +23,6 @@ import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
@@ -50,37 +46,30 @@ import org.springframework.web.method.support.HandlerMethodReturnValueHandlerCom
|
||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
import org.springframework.web.servlet.view.RedirectView;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Test fixture with {@link ServletInvocableHandlerMethod}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class ServletInvocableHandlerMethodTests {
|
||||
|
||||
private HandlerMethodArgumentResolverComposite argumentResolvers;
|
||||
private final HandlerMethodArgumentResolverComposite argumentResolvers = new HandlerMethodArgumentResolverComposite();
|
||||
|
||||
private HandlerMethodReturnValueHandlerComposite returnValueHandlers;
|
||||
private final HandlerMethodReturnValueHandlerComposite returnValueHandlers = new HandlerMethodReturnValueHandlerComposite();
|
||||
|
||||
private ModelAndViewContainer mavContainer;
|
||||
private final ModelAndViewContainer mavContainer = new ModelAndViewContainer();
|
||||
|
||||
private ServletWebRequest webRequest;
|
||||
private final MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
private final MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
private MockHttpServletResponse response;
|
||||
private final ServletWebRequest webRequest = new ServletWebRequest(this.request, this.response);
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
this.returnValueHandlers = new HandlerMethodReturnValueHandlerComposite();
|
||||
this.argumentResolvers = new HandlerMethodArgumentResolverComposite();
|
||||
this.mavContainer = new ModelAndViewContainer();
|
||||
this.request = new MockHttpServletRequest();
|
||||
this.response = new MockHttpServletResponse();
|
||||
this.webRequest = new ServletWebRequest(this.request, this.response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeAndHandle_VoidWithResponseStatus() throws Exception {
|
||||
ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new Handler(), "responseStatus");
|
||||
@@ -279,11 +268,11 @@ public class ServletInvocableHandlerMethodTests {
|
||||
return "view";
|
||||
}
|
||||
|
||||
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public void responseStatus() {
|
||||
}
|
||||
|
||||
@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "400 Bad Request")
|
||||
@ResponseStatus(code = HttpStatus.BAD_REQUEST, reason = "400 Bad Request")
|
||||
public String responseStatusWithReason() {
|
||||
return "foo";
|
||||
}
|
||||
@@ -299,7 +288,6 @@ public class ServletInvocableHandlerMethodTests {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class MethodLevelResponseBodyHandler {
|
||||
|
||||
@ResponseBody
|
||||
@@ -324,12 +312,11 @@ public class ServletInvocableHandlerMethodTests {
|
||||
return new DeferredResult<>();
|
||||
}
|
||||
|
||||
public ResponseEntity handleRawType() {
|
||||
public ResponseEntity<Void> handleRawType() {
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class ExceptionRaisingReturnValueHandler implements HandlerMethodReturnValueHandler {
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user