414731 Request.getCookies() should return null if there are no cookies

This commit is contained in:
Jan Bartel 2013-08-09 18:08:16 +10:00
parent 06ef5b7930
commit 2c3ecf9e38
4 changed files with 31 additions and 10 deletions

View File

@ -175,10 +175,14 @@ public class BalancerServlet extends ProxyServlet
private String getBalancerMemberNameFromSessionCookie(HttpServletRequest request)
{
for (Cookie cookie : request.getCookies())
Cookie[] cookies = request.getCookies();
if (cookies != null)
{
if (JSESSIONID.equalsIgnoreCase(cookie.getName()))
return extractBalancerMemberNameFromSessionId(cookie.getValue());
for (Cookie cookie : cookies)
{
if (JSESSIONID.equalsIgnoreCase(cookie.getName()))
return extractBalancerMemberNameFromSessionId(cookie.getValue());
}
}
return null;
}

View File

@ -48,7 +48,11 @@ public class HashCrossContextPsuedoSession<T> implements CrossContextPsuedoSessi
public T fetch(HttpServletRequest request)
{
for (Cookie cookie : request.getCookies())
Cookie[] cookies = request.getCookies();
if (cookies == null)
return null;
for (Cookie cookie : cookies)
{
if (_cookieName.equals(cookie.getName()))
{

View File

@ -544,7 +544,12 @@ public class Request implements HttpServletRequest
public Cookie[] getCookies()
{
if (_cookiesExtracted)
return _cookies == null?null:_cookies.getCookies();
{
if (_cookies == null || _cookies.getCookies().length == 0)
return null;
return _cookies.getCookies();
}
_cookiesExtracted = true;
@ -563,7 +568,11 @@ public class Request implements HttpServletRequest
}
}
return _cookies == null?null:_cookies.getCookies();
//Javadoc for Request.getCookies() stipulates null for no cookies
if (_cookies == null || _cookies.getCookies().length == 0)
return null;
return _cookies.getCookies();
}
/* ------------------------------------------------------------ */

View File

@ -50,12 +50,16 @@ public class RewriteServlet extends HttpServlet
out.println("<tr><th>Rewritten request URI: </th><td>" + req.getRequestURI() + "</td></tr>");
Cookie cookie = null;
for(Cookie c: req.getCookies())
Cookie[] cookies = req.getCookies();
if (cookies != null)
{
if (c.getName().equals("visited"))
for(Cookie c: cookies)
{
cookie = c;
break;
if (c.getName().equals("visited"))
{
cookie = c;
break;
}
}
}
if (cookie!=null)