Package java.net

Examples of java.net.ProxySelector


  /**
   * @tests java.net.ProxySelector#getDefault()
   */
  public void test_getDefault() {
    ProxySelector selector1 = ProxySelector.getDefault();
    assertNotNull(selector1);

    ProxySelector selector2 = ProxySelector.getDefault();
    assertSame(selector1, selector2);
  }
View Full Code Here


  /**
   * @tests java.net.ProxySelector#setDefault(ProxySelector)}
   */
  public void test_setDefaultLjava_net_ProxySelector() {
    ProxySelector originalSelector = ProxySelector.getDefault();
    try {
      ProxySelector newSelector = new MockProxySelector();
      ProxySelector.setDefault(newSelector);
      assertSame(newSelector, ProxySelector.getDefault());
      // use null to unset
      ProxySelector.setDefault(null);
      assertSame(null, ProxySelector.getDefault());
View Full Code Here

  /**
   * @tests java.net.ProxySelector#setDefault(ProxySelector)}
   */
  public void test_setDefaultLjava_net_ProxySelector_Security() {
    ProxySelector originalSelector = ProxySelector.getDefault();
    SecurityManager originalSecurityManager = System.getSecurityManager();
    try {
      System.setSecurityManager(new MockSecurityManager());
    } catch (SecurityException e) {
      System.err.println("No setSecurityManager permission.");
View Full Code Here

        MockServer proxy = new MockServer("proxy");

        URL url = new URL("http://localhost:" + server.port());

        // keep default proxy selector
        ProxySelector defPS = ProxySelector.getDefault();
        // replace selector
        ProxySelector.setDefault(new TestProxySelector(server.port(), proxy
                .port()));

        try {
View Full Code Here

            // IOException will be thrown in the case of failure
            connection = getHTTPConnection(proxy);
        } else {
            // Use system-wide ProxySelect to select proxy list,
            // then try to connect via elements in the proxy list.
            ProxySelector selector = ProxySelector.getDefault();
            List<Proxy> proxyList = selector.select(uri);
            if (proxyList != null) {
                for (Proxy selectedProxy : proxyList) {
                    if (selectedProxy.type() == Proxy.Type.DIRECT) {
                        // the same as NO_PROXY
                        continue;
                    }
                    try {
                        connection = getHTTPConnection(selectedProxy);
                        proxy = selectedProxy;
                        break; // connected
                    } catch (IOException e) {
                        // failed to connect, tell it to the selector
                        selector.connectFailed(uri, selectedProxy.address(), e);
                    }
                }
            }
        }
        if (connection == null) {
View Full Code Here

                                      HttpRequest request,
                                      HttpContext context)
        throws HttpException {

        // the proxy selector can be 'unset', so we better deal with null here
        ProxySelector psel = this.proxySelector;
        if (psel == null)
            psel = ProxySelector.getDefault();
        if (psel == null)
            return null;

        URI targetURI = null;
        try {
            targetURI = new URI(target.toURI());
        } catch (URISyntaxException usx) {
            throw new HttpException
                ("Cannot convert host to URI: " + target, usx);
        }
        List<Proxy> proxies = psel.select(targetURI);

        Proxy p = chooseProxy(proxies, target, request, context);

        HttpHost result = null;
        if (p.type() == Proxy.Type.HTTP) {
View Full Code Here

        MockServer proxy = new MockServer("proxy");

        URL url = new URL("http://localhost:" + server.port());

        // keep default proxy selector
        ProxySelector defPS = ProxySelector.getDefault();
        // replace selector
        ProxySelector.setDefault(new TestProxySelector(server.port(), proxy
                .port()));

        try {
View Full Code Here

                                      HttpRequest request,
                                      HttpContext context)
        throws HttpException {

        // the proxy selector can be 'unset', so we better deal with null here
        ProxySelector psel = this.proxySelector;
        if (psel == null)
            psel = ProxySelector.getDefault();
        if (psel == null)
            return null;

        URI targetURI = null;
        try {
            targetURI = new URI(target.toURI());
        } catch (URISyntaxException usx) {
            throw new HttpException
                ("Cannot convert host to URI: " + target, usx);
        }
        List<Proxy> proxies = psel.select(targetURI);

        Proxy p = chooseProxy(proxies, target, request, context);

        HttpHost result = null;
        if (p.type() == Proxy.Type.HTTP) {
View Full Code Here

  /**
   * @tests java.net.ProxySelector#getDefault()
   */
  public void test_getDefault() {
    ProxySelector selector1 = ProxySelector.getDefault();
    assertNotNull(selector1);

    ProxySelector selector2 = ProxySelector.getDefault();
    assertSame(selector1, selector2);
  }
View Full Code Here

  /**
   * @tests java.net.ProxySelector#setDefault(ProxySelector)}
   */
  public void test_setDefaultLjava_net_ProxySelector() {
    ProxySelector originalSelector = ProxySelector.getDefault();
    try {
      ProxySelector newSelector = new MockProxySelector();
      ProxySelector.setDefault(newSelector);
      assertSame(newSelector, ProxySelector.getDefault());
      // use null to unset
      ProxySelector.setDefault(null);
      assertSame(null, ProxySelector.getDefault());
View Full Code Here

TOP

Related Classes of java.net.ProxySelector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.