Do not use Servlet 3.0 API in doOptions()

Refactor FrameworkServlet.doOptions() to capture the "Allow" header
by using a HttpServletResponseWrapper.

Prior to this commit the HttpServletResponse.getHeader() method was
used which is only available in Servlet 3.0 environments.

Issue: SPR-10341
This commit is contained in:
Phillip Webb
2013-02-28 17:48:12 -08:00
parent c986a1efc1
commit b27fc0ef30
2 changed files with 17 additions and 5 deletions

View File

@@ -61,6 +61,8 @@ import org.springframework.web.util.WebUtils;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
/**
* @author Rod Johnson
@@ -857,9 +859,10 @@ public class DispatcherServletTests extends TestCase {
public void testAllowedOptionsIncludesPatchMethod() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "OPTIONS", "/foo");
MockHttpServletResponse response = new MockHttpServletResponse();
MockHttpServletResponse response = spy(new MockHttpServletResponse());
DispatcherServlet servlet = new DispatcherServlet();
servlet.service(request, response);
verify(response, never()).getHeader(anyString()); // SPR-10341
assertThat(response.getHeader("Allow"), equalTo("GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH"));
}