Package java.net

Examples of java.net.ProxySelector


        }
        if (null == proxyList) {
            currentProxy = null;
            connectInternal();
        } else {
            ProxySelector selector = ProxySelector.getDefault();
            Iterator<Proxy> iter = proxyList.iterator();
            boolean connectOK = false;
            while (iter.hasNext() && !connectOK) {
                currentProxy = iter.next();
                try {
                    connectInternal();
                    connectOK = true;
                } catch (IOException ioe) {
                    // If connect failed, callback "connectFailed"
                    // should be invoked.
                    if (null != selector && Proxy.NO_PROXY != currentProxy) {
                        selector.connectFailed(uri, currentProxy.address(), ioe);
                    }
                }
            }
            if (!connectOK) {
                throw new IOException(Msg.getString("K0097"));
View Full Code Here


            // IOException will be thrown in the case of failure
            socket = 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 {
                        socket = getHTTPConnection(selectedProxy);
                        proxy = selectedProxy;
                        break; // connected
                    } catch (IOException e) {
                        // failed to connect, tell it to the selector
                        selector.connectFailed(uri, selectedProxy.address(), e);
                    }
                }
            }
        }
        if (socket == null) {
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

        }
        if (null == proxyList) {
            currentProxy = null;
            connectInternal();
        } else {
            ProxySelector selector = ProxySelector.getDefault();
            Iterator<Proxy> iter = proxyList.iterator();
            boolean connectOK = false;
            String failureReason = ""; //$NON-NLS-1$
            while (iter.hasNext() && !connectOK) {
                currentProxy = iter.next();
                try {
                    connectInternal();
                    connectOK = true;
                } catch (IOException ioe) {
                    failureReason = ioe.getLocalizedMessage();
                    // If connect failed, callback "connectFailed"
                    // should be invoked.
                    if (null != selector && Proxy.NO_PROXY != currentProxy) {
                        selector.connectFailed(uri, currentProxy.address(), ioe);
                    }
                }
            }
            if (!connectOK) {
                // K0097=Unable to connect to server\: {0}
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

                + Support_Configuration.ProxyServerTestHost
                + "/cgi-bin/test.pl");
        URL ftpUrl = new URL("ftp://" + Support_Configuration.FTPTestAddress
                + "/nettest.txt");
        URL[] urlList = { httpUrl, ftpUrl };
        ProxySelector originalSelector = ProxySelector.getDefault();
        ProxySelector.setDefault(new MockProxySelector());
        try {
            for (int i = 0; i < urlList.length; ++i) {
                try {
                    isSelectCalled = false;
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

        + Support_Configuration.ProxyServerTestHost
        + "/cgi-bin/test.pl");
    URL ftpUrl = new URL("ftp://" + Support_Configuration.FTPTestAddress
        + "/nettest.txt");
    URL[] urlList = { httpUrl, ftpUrl };
    ProxySelector originalSelector = ProxySelector.getDefault();
    ProxySelector.setDefault(new MockProxySelector());
    try {
      for (int i = 0; i < urlList.length; ++i) {
        try {
          isSelectCalled = false;
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_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

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.