java.net.CookiePolicy Java Examples
The following examples show how to use
java.net.CookiePolicy.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpClientUnitTest.java From tutorials with MIT License | 7 votes |
@Test public void shouldStoreCookieWhenPolicyAcceptAll() throws URISyntaxException, IOException, InterruptedException { HttpRequest request = HttpRequest.newBuilder() .uri(new URI("https://postman-echo.com/get")) .GET() .build(); HttpClient httpClient = HttpClient.newBuilder() .cookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ALL)) .build(); httpClient.send(request, HttpResponse.BodyHandlers.ofString()); assertTrue(httpClient.cookieHandler() .isPresent()); }
Example #2
Source File: CookieHttpClientTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
CookieHttpClientTest() throws Exception { /* start the server */ ss = new ServerSocket(0); (new Thread(this)).start(); URL url = new URL("http://localhost:" + ss.getLocalPort() +"/"); // Run without a CookieHandler first InputStream in = url.openConnection().getInputStream(); while (in.read() != -1); // read response body so connection can be reused // Set a CookeHandler and retest using the HttpClient from the KAC CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); in = url.openConnection().getInputStream(); while (in.read() != -1); if (manager.getCookieStore().getCookies().isEmpty()) { throw new RuntimeException("Failed: No cookies in the cookie Handler."); } }
Example #3
Source File: OkHttpClientManager.java From BlueBoard with Apache License 2.0 | 6 votes |
public static OkHttpClient getsInstance() { if (sInstance == null) { synchronized (OkHttpClientManager.class) { if (sInstance == null) { sInstance = new com.squareup.okhttp.OkHttpClient(); // cookie enabled sInstance.setCookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ORIGINAL_SERVER)); // timeout reading data from the host sInstance.setReadTimeout(15, TimeUnit.SECONDS); // timeout connection host sInstance.setConnectTimeout(20, TimeUnit.SECONDS); } } } return sInstance; }
Example #4
Source File: CookieHttpClientTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
CookieHttpClientTest() throws Exception { /* start the server */ ss = new ServerSocket(0); (new Thread(this)).start(); URL url = new URL("http://localhost:" + ss.getLocalPort() +"/"); // Run without a CookieHandler first InputStream in = url.openConnection().getInputStream(); while (in.read() != -1); // read response body so connection can be reused // Set a CookeHandler and retest using the HttpClient from the KAC CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); in = url.openConnection().getInputStream(); while (in.read() != -1); if (manager.getCookieStore().getCookies().isEmpty()) { throw new RuntimeException("Failed: No cookies in the cookie Handler."); } }
Example #5
Source File: CookieHttpClientTest.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
CookieHttpClientTest() throws Exception { /* start the server */ ss = new ServerSocket(0); (new Thread(this)).start(); URL url = new URL("http://localhost:" + ss.getLocalPort() +"/"); // Run without a CookieHandler first InputStream in = url.openConnection().getInputStream(); while (in.read() != -1); // read response body so connection can be reused // Set a CookeHandler and retest using the HttpClient from the KAC CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); in = url.openConnection().getInputStream(); while (in.read() != -1); if (manager.getCookieStore().getCookies().isEmpty()) { throw new RuntimeException("Failed: No cookies in the cookie Handler."); } }
Example #6
Source File: CookieHttpClientTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
CookieHttpClientTest() throws Exception { /* start the server */ ss = new ServerSocket(0); (new Thread(this)).start(); URL url = new URL("http://localhost:" + ss.getLocalPort() +"/"); // Run without a CookieHandler first InputStream in = url.openConnection().getInputStream(); while (in.read() != -1); // read response body so connection can be reused // Set a CookeHandler and retest using the HttpClient from the KAC CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); in = url.openConnection().getInputStream(); while (in.read() != -1); if (manager.getCookieStore().getCookies().isEmpty()) { throw new RuntimeException("Failed: No cookies in the cookie Handler."); } }
Example #7
Source File: AbstractCookiesTest.java From j2objc with Apache License 2.0 | 6 votes |
public void testCookieWithNullPath() throws Exception { FakeSingleCookieStore fscs = new FakeSingleCookieStore(); CookieManager cm = new CookieManager(fscs, CookiePolicy.ACCEPT_ALL); HttpCookie cookie = new HttpCookie("foo", "bar"); cookie.setDomain("http://www.foo.com"); cookie.setVersion(0); fscs.setNextCookie(cookie); Map<String, List<String>> cookieHeaders = cm.get( new URI("http://www.foo.com/log/me/in"), Collections.EMPTY_MAP); List<String> cookies = cookieHeaders.get("Cookie"); assertEquals("foo=bar", cookies.get(0)); }
Example #8
Source File: HttpClientUnitTest.java From tutorials with MIT License | 6 votes |
@Test public void shouldNotStoreCookieWhenPolicyAcceptNone() throws URISyntaxException, IOException, InterruptedException { HttpRequest request = HttpRequest.newBuilder() .uri(new URI("https://postman-echo.com/get")) .GET() .build(); HttpClient httpClient = HttpClient.newBuilder() .cookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_NONE)) .build(); httpClient.send(request, HttpResponse.BodyHandlers.ofString()); assertTrue(httpClient.cookieHandler() .isPresent()); }
Example #9
Source File: CookieHttpClientTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
CookieHttpClientTest() throws Exception { /* start the server */ ss = new ServerSocket(0); (new Thread(this)).start(); URL url = new URL("http://localhost:" + ss.getLocalPort() +"/"); // Run without a CookieHandler first InputStream in = url.openConnection().getInputStream(); while (in.read() != -1); // read response body so connection can be reused // Set a CookeHandler and retest using the HttpClient from the KAC CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); in = url.openConnection().getInputStream(); while (in.read() != -1); if (manager.getCookieStore().getCookies().isEmpty()) { throw new RuntimeException("Failed: No cookies in the cookie Handler."); } }
Example #10
Source File: OkHttpClientManager.java From OkDownload with Apache License 2.0 | 6 votes |
public static OkHttpClient getsInstance() { if (sInstance == null) { synchronized (OkHttpClientManager.class) { if (sInstance == null) { sInstance = new com.squareup.okhttp.OkHttpClient(); // cookie enabled sInstance.setCookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ORIGINAL_SERVER)); // timeout reading data from the host sInstance.setReadTimeout(15, TimeUnit.SECONDS); // timeout connection host sInstance.setConnectTimeout(20, TimeUnit.SECONDS); } } } return sInstance; }
Example #11
Source File: CookieHttpClientTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
CookieHttpClientTest() throws Exception { /* start the server */ ss = new ServerSocket(0); (new Thread(this)).start(); URL url = new URL("http://localhost:" + ss.getLocalPort() +"/"); // Run without a CookieHandler first InputStream in = url.openConnection().getInputStream(); while (in.read() != -1); // read response body so connection can be reused // Set a CookeHandler and retest using the HttpClient from the KAC CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); in = url.openConnection().getInputStream(); while (in.read() != -1); if (manager.getCookieStore().getCookies().isEmpty()) { throw new RuntimeException("Failed: No cookies in the cookie Handler."); } }
Example #12
Source File: CookieHttpClientTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
CookieHttpClientTest() throws Exception { /* start the server */ ss = new ServerSocket(0); (new Thread(this)).start(); URL url = new URL("http://localhost:" + ss.getLocalPort() +"/"); // Run without a CookieHandler first InputStream in = url.openConnection().getInputStream(); while (in.read() != -1); // read response body so connection can be reused // Set a CookeHandler and retest using the HttpClient from the KAC CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); in = url.openConnection().getInputStream(); while (in.read() != -1); if (manager.getCookieStore().getCookies().isEmpty()) { throw new RuntimeException("Failed: No cookies in the cookie Handler."); } }
Example #13
Source File: RestClient.java From autorest-clientruntime-for-java with MIT License | 6 votes |
/** * Creates an instance of the builder with a base URL and 2 custom builders. * * @param httpClientBuilder the builder to build an {@link OkHttpClient}. * @param retrofitBuilder the builder to build a {@link Retrofit}. */ public Builder(OkHttpClient.Builder httpClientBuilder, Retrofit.Builder retrofitBuilder) { if (httpClientBuilder == null) { throw new IllegalArgumentException("httpClientBuilder == null"); } if (retrofitBuilder == null) { throw new IllegalArgumentException("retrofitBuilder == null"); } CookieManager cookieManager = new CookieManager(); cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); customHeadersInterceptor = new CustomHeadersInterceptor(); // Set up OkHttp client this.httpClientBuilder = httpClientBuilder .cookieJar(new JavaNetCookieJar(cookieManager)) .readTimeout(120, TimeUnit.SECONDS) .connectTimeout(60, TimeUnit.SECONDS) .addInterceptor(new RequestIdHeaderInterceptor()) .addInterceptor(new BaseUrlHandler()); this.retrofitBuilder = retrofitBuilder; this.loggingInterceptor = new LoggingInterceptor(LogLevel.NONE); this.useHttpClientThreadPool = false; }
Example #14
Source File: CookieHttpClientTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
CookieHttpClientTest() throws Exception { /* start the server */ ss = new ServerSocket(0); (new Thread(this)).start(); URL url = new URL("http://localhost:" + ss.getLocalPort() +"/"); // Run without a CookieHandler first InputStream in = url.openConnection().getInputStream(); while (in.read() != -1); // read response body so connection can be reused // Set a CookeHandler and retest using the HttpClient from the KAC CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); in = url.openConnection().getInputStream(); while (in.read() != -1); if (manager.getCookieStore().getCookies().isEmpty()) { throw new RuntimeException("Failed: No cookies in the cookie Handler."); } }
Example #15
Source File: OkHttpUtils.java From NewsMe with Apache License 2.0 | 6 votes |
private OkHttpUtils() { mOkHttpClient = new OkHttpClient(); //cookie enabled mOkHttpClient.setCookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ORIGINAL_SERVER)); mDelivery = new Handler(Looper.getMainLooper()); if (true) { mOkHttpClient.setHostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } }); } }
Example #16
Source File: CookieHttpClientTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
CookieHttpClientTest() throws Exception { /* start the server */ ss = new ServerSocket(0); (new Thread(this)).start(); URL url = new URL("http://localhost:" + ss.getLocalPort() +"/"); // Run without a CookieHandler first InputStream in = url.openConnection().getInputStream(); while (in.read() != -1); // read response body so connection can be reused // Set a CookeHandler and retest using the HttpClient from the KAC CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); in = url.openConnection().getInputStream(); while (in.read() != -1); if (manager.getCookieStore().getCookies().isEmpty()) { throw new RuntimeException("Failed: No cookies in the cookie Handler."); } }
Example #17
Source File: CookieHttpClientTest.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
CookieHttpClientTest() throws Exception { /* start the server */ ss = new ServerSocket(0); (new Thread(this)).start(); URL url = new URL("http://localhost:" + ss.getLocalPort() +"/"); // Run without a CookieHandler first InputStream in = url.openConnection().getInputStream(); while (in.read() != -1); // read response body so connection can be reused // Set a CookeHandler and retest using the HttpClient from the KAC CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); in = url.openConnection().getInputStream(); while (in.read() != -1); if (manager.getCookieStore().getCookies().isEmpty()) { throw new RuntimeException("Failed: No cookies in the cookie Handler."); } }
Example #18
Source File: CookieHttpClientTest.java From hottub with GNU General Public License v2.0 | 6 votes |
CookieHttpClientTest() throws Exception { /* start the server */ ss = new ServerSocket(0); (new Thread(this)).start(); URL url = new URL("http://localhost:" + ss.getLocalPort() +"/"); // Run without a CookieHandler first InputStream in = url.openConnection().getInputStream(); while (in.read() != -1); // read response body so connection can be reused // Set a CookeHandler and retest using the HttpClient from the KAC CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); in = url.openConnection().getInputStream(); while (in.read() != -1); if (manager.getCookieStore().getCookies().isEmpty()) { throw new RuntimeException("Failed: No cookies in the cookie Handler."); } }
Example #19
Source File: BaseHttp.java From MousePaint with MIT License | 5 votes |
protected BaseHttp() { mGson = new Gson(); mOkHttpClient = new OkHttpClient(); mHandler = new Handler(Looper.getMainLooper()); //cookie enabled mOkHttpClient.setCookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ORIGINAL_SERVER)); }
Example #20
Source File: CookieHttpsClientTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
void doClientSide() throws Exception { // Wait for server to get started. while (!serverReady) { Thread.sleep(50); } HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; }}); URL url = new URL("https://localhost:" + serverPort +"/"); // Run without a CookieHandler first InputStream in = url.openConnection().getInputStream(); while (in.read() != -1); // read response body so connection can be reused // Set a CookeHandler and retest using the HttpClient from the KAC CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); in = url.openConnection().getInputStream(); while (in.read() != -1); if (manager.getCookieStore().getCookies().isEmpty()) { throw new RuntimeException("Failed: No cookies in the cookie Handler."); } }
Example #21
Source File: OkHttpUtils.java From SimpleNews with Apache License 2.0 | 5 votes |
private OkHttpUtils() { mOkHttpClient = new OkHttpClient(); mOkHttpClient.setConnectTimeout(10, TimeUnit.SECONDS); mOkHttpClient.setWriteTimeout(10, TimeUnit.SECONDS); mOkHttpClient.setReadTimeout(30, TimeUnit.SECONDS); //cookie enabled mOkHttpClient.setCookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ORIGINAL_SERVER)); mDelivery = new Handler(Looper.getMainLooper()); }
Example #22
Source File: HttpOnly.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
void populateCookieStore(URI uri) throws IOException { CookieManager cm = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(cm); Map<String,List<String>> header = new HashMap<>(); List<String> values = new ArrayList<>(); values.add("JSESSIONID=" + SESSION_ID + "; version=1; Path=" + URI_PATH +"; HttpOnly"); values.add("CUSTOMER=WILE_E_COYOTE; version=1; Path=" + URI_PATH); header.put("Set-Cookie", values); cm.put(uri, header); }
Example #23
Source File: CookieHttpClientTest.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
CookieHttpClientTest() throws Exception { /* start the server */ ss = new ServerSocket(0); (new Thread(this)).start(); URL url = new URL("http://localhost:" + ss.getLocalPort() +"/"); // Run without a CookieHandler first InputStream in = url.openConnection().getInputStream(); while (in.read() != -1); // read response body so connection can be reused // Set a CookeHandler and retest using the HttpClient from the KAC CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); in = url.openConnection().getInputStream(); while (in.read() != -1); if (manager.getCookieStore().getCookies().isEmpty()) { throw new RuntimeException("Failed: No cookies in the cookie Handler."); } }
Example #24
Source File: HttpOnly.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
void populateCookieStore(URI uri) throws IOException { CookieManager cm = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(cm); Map<String,List<String>> header = new HashMap<>(); List<String> values = new ArrayList<>(); values.add("JSESSIONID=" + SESSION_ID + "; version=1; Path=" + URI_PATH +"; HttpOnly"); values.add("CUSTOMER=WILE_E_COYOTE; version=1; Path=" + URI_PATH); header.put("Set-Cookie", values); cm.put(uri, header); }
Example #25
Source File: CookieHttpsClientTest.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
void doClientSide() throws Exception { // Wait for server to get started. while (!serverReady) { Thread.sleep(50); } HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; }}); URL url = new URL("https://localhost:" + serverPort +"/"); // Run without a CookieHandler first InputStream in = url.openConnection().getInputStream(); while (in.read() != -1); // read response body so connection can be reused // Set a CookeHandler and retest using the HttpClient from the KAC CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); in = url.openConnection().getInputStream(); while (in.read() != -1); if (manager.getCookieStore().getCookies().isEmpty()) { throw new RuntimeException("Failed: No cookies in the cookie Handler."); } }
Example #26
Source File: AbstractCookiesTest.java From j2objc with Apache License 2.0 | 5 votes |
private CookieManager store(String[][] cookies, Map<String, List<String>> responseHeaders, CookiePolicy policy) throws IOException, URISyntaxException { CookieManager manager = new CookieManager(createCookieStore(), policy); // Put all cookies into manager for (int i = 0; i < cookies.length; i++) { for (int j = 2; j < cookies[i].length; j += 2) { URI uri = new URI(cookies[i][j]); manager.put(uri, responseHeaders); } } return manager; }
Example #27
Source File: HttpOnly.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
void populateCookieStore(URI uri) throws IOException { CookieManager cm = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(cm); Map<String,List<String>> header = new HashMap<>(); List<String> values = new ArrayList<>(); values.add("JSESSIONID=" + SESSION_ID + "; version=1; Path=" + URI_PATH +"; HttpOnly"); values.add("CUSTOMER=WILE_E_COYOTE; version=1; Path=" + URI_PATH); header.put("Set-Cookie", values); cm.put(uri, header); }
Example #28
Source File: CookieHttpsClientTest.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
void doClientSide() throws Exception { // Wait for server to get started. while (!serverReady) { Thread.sleep(50); } HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; }}); URL url = new URL("https://localhost:" + serverPort +"/"); // Run without a CookieHandler first InputStream in = url.openConnection().getInputStream(); while (in.read() != -1); // read response body so connection can be reused // Set a CookeHandler and retest using the HttpClient from the KAC CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); in = url.openConnection().getInputStream(); while (in.read() != -1); if (manager.getCookieStore().getCookies().isEmpty()) { throw new RuntimeException("Failed: No cookies in the cookie Handler."); } }
Example #29
Source File: WallabagConnection.java From android-app with GNU General Public License v3.0 | 5 votes |
private static OkHttpClient.Builder getClientBuilder(boolean addCookieManager) { OkHttpClient.Builder b = new OkHttpClient.Builder() .readTimeout(45, TimeUnit.SECONDS); if(addCookieManager) { b.cookieJar(new JavaNetCookieJar(new CookieManager(null, CookiePolicy.ACCEPT_ALL))); } if(BuildConfig.DEBUG) { b.addInterceptor(new LoggingInterceptor()); b.addNetworkInterceptor(new StethoInterceptor()); } return b; }
Example #30
Source File: CookieHttpsClientTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
void doClientSide() throws Exception { // Wait for server to get started. while (!serverReady) { Thread.sleep(50); } HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; }}); URL url = new URL("https://localhost:" + serverPort +"/"); // Run without a CookieHandler first InputStream in = url.openConnection().getInputStream(); while (in.read() != -1); // read response body so connection can be reused // Set a CookeHandler and retest using the HttpClient from the KAC CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); in = url.openConnection().getInputStream(); while (in.read() != -1); if (manager.getCookieStore().getCookies().isEmpty()) { throw new RuntimeException("Failed: No cookies in the cookie Handler."); } }