Cookie[] cookies = new Cookie[count];
int idx=0;
for (int i = 0; i < count; i++) {
ServerCookie scookie = serverCookies.getCookie(i);
if (scookie.getName().equals(Globals.SESSION_COOKIE_NAME)) {
// Override anything requested in the URL
if (!request.isRequestedSessionIdFromCookie()) {
// Accept only the first session id cookie
request.setRequestedSessionId
(scookie.getValue().toString());
request.setRequestedSessionCookie(true);
request.setRequestedSessionURL(false);
if (log.isDebugEnabled())
log.debug(" Requested cookie session id is " +
((HttpServletRequest) request.getRequest())
.getRequestedSessionId());
} else {
if (!request.isRequestedSessionIdValid()) {
// Replace the session id until one is valid
request.setRequestedSessionId
(scookie.getValue().toString());
}
}
}
try {
Cookie cookie = new Cookie(scookie.getName().toString(),
scookie.getValue().toString());
cookie.setPath(scookie.getPath().toString());
cookie.setVersion(scookie.getVersion());
String domain = scookie.getDomain().toString();
if (domain != null) {
cookie.setDomain(scookie.getDomain().toString());
}
cookies[idx++] = cookie;
} catch(IllegalArgumentException e) {
log.info("Bad Cookie: Name: " + scookie.getName()
+ " Value: " + scookie.getValue());
}
}
if( idx < count ) {
Cookie [] ncookies = new Cookie[idx];
System.arraycopy(cookies, 0, ncookies, 0, idx);