Package java.net

Examples of java.net.ProxySelector


  /**
   * @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


            // 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

                + 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

                + 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

                + 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

                + 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

                + 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

                                      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

            assertThat(expectedProxyHost, is(httpRoute.getProxyHost().getHostName()));
        }
    }

    private void assertGlobalProxyHost(String expectedProxyHost) {
        ProxySelector proxySelector = ProxySelector.getDefault();
        Proxy globalProxy = null;
        if (proxySelector != null) {
            List<Proxy> globalProxies = proxySelector.select(URI.create("http://soapui.org/"));
            assertThat(globalProxies.size(), is(1));
            globalProxy = globalProxies.get(0);
        }

        if (expectedProxyHost == null) {
View Full Code Here

    assertThat(content).contains("agent");
  }

  @Test
  public void shouldGetDirectProxySynthesis() throws URISyntaxException {
    ProxySelector proxySelector = mock(ProxySelector.class);
    when(proxySelector.select(any(URI.class))).thenReturn(Arrays.asList(Proxy.NO_PROXY));
    assertThat(HttpDownloader.BaseHttpDownloader.getProxySynthesis(new URI("http://an_url"), proxySelector)).isEqualTo("no proxy");
  }
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.