Java 8 ProxySelector - 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 ProxySelector class.

This code example shows how to use the following methods:select
        System.clearProperty("socksProxyHost");
        System.clearProperty("socksProxyPort");
    } 
 
    public void testNoProxySystemProperty() throws URISyntaxException { 
        assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(ftpUri));
        assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(httpUri));
        assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(httpsUri));
        assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(socketUri));
        assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(otherUri));
    } 
 
    public void testProxyHostOnly() throws URISyntaxException { 
        System.setProperty("ftp.proxyHost", "a");
        System.setProperty("http.proxyHost", "b");
        System.setProperty("https.proxyHost", "c");
        System.setProperty("other.proxyHost", "d");
        System.setProperty("socket.proxyHost", "d");
        assertEquals(Arrays.asList(new Proxy(Proxy.Type.HTTP, createUnresolved("a", 80))),
                proxySelector.select(ftpUri));
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:select
        System.clearProperty("proxyHost");
        System.clearProperty("proxyPort");
    } 
 
    public void testNoProxySystemProperty() throws URISyntaxException { 
        assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(ftpUri));
        assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(httpUri));
        assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(httpsUri));
        assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(socketUri));
        assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(otherUri));
    } 
 
    public void testProxyHostOnly() throws URISyntaxException { 
        System.setProperty("ftp.proxyHost", "a");
        System.setProperty("http.proxyHost", "b");
        System.setProperty("https.proxyHost", "c");
        System.setProperty("other.proxyHost", "d");
        System.setProperty("socket.proxyHost", "d");
        assertEquals(Arrays.asList(new Proxy(Proxy.Type.HTTP, createUnresolved("a", 80))),
                proxySelector.select(ftpUri));
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:select
 
  private List<Proxy> selectDefault(final URI uri)
  { 
    if (defaultSelector != null)
    { 
      return defaultSelector.select(uri);
    } 
 
    final List<Proxy> list = new ArrayList<Proxy>();
    list.add(Proxy.NO_PROXY);
    return list;
  } 
 
  /** 
   * Called to indicate that a connection could not be established 
   * to a proxy/socks server. An implementation of this method can 
   * temporarily remove the proxies or reorder the sequence of 
   * proxies returned by select(String, String), using the address 
   * and they kind of IOException given. 
   * 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:select
  private void resetNextProxy(URI uri, Proxy proxy) {
    this.hasNextProxy = true; // This includes NO_PROXY!
    if (proxy != null) {
      this.userSpecifiedProxy = proxy;
    } else { 
      List<Proxy> proxyList = proxySelector.select(uri);
      if (proxyList != null) {
        this.proxySelectorProxies = proxyList.iterator();
      } 
    } 
  } 
 
  /** Returns true if there's another proxy to try. */ 
  private boolean hasNextProxy() { 
    return hasNextProxy;
  } 
 
  /** Returns the next proxy to try. May be PROXY.NO_PROXY but never null. */ 
  private Proxy nextProxy() {
    // If the user specifies a proxy, try that and only that. 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:select
		ProxySelector selector = this.fallbackSelector;
		String protocol = uri.getScheme();
		if (protocol != null && this.selectors.get(protocol) != null) {
			selector = this.selectors.get(protocol);
		} 
		return selector.select(uri);
	} 
 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:select
  private void resetNextProxy(URI uri, Proxy proxy) {
    this.hasNextProxy = true; // This includes NO_PROXY!
    if (proxy != null) {
      this.userSpecifiedProxy = proxy;
    } else { 
      List<Proxy> proxyList = proxySelector.select(uri);
      if (proxyList != null) {
        this.proxySelectorProxies = proxyList.iterator();
      } 
    } 
  } 
 
  /** Returns true if there's another proxy to try. */ 
  private boolean hasNextProxy() { 
    return hasNextProxy;
  } 
 
  /** Returns the next proxy to try. May be PROXY.NO_PROXY but never null. */ 
  private Proxy nextProxy() {
    // If the user specifies a proxy, try that and only that. 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:connectFailed
	 */ 
	public void test_connectionFailedLjava_net_URILjava_net_SocketAddressLjava_io_IOException_IllegalArguement() 
			throws URISyntaxException { 
		SocketAddress sa = InetSocketAddress.createUnresolved("127.0.0.1", 0);
		try { 
			selector.connectFailed(null, sa, new SocketException());
			fail("should throw IllegalArgumentException if any argument is null.");
		} catch (IllegalArgumentException e) {
			// expected 
		} 
		try { 
			selector.connectFailed(httpUri, null, new SocketException());
			fail("should throw IllegalArgumentException if any argument is null.");
		} catch (IllegalArgumentException e) {
			// expected 
		} 
		try { 
			selector.connectFailed(httpUri, sa, null);
			fail("should throw IllegalArgumentException if any argument is null.");
		} catch (IllegalArgumentException e) {

4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:select
 
  private List<Proxy> selectDefault(final URI uri)
  { 
    if (defaultSelector != null)
    { 
      return defaultSelector.select(uri);
    } 
 
    final List<Proxy> list = new ArrayList<Proxy>();
    list.add(Proxy.NO_PROXY);
    return list;
  } 
 
  /** 
   * Called to indicate that a connection could not be established 
   * to a proxy/socks server. An implementation of this method can 
   * temporarily remove the proxies or reorder the sequence of 
   * proxies returned by select(String, String), using the address 
   * and they kind of IOException given. 
   * 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:select
  private void resetNextProxy(URI uri, Proxy proxy) {
    this.hasNextProxy = true; // This includes NO_PROXY!
    if (proxy != null) {
      this.userSpecifiedProxy = proxy;
    } else { 
      List<Proxy> proxyList = proxySelector.select(uri);
      if (proxyList != null) {
        this.proxySelectorProxies = proxyList.iterator();
      } 
    } 
  } 
 
  /** Returns true if there's another proxy to try. */ 
  private boolean hasNextProxy() { 
    return hasNextProxy;
  } 
 
  /** Returns the next proxy to try. May be PROXY.NO_PROXY but never null. */ 
  private Proxy nextProxy() {
    // If the user specifies a proxy, try that and only that. 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setDefault
			PROXIES.add(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(InetAddress.getLocalHost(), 80)));
		} catch (UnknownHostException e) {}
	} 
 
	public static void main(String[] args) throws UnknownHostException, IOException {
		ProxySelector.setDefault(new ProxySelector() {
			@Override 
			public List<Proxy> select(URI uri) {
				return PROXIES;
			} 
 
			@Override 
			public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
				 
			} 
		}); 
 
//		 java.net.Socket client = new java.net.Socket("www.baidu.com", 80); 
	} 
} 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Java 8 ProxySelector Methods: