Java 8 CookieManager - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 CookieManager class.

This code example shows how to use the following methods:get, put, setCookiePolicy
     */ 
    public void test_SetCookiePolicy_LCookiePolicy() throws URISyntaxException, 
            IOException { 
 
        // Policy = ACCEPT_NONE 
        CookieManager manager = new CookieManager();
        manager.setCookiePolicy(CookiePolicy.ACCEPT_NONE);
        Map<String, List<String>> responseHeaders = new TreeMap<String, List<String>>();        
        URI uri = new URI("http://a.b.c");
        manager.put(uri, responseHeaders);
        Map<String, List<String>> map = manager.get(uri,
                new HashMap<String, List<String>>());
 
        assertEquals(1, map.size());
        assertTrue(map.get("Cookie").isEmpty());
        Object key = map.keySet().toArray()[0];
        assertNotNull(key);
        assertEquals("Cookie", key);
 
        // Policy = ACCEPT_ALL 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getCookieStore
{ 
    private final CookieStore delegate;
 
    public HttpCookieStore() 
    { 
        delegate = new CookieManager().getCookieStore();
    } 
 
    @Override 
    public void add(URI uri, HttpCookie cookie)
    { 
        delegate.add(uri, cookie);
    } 
 
    @Override 
    public List<HttpCookie> get(URI uri)
    { 
        return delegate.get(uri);
    } 
 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setCookiePolicy
		initCookieManager(); 
		performAuthenticationRequest(endpoint);
	} 
 
	private void initCookieManager() { 
		CookieManager manager = new CookieManager();
		manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
		CookieHandler.setDefault(manager);
	} 
 
	private void performAuthenticationRequest(GerritEndpoint endpoint) {
		String loginUrl = appendPath(endpoint.getUrl(), "login/");
		HttpRequest request = createRequest(endpoint, loginUrl);
		processRequest(endpoint, request);
	} 
 
	private HttpRequest createRequest(GerritEndpoint endpoint, String loginUrl) {
		HttpRequest request = HttpRequest.get(loginUrl);
		request.acceptGzipEncoding().uncompress(true).trustAllCerts().trustAllHosts();
		request.basic(endpoint.getUsername(), endpoint.getPassword());
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:put
    } 
 
    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);
    } 
 
    void doClient(URI uri) throws Exception {
        HttpURLConnection uc = (HttpURLConnection) uri.toURL().openConnection();
        int resp = uc.getResponseCode();
        check(resp == 200,
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
        final ProtocolChannelClient.Configuration configuration = new ProtocolChannelClient.Configuration();
 
        if(client.getProtocol() == null) {
            // WFLY-1462 for compatibility assume remoting if the standard native port is configured 
            String protocol = client.getPort() == 9999 ? "remote://" : "http-remoting://";
            configuration.setUri(new URI(protocol + formatPossibleIpv6Address(client.getHost()) +  ":" + client.getPort()));
        } else  { 
            configuration.setUri(new URI(client.getProtocol() + "://" + formatPossibleIpv6Address(client.getHost()) +  ":" + client.getPort()));
        } 
        configuration.setOptionMap(DEFAULT_OPTIONS);
        final long timeout = client.getConnectionTimeout();
        if(timeout > 0) {
            configuration.setConnectionTimeout(timeout);
        } 
        return configuration;
    } 
 
    private static String formatPossibleIpv6Address(String address) {
        if (address == null) {
            return address;
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getHost, getPort, getUserInfo
 
    public  Context getRemoteContext() throws Exception {
        final Properties env = new Properties();
        env.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName());
        URI webUri = managementClient.getWebUri();
        URI namingUri = new URI("http-remoting", webUri.getUserInfo(), webUri.getHost(), webUri.getPort(), "", "" ,"");
        env.put(Context.PROVIDER_URL, namingUri.toString());
        env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
        env.put("jboss.naming.client.security.callback.handler.class", CallbackHandler.class.getName());
        return new InitialContext(env);
    } 
 
    @Test 
    public void testRemoteLookup() throws Exception { 
        Context context = null;
        try { 
            context = getRemoteContext();
            assertEquals("TestValue", context.lookup("test"));
        } finally { 
            if (context != null)
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getHost, getPath, getPort, getUserInfo
		    new GenericObjectPoolConfig()); 
	} 
    } 
 
    public JedisPool(final URI uri) {
	String h = uri.getHost();
	int port = uri.getPort();
	String password = uri.getUserInfo().split(":", 2)[1];
	int database = Integer.parseInt(uri.getPath().split("/", 2)[1]);
	this.internalPool = new GenericObjectPool<Jedis>(new JedisFactory(h,
		port, Protocol.DEFAULT_TIMEOUT, password, database, null),
		new GenericObjectPoolConfig()); 
    } 
 
    public JedisPool(final GenericObjectPoolConfig poolConfig,
	    final String host, int port, int timeout, final String password) {
	this(poolConfig, host, port, timeout, password,
		Protocol.DEFAULT_DATABASE, null); 
    } 
 
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
  @Override 
  public URI getTrackingUri(ApplicationId id) throws URISyntaxException { 
    String jobSuffix = id.toString().replaceFirst("^application_", "job_"); 
    String historyServerAddress = 
        MRWebAppUtil.getJHSWebappURLWithScheme(getConf()); 
    return new URI(historyServerAddress + "/jobhistory/job/"+ jobSuffix); 
  } 
} 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getHost, getPort
        if (host == null) {
            String referrer = request.getHeader("referer");
            if (referrer != null) {
                URI url;
                try { 
                    url = new URI(referrer);
                    int port = url.getPort();
                    host = url.getHost() + ((port > -1) ? ":" + url.getPort() : "");
                } catch (URISyntaxException e) {
                    throw new RuntimeException("referrer '" + referrer + "' can't be parsed as a URL");
                } 
            } else { 
                throw new RuntimeException("neither the 'host' nor 'referer' headers were present in the HTTP response, I can't determine what URL OpenRefine is listening to.");
            } 
        } 
        return "http://" + host + "/command/core/authorize/" + provider.getHost();
    } 
} 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getHost, getPort
    AndroidHttpClient client = null;
 
    try { 
      Log.w("MmsSender", "Sending MMS1 of length: " + (mms != null ? mms.length : "null"));
      client                 = constructHttpClient(context, parameters);
      URI targetUrl          = new URI(parameters.getMmsc());
      HttpHost target        = new HttpHost(targetUrl.getHost(), targetUrl.getPort(), HttpHost.DEFAULT_SCHEME_NAME);
      HttpPost request       = new HttpPost(parameters.getMmsc());
      ByteArrayEntity entity = new ByteArrayEntity(mms);
 
      entity.setContentType("application/vnd.wap.mms-message");
 
      request.setEntity(entity);
      request.setParams(client.getParams());
      request.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");
//      request.addHeader("x-wap-profile", "http://www.htcmms.com.tw/Android/Common/nexusone/ua-profile.xml"); 
      request.addHeader("x-wap-profile", "http://www.google.com/oha/rdf/ua-profile-kila.xml");
      HttpResponse response = client.execute(target, request);
      StatusLine status     = response.getStatusLine();
 
8
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Java 8 CookieManager Questions & Answers:

See Code Examples for Java 8 CookieManager Methods: