Recreating the CookieManager if the CookieStore is changed.

This commit is contained in:
Simone Bordet 2012-12-12 14:54:22 +01:00
parent f3d53918b5
commit 8d0c90eef9
1 changed files with 9 additions and 2 deletions

View File

@ -33,6 +33,7 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
@ -203,7 +204,7 @@ public class HttpClient extends ContainerLifeCycle
decoderFactories.add(new GZIPContentDecoder.Factory()); decoderFactories.add(new GZIPContentDecoder.Factory());
cookieManager = new CookieManager(cookieStore, CookiePolicy.ACCEPT_ALL); cookieManager = newCookieManager();
cookieStore = cookieManager.getCookieStore(); cookieStore = cookieManager.getCookieStore();
super.doStart(); super.doStart();
@ -216,6 +217,11 @@ public class HttpClient extends ContainerLifeCycle
return new ClientSelectorManager(getExecutor(), getScheduler()); return new ClientSelectorManager(getExecutor(), getScheduler());
} }
private CookieManager newCookieManager()
{
return new CookieManager(getCookieStore(), CookiePolicy.ACCEPT_ALL);
}
@Override @Override
protected void doStop() throws Exception protected void doStop() throws Exception
{ {
@ -261,7 +267,8 @@ public class HttpClient extends ContainerLifeCycle
*/ */
public void setCookieStore(CookieStore cookieStore) public void setCookieStore(CookieStore cookieStore)
{ {
this.cookieStore = cookieStore; this.cookieStore = Objects.requireNonNull(cookieStore);
this.cookieManager = newCookieManager();
} }
/** /**