in src/main/java/org/apache/sling/testing/clients/interceptors/StickyCookieInterceptor.java [34:60]
public void process(HttpRequest httpRequest, HttpContext httpContext) throws HttpException, IOException {
final HttpClientContext clientContext = HttpClientContext.adapt(httpContext);
List<Cookie> cookies = clientContext.getCookieStore().getCookies();
boolean set = (null != StickyCookieHolder.getTestStickySessionCookie());
boolean found = false;
ListIterator<Cookie> it = cookies.listIterator();
while (it.hasNext()) {
Cookie cookie = it.next();
if (cookie.getName().equals(StickyCookieHolder.COOKIE_NAME)) {
found = true;
if (set) {
// set the cookie with the value saved for each thread using the rule
it.set(StickyCookieHolder.getTestStickySessionCookie());
} else {
// if the cookie is not set in TestStickySessionRule, remove it from here
it.remove();
}
}
}
// if the cookie needs to be set from TestStickySessionRule but did not exist in the client cookie list, add it here.
if (!found && set) {
cookies.add(StickyCookieHolder.getTestStickySessionCookie());
}
BasicCookieStore cs = new BasicCookieStore();
cs.addCookies(cookies.toArray(new Cookie[cookies.size()]));
httpContext.setAttribute(HttpClientContext.COOKIE_STORE, cs);
}