WrappedHttpServletRequest may throw an exception returning cookies

HttpServletRequest.getCookies() may return null
This commit is contained in:
Scott Rossillo 2015-06-16 21:54:24 -04:00
parent c6b34f32a1
commit 05bd51ac1c
2 changed files with 15 additions and 1 deletions

View file

@ -64,6 +64,12 @@ class WrappedHttpServletRequest implements Request {
@Override
public Cookie getCookie(String cookieName) {
javax.servlet.http.Cookie[] cookies = request.getCookies();
if (cookies == null) {
return null;
}
for (javax.servlet.http.Cookie cookie : request.getCookies()) {
if (cookie.getName().equals(cookieName)) {
return new Cookie(cookie.getName(), cookie.getValue(), cookie.getVersion(), cookie.getDomain(), cookie.getPath());

View file

@ -24,10 +24,11 @@ public class WrappedHttpServletRequestTest {
private static final String QUERY_PARM_2 = "code2";
private WrappedHttpServletRequest request;
private MockHttpServletRequest mockHttpServletRequest;
@Before
public void setUp() throws Exception {
MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
mockHttpServletRequest = new MockHttpServletRequest();
request = new WrappedHttpServletRequest(mockHttpServletRequest);
mockHttpServletRequest.setMethod(REQUEST_METHOD);
@ -75,6 +76,13 @@ public class WrappedHttpServletRequestTest {
assertNotNull(request.getCookie(COOKIE_NAME));
}
@Test
public void testGetCookieCookiesNull() throws Exception
{
mockHttpServletRequest.setCookies(null);
request.getCookie(COOKIE_NAME);
}
@Test
public void testGetHeader() throws Exception {
String header = request.getHeader(HEADER_SINGLE_VALUE);