use of java.net.CookieManager in project scout.rt by eclipse.
the class MultiSessionCookieStoreInstaller method install.
public void install() {
CookieHandler cookieHandler = CookieHandler.getDefault();
if (!checkMultiSessionCookieStoreAlreadyInstalled(cookieHandler)) {
// Install MultiSessionCookieStore
m_oldCookieHandler = cookieHandler;
m_newCookieHandler = new CookieManager(BEANS.get(MultiSessionCookieStore.class), CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(m_newCookieHandler);
LOG.info("Successfully installed {}", cookieHandlerToString(m_newCookieHandler));
}
}
use of java.net.CookieManager in project scout.rt by eclipse.
the class MultiSessionCookieStoreInstallerTest method checkOtherCookieStoreAlreadyInstalled.
@Test
public void checkOtherCookieStoreAlreadyInstalled() {
// Other CookieHandler implementation is installed -> OK
CookieHandler cookieHandler = Mockito.mock(CookieHandler.class);
s_installer.checkMultiSessionCookieStoreAlreadyInstalled(cookieHandler);
// Other CookieManager implementation is installed -> OK
CookieManager cookieManager = Mockito.mock(CookieManager.class);
s_installer.checkMultiSessionCookieStoreAlreadyInstalled(cookieManager);
// Other CookieManager with other CookieStore implementation is installed -> OK
Mockito.when(cookieManager.getCookieStore()).thenReturn(Mockito.mock(CookieStore.class));
s_installer.checkMultiSessionCookieStoreAlreadyInstalled(cookieManager);
}
use of java.net.CookieManager in project opacclient by opacapp.
the class HttpClientFactory method getOkHttpClientBuilder.
protected OkHttpClient.Builder getOkHttpClientBuilder(boolean customssl, boolean tls_only, boolean allCipherSuites) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
builder.cookieJar(new JavaNetCookieJar(cookieManager));
builder.addNetworkInterceptor(new CustomRedirectInterceptor());
builder.connectTimeout(60, TimeUnit.SECONDS);
builder.readTimeout(60, TimeUnit.SECONDS);
builder.writeTimeout(60, TimeUnit.SECONDS);
if (customssl && ssl_store_path != null) {
try {
if (trust_store == null) {
trust_store = getKeyStore();
}
X509TrustManager trustManager = new AdditionalKeyStoresSSLSocketFactory.AdditionalKeyStoresTrustManager(trust_store);
SSLSocketFactory sf = AdditionalKeyStoresSSLSocketFactory.createForOkHttp(trustManager);
if (allCipherSuites) {
sf = new AllCiphersProxySocketFactory(sf);
}
sf = new TLS12ProxySocketFactory(sf);
builder.sslSocketFactory(sf, trustManager);
List<ConnectionSpec> connectionSpecs = new ArrayList<ConnectionSpec>();
connectionSpecs.add(ConnectionSpec.MODERN_TLS);
connectionSpecs.add(new ConnectionSpec.Builder(ConnectionSpec.COMPATIBLE_TLS).allEnabledCipherSuites().build());
if (!tls_only) {
connectionSpecs.add(new ConnectionSpec.Builder(ConnectionSpec.COMPATIBLE_TLS).tlsVersions(TlsVersion.SSL_3_0, TlsVersion.TLS_1_0).allEnabledCipherSuites().build());
} else if (allCipherSuites) {
connectionSpecs.add(new ConnectionSpec.Builder(ConnectionSpec.COMPATIBLE_TLS).allEnabledCipherSuites().build());
}
connectionSpecs.add(ConnectionSpec.CLEARTEXT);
builder.connectionSpecs(connectionSpecs);
return builder;
} catch (Exception e) {
e.printStackTrace();
return builder;
}
} else {
try {
X509TrustManager trustManager = getSystemDefaultTrustManager();
SSLSocketFactory socketFactory = getSystemDefaultSSLSocketFactory(trustManager);
builder.sslSocketFactory(new TLS12ProxySocketFactory(socketFactory), trustManager);
} catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException ignored) {
}
return builder;
}
}
use of java.net.CookieManager in project okhttp by square.
the class CookiesTest method acceptOriginalServerMatchesSubdomain.
@Test
public void acceptOriginalServerMatchesSubdomain() throws Exception {
CookieManager cookieManager = new CookieManager(null, ACCEPT_ORIGINAL_SERVER);
JavaNetCookieJar cookieJar = new JavaNetCookieJar(cookieManager);
HttpUrl url = HttpUrl.get("https://www.squareup.com/");
cookieJar.saveFromResponse(url, asList(Cookie.parse(url, "a=android; Domain=squareup.com")));
List<Cookie> actualCookies = cookieJar.loadForRequest(url);
assertThat(actualCookies.size()).isEqualTo(1);
assertThat(actualCookies.get(0).name()).isEqualTo("a");
assertThat(actualCookies.get(0).value()).isEqualTo("android");
}
use of java.net.CookieManager in project okhttp by square.
the class CookiesTest method acceptOriginalServerMatchesRfc2965Dot.
@Test
public void acceptOriginalServerMatchesRfc2965Dot() throws Exception {
CookieManager cookieManager = new CookieManager(null, ACCEPT_ORIGINAL_SERVER);
JavaNetCookieJar cookieJar = new JavaNetCookieJar(cookieManager);
HttpUrl url = HttpUrl.get("https://www.squareup.com/");
cookieJar.saveFromResponse(url, asList(Cookie.parse(url, "a=android; Domain=.squareup.com")));
List<Cookie> actualCookies = cookieJar.loadForRequest(url);
assertThat(actualCookies.size()).isEqualTo(1);
assertThat(actualCookies.get(0).name()).isEqualTo("a");
assertThat(actualCookies.get(0).value()).isEqualTo("android");
}
Aggregations