当前位置: 首页>>代码示例>>Java>>正文


Java ProxySelector类代码示例

本文整理汇总了Java中java.net.ProxySelector的典型用法代码示例。如果您正苦于以下问题:Java ProxySelector类的具体用法?Java ProxySelector怎么用?Java ProxySelector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ProxySelector类属于java.net包,在下文中一共展示了ProxySelector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: Address

import java.net.ProxySelector; //导入依赖的package包/类
public Address(String uriHost, int uriPort, Dns dns, SocketFactory socketFactory,
    SSLSocketFactory sslSocketFactory, HostnameVerifier hostnameVerifier,
    CertificatePinner certificatePinner, Authenticator proxyAuthenticator, Proxy proxy,
    List<Protocol> protocols, List<ConnectionSpec> connectionSpecs, ProxySelector proxySelector) {
  this.url = new HttpUrl.Builder()
      .scheme(sslSocketFactory != null ? "https" : "http")
      .host(uriHost)
      .port(uriPort)
      .build();

  if (dns == null) throw new NullPointerException("dns == null");
  this.dns = dns;

  if (socketFactory == null) throw new NullPointerException("socketFactory == null");
  this.socketFactory = socketFactory;

  if (proxyAuthenticator == null) {
    throw new NullPointerException("proxyAuthenticator == null");
  }
  this.proxyAuthenticator = proxyAuthenticator;

  if (protocols == null) throw new NullPointerException("protocols == null");
  this.protocols = Util.immutableList(protocols);

  if (connectionSpecs == null) throw new NullPointerException("connectionSpecs == null");
  this.connectionSpecs = Util.immutableList(connectionSpecs);

  if (proxySelector == null) throw new NullPointerException("proxySelector == null");
  this.proxySelector = proxySelector;

  this.proxy = proxy;
  this.sslSocketFactory = sslSocketFactory;
  this.hostnameVerifier = hostnameVerifier;
  this.certificatePinner = certificatePinner;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:36,代码来源:Address.java

示例2: copyWithDefaults

import java.net.ProxySelector; //导入依赖的package包/类
OkHttpClient copyWithDefaults() {
    OkHttpClient result = new OkHttpClient(this);
    if (result.proxySelector == null) {
        result.proxySelector = ProxySelector.getDefault();
    }
    if (result.cookieHandler == null) {
        result.cookieHandler = CookieHandler.getDefault();
    }
    if (result.socketFactory == null) {
        result.socketFactory = SocketFactory.getDefault();
    }
    if (result.sslSocketFactory == null) {
        result.sslSocketFactory = getDefaultSSLSocketFactory();
    }
    if (result.hostnameVerifier == null) {
        result.hostnameVerifier = OkHostnameVerifier.INSTANCE;
    }
    if (result.certificatePinner == null) {
        result.certificatePinner = CertificatePinner.DEFAULT;
    }
    if (result.authenticator == null) {
        result.authenticator = AuthenticatorAdapter.INSTANCE;
    }
    if (result.connectionPool == null) {
        result.connectionPool = ConnectionPool.getDefault();
    }
    if (result.protocols == null) {
        result.protocols = DEFAULT_PROTOCOLS;
    }
    if (result.connectionSpecs == null) {
        result.connectionSpecs = DEFAULT_CONNECTION_SPECS;
    }
    if (result.dns == null) {
        result.dns = Dns.SYSTEM;
    }
    return result;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:38,代码来源:OkHttpClient.java

示例3: Address

import java.net.ProxySelector; //导入依赖的package包/类
public Address(String uriHost, int uriPort, Dns dns, SocketFactory socketFactory,
    @Nullable SSLSocketFactory sslSocketFactory, @Nullable HostnameVerifier hostnameVerifier,
    @Nullable CertificatePinner certificatePinner, Authenticator proxyAuthenticator,
    @Nullable Proxy proxy, List<Protocol> protocols, List<ConnectionSpec> connectionSpecs,
    ProxySelector proxySelector) {
  this.url = new HttpUrl.Builder()
      .scheme(sslSocketFactory != null ? "https" : "http")
      .host(uriHost)
      .port(uriPort)
      .build();

  if (dns == null) throw new NullPointerException("dns == null");
  this.dns = dns;

  if (socketFactory == null) throw new NullPointerException("socketFactory == null");
  this.socketFactory = socketFactory;

  if (proxyAuthenticator == null) {
    throw new NullPointerException("proxyAuthenticator == null");
  }
  this.proxyAuthenticator = proxyAuthenticator;

  if (protocols == null) throw new NullPointerException("protocols == null");
  this.protocols = Util.immutableList(protocols);

  if (connectionSpecs == null) throw new NullPointerException("connectionSpecs == null");
  this.connectionSpecs = Util.immutableList(connectionSpecs);

  if (proxySelector == null) throw new NullPointerException("proxySelector == null");
  this.proxySelector = proxySelector;

  this.proxy = proxy;
  this.sslSocketFactory = sslSocketFactory;
  this.hostnameVerifier = hostnameVerifier;
  this.certificatePinner = certificatePinner;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:37,代码来源:Address.java

示例4: copyWithDefaults

import java.net.ProxySelector; //导入依赖的package包/类
/**
 * Returns a shallow copy of this OkHttpClient that uses the system-wide default for
 * each field that hasn't been explicitly configured.
 */
private OkHttpClient copyWithDefaults() {
  OkHttpClient result = new OkHttpClient(this);
  result.proxy = proxy;
  result.proxySelector = proxySelector != null ? proxySelector : ProxySelector.getDefault();
  result.cookieHandler = cookieHandler != null ? cookieHandler : CookieHandler.getDefault();
  result.responseCache = responseCache != null ? responseCache : ResponseCache.getDefault();
  result.sslSocketFactory = sslSocketFactory != null
      ? sslSocketFactory
      : HttpsURLConnection.getDefaultSSLSocketFactory();
  result.hostnameVerifier = hostnameVerifier != null
      ? hostnameVerifier
      : OkHostnameVerifier.INSTANCE;
  result.authenticator = authenticator != null
      ? authenticator
      : HttpAuthenticator.SYSTEM_DEFAULT;
  result.connectionPool = connectionPool != null ? connectionPool : ConnectionPool.getDefault();
  result.followProtocolRedirects = followProtocolRedirects;
  result.transports = transports != null ? transports : DEFAULT_TRANSPORTS;
  result.connectTimeout = connectTimeout;
  result.readTimeout = readTimeout;
  return result;
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:27,代码来源:OkHttpClient.java

示例5: retrieveDocument

import java.net.ProxySelector; //导入依赖的package包/类
public HashMap<String, InputStream> retrieveDocument(String baseAddress,
        String documentAddress) throws IOException,URISyntaxException{
    
    String effAddr = getEffectiveAddress(baseAddress, documentAddress);
    if(effAddr == null)
        return null;
    URI currURI = new URI(effAddr);
    HashMap<String, InputStream> result = null;
    
    InputStream is = getInputStreamOfURL(currURI.toURL(), ProxySelector.
            getDefault().select(currURI).get(0));
    result = new HashMap<String, InputStream>();
    result.put(effectiveURL.toString(), is);
    return result;
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:URLResourceRetriever.java

示例6: createEndpoint

import java.net.ProxySelector; //导入依赖的package包/类
private Endpoint createEndpoint() throws IOException {
    URL realUrl = getUrl();
    try {
        if ("https".equals(realUrl.getProtocol())) { // NOI18N
            SSLContext context = ContextProvider.getInstance().getSSLContext(instance);
            return Endpoint.forSocket(context.getSocketFactory().createSocket(realUrl.getHost(), realUrl.getPort()));
        } else if ("http".equals(realUrl.getProtocol())) { // NOI18N
            Socket s = new Socket(ProxySelector.getDefault().select(realUrl.toURI()).get(0));
            int port = realUrl.getPort();
            if (port < 0) {
                port = realUrl.getDefaultPort();
            }
            s.connect(new InetSocketAddress(realUrl.getHost(), port));
            return Endpoint.forSocket(s);
        } else {
            throw new IOException("Unknown protocol: " + realUrl.getProtocol());
        }
    } catch (URISyntaxException ex) {
        throw new IOException(ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:DockerAction.java

示例7: setUp

import java.net.ProxySelector; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
    super.setUp();
    System.setProperty("netbeans.user", getWorkDir().getAbsolutePath());
    
    // reset
    Method m = MylynSupport.class.getDeclaredMethod("reset", new Class[0]);
    m.setAccessible(true);
    m.invoke(MylynSupport.class);
            
    Field f = Bugzilla.class.getDeclaredField("instance");
    f.setAccessible(true);
    f.set(Bugzilla.class, null);
    
    brc = Bugzilla.getInstance().getRepositoryConnector();
    
    WebUtil.init();
    
    if (defaultPS == null) {
        defaultPS = ProxySelector.getDefault();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:ExceptionHandlerTest.java

示例8: testIgnoring

import java.net.ProxySelector; //导入依赖的package包/类
@Test // https://github.com/danikula/AndroidVideoCache/issues/28
public void testIgnoring() throws Exception {
    InetSocketAddress proxyAddress = new InetSocketAddress("proxy.com", 80);
    Proxy systemProxy = new Proxy(Proxy.Type.HTTP, proxyAddress);
    ProxySelector mockedProxySelector = Mockito.mock(ProxySelector.class);
    when(mockedProxySelector.select(Mockito.<URI>any())).thenReturn(Lists.newArrayList(systemProxy));
    ProxySelector.setDefault(mockedProxySelector);

    IgnoreHostProxySelector.install("localhost", 42);

    ProxySelector proxySelector = ProxySelector.getDefault();
    List<Proxy> githubProxies = proxySelector.select(new URI("http://github.com"));
    assertThat(githubProxies).hasSize(1);
    assertThat(githubProxies.get(0).address()).isEqualTo(proxyAddress);

    List<Proxy> localhostProxies = proxySelector.select(new URI("http://localhost:42"));
    assertThat(localhostProxies).hasSize(1);
    assertThat(localhostProxies.get(0)).isEqualTo(Proxy.NO_PROXY);

    List<Proxy> localhostPort69Proxies = proxySelector.select(new URI("http://localhost:69"));
    assertThat(localhostPort69Proxies).hasSize(1);
    assertThat(localhostPort69Proxies.get(0).address()).isEqualTo(proxyAddress);
}
 
开发者ID:Achenglove,项目名称:AndroidVideoCache,代码行数:24,代码来源:ProxySelectorTest.java

示例9: chooseProxy

import java.net.ProxySelector; //导入依赖的package包/类
private Proxy chooseProxy() {
    ProxySelector sel =
        java.security.AccessController.doPrivileged(
            new java.security.PrivilegedAction<ProxySelector>() {
                @Override
                public ProxySelector run() {
                    return ProxySelector.getDefault();
                }
            });

    if(sel==null)
        return Proxy.NO_PROXY;


    if(!sel.getClass().getName().equals("sun.net.spi.DefaultProxySelector"))
        // user-defined proxy. may return a different proxy for each invocation
        return null;

    Iterator<Proxy> it = sel.select(uri).iterator();
    if(it.hasNext())
        return it.next();

    return Proxy.NO_PROXY;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:EndpointAddress.java

示例10: main

import java.net.ProxySelector; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    System.setProperty("java.net.useSystemProxies", "true");
    final ProxySelector ps = ProxySelector.getDefault();
    final URI uri = new URI("http://ubuntu.com");
    Thread[] threads = new Thread[NUM_THREADS];

    for (int i = 0; i < NUM_THREADS; i++) {
        threads[i] = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    ps.select(uri);
                } catch (Exception x) {
                    throw new RuntimeException(x);
                }
            }
        });
    }
    for (int i = 0; i < NUM_THREADS; i++) {
        threads[i].start();
    }
    for (int i = 0; i < NUM_THREADS; i++) {
        threads[i].join();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:MultiThreadedSystemProxies.java

示例11: getProxy

import java.net.ProxySelector; //导入依赖的package包/类
private static Proxy getProxy() {
	List<Proxy> l = null;
	try {
		final ProxySelector def = ProxySelector.getDefault();
		l = def.select(new URI("http://foo/bar"));
		ProxySelector.setDefault(null);
	} catch (final Exception e) {

	}
	if (l != null) {
		for (final Iterator<Proxy> iter = l.iterator(); iter.hasNext();) {
			final java.net.Proxy proxy = iter.next();
			return proxy;
		}
	}
	return null;
}
 
开发者ID:leolewis,项目名称:openvisualtraceroute,代码行数:18,代码来源:Env.java

示例12: initDefaultBuilder

import java.net.ProxySelector; //导入依赖的package包/类
/**
 * Initializes default http client builder instance
 * 
 * @return
 */
protected HttpClientBuilder initDefaultBuilder() {
	HttpClientBuilder builder = HttpClientBuilder.create();

	if (null != credentials) {
		CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
		credentialsProvider.setCredentials(AuthScope.ANY, credentials);
		builder.setDefaultCredentialsProvider(credentialsProvider);
	}

	builder.setMaxConnPerRoute(5);
	builder.setMaxConnTotal(20);
	// dirty hack to avoid npe in soapui client, soapui client sets default
	// proxy selector to null
	ProxySelector proxySelector = ProxySelector.getDefault();
	if (proxySelector != null)
		builder.setRoutePlanner(new SystemDefaultRoutePlanner(proxySelector));

	if (null != interceptors && !interceptors.isEmpty()) {
		for (HttpRequestInterceptor interceptor : interceptors) {
			builder.addInterceptorFirst(interceptor);
		}
	}

	return builder;
}
 
开发者ID:reportportal,项目名称:client-java-rest-core,代码行数:31,代码来源:AuthClientFactory.java

示例13: getProxySelector

import java.net.ProxySelector; //导入依赖的package包/类
/*************************************************************************
 * Loads the proxy settings from environment variables.
 * 
 * @return a configured ProxySelector, null if none is found.
 ************************************************************************/

@Override
public ProxySelector getProxySelector() {
  ProtocolDispatchSelector ps = new ProtocolDispatchSelector();

  Logger.log(getClass(), LogLevel.TRACE, "Using settings from Java System Properties");

  setupProxyForProtocol(ps, "http", 80);
  setupProxyForProtocol(ps, "https", 443);
  setupProxyForProtocol(ps, "ftp", 80);
  setupProxyForProtocol(ps, "ftps", 80);
  boolean socksAvailable = setupSocktProxy(ps);

  if (ps.size() == 0 && !socksAvailable) {
    return null;
  }

  return ps;
}
 
开发者ID:MarkusBernhardt,项目名称:proxy-vole,代码行数:25,代码来源:JavaProxySearchStrategy.java

示例14: setupProxyForProtocol

import java.net.ProxySelector; //导入依赖的package包/类
/*************************************************************************
 * Parse properties for the given protocol.
 * 
 * @param ps
 * @param protocol
 * @throws NumberFormatException
 ************************************************************************/

private void setupProxyForProtocol(ProtocolDispatchSelector ps, String protocol, int defaultPort) {
  String host = System.getProperty(protocol + ".proxyHost");
  if (host == null || host.trim().length() == 0) {
    return;
  }

  String port = System.getProperty(protocol + ".proxyPort", Integer.toString(defaultPort));
  String whiteList = System.getProperty(protocol + ".nonProxyHosts", "").replace('|', ',');

  if ("https".equalsIgnoreCase(protocol)) { // This is dirty but https has
                                            // no own property for it.
    whiteList = System.getProperty("http.nonProxyHosts", "").replace('|', ',');
  }

  Logger.log(getClass(), LogLevel.TRACE, protocol.toUpperCase() + " proxy {0}:{1} found using whitelist: {2}", host,
      port, whiteList);

  ProxySelector protocolSelector = new FixedProxySelector(host, Integer.parseInt(port));
  if (whiteList.trim().length() > 0) {
    protocolSelector = new ProxyBypassListSelector(whiteList, protocolSelector);
  }

  ps.setSelector(protocol, protocolSelector);
}
 
开发者ID:MarkusBernhardt,项目名称:proxy-vole,代码行数:33,代码来源:JavaProxySearchStrategy.java

示例15: getFirstProxy

import java.net.ProxySelector; //导入依赖的package包/类
static Proxy getFirstProxy(URL url) throws URISyntaxException {
	System.setProperty("java.net.useSystemProxies", "true");

	List<Proxy> proxylist = ProxySelector.getDefault().select(url.toURI());


	if (proxylist != null) {
		for (Proxy proxy: proxylist) {
			SocketAddress addr = proxy.address();

			if (addr != null) {
				return proxy;
			}
		}

	}
	return null;
}
 
开发者ID:MaxSmile,项目名称:EasyVPN-Free,代码行数:19,代码来源:ProxyDetection.java


注:本文中的java.net.ProxySelector类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。