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


Java ProxyAuthenticationStrategy类代码示例

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


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

示例1: get

import org.apache.http.impl.client.ProxyAuthenticationStrategy; //导入依赖的package包/类
@Override
public HttpClient get() {
  HttpClientBuilder builder =
      HttpClientBuilder.create()
          .setMaxConnPerRoute(maxConnectionPerRoute)
          .setMaxConnTotal(maxTotalConnection);

  if (proxy.getProxyUrl() != null) {
    URL url = proxy.getProxyUrl();
    builder.setProxy(new HttpHost(url.getHost(), url.getPort()));
    if (!Strings.isNullOrEmpty(proxy.getUsername())
        && !Strings.isNullOrEmpty(proxy.getPassword())) {
      UsernamePasswordCredentials creds =
          new UsernamePasswordCredentials(proxy.getUsername(), proxy.getPassword());
      CredentialsProvider credsProvider = new BasicCredentialsProvider();
      credsProvider.setCredentials(new AuthScope(url.getHost(), url.getPort()), creds);
      builder.setDefaultCredentialsProvider(credsProvider);
      builder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());
    }
  }

  return builder.build();
}
 
开发者ID:GerritCodeReview,项目名称:plugins_github,代码行数:24,代码来源:PooledHttpClientProvider.java

示例2: testFcmClientWithProxySettings

import org.apache.http.impl.client.ProxyAuthenticationStrategy; //导入依赖的package包/类
@Test
public void testFcmClientWithProxySettings() throws Exception {

    // Create Settings:
    IFcmClientSettings settings = new FakeFcmClientSettings();

    // Define the Credentials to be used:
    BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider();

    // Set the Credentials (any auth scope used):
    basicCredentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("your_username", "your_password"));

    // Create the Apache HttpClientBuilder:
    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create()
            // Set the Proxy Address:
            .setProxy(new HttpHost("your_hostname", 1234))
            // Set the Authentication Strategy:
            .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy())
            // Set the Credentials Provider we built above:
            .setDefaultCredentialsProvider(basicCredentialsProvider);

    // Create the DefaultHttpClient:
    DefaultHttpClient httpClient = new DefaultHttpClient(settings, httpClientBuilder);

    // Finally build the FcmClient:
    try(IFcmClient client = new FcmClient(settings, httpClient)) {
        // TODO Work with the Proxy ...
    }
}
 
开发者ID:bytefish,项目名称:FcmJava,代码行数:30,代码来源:HttpBuilderConfigurationTest.java

示例3: createHttpClient

import org.apache.http.impl.client.ProxyAuthenticationStrategy; //导入依赖的package包/类
public static void createHttpClient() {
    HttpClientBuilder clientBuilder = HttpClientBuilder.create();
    
    String ip = System.getProperty("com.thesimego.proxy.ip");
    String port = System.getProperty("com.thesimego.proxy.port");
    String login = System.getProperty("com.thesimego.proxy.login");
    String password = System.getProperty("com.thesimego.proxy.password");
    
    if(ip != null && port != null && !ip.trim().isEmpty() && !port.trim().isEmpty()) {
        
        if(login != null && password != null && !login.trim().isEmpty() && !password.trim().isEmpty()) {
            CredentialsProvider credsProvider = new BasicCredentialsProvider();
            credsProvider.setCredentials(
                    new AuthScope(ip, Integer.parseInt(port)),
                    new UsernamePasswordCredentials(login, password));
            clientBuilder.setDefaultCredentialsProvider(credsProvider);
        }
        
        clientBuilder.useSystemProperties();
        clientBuilder.setProxy(new HttpHost(ip, Integer.parseInt(port)));
        clientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());
    }
    
    httpClient = clientBuilder.build();

    BasicCookieStore cookieStore = new BasicCookieStore();
    httpContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
}
 
开发者ID:Simego,项目名称:ChatWA-Client,代码行数:29,代码来源:RequestClient.java

示例4: main

import org.apache.http.impl.client.ProxyAuthenticationStrategy; //导入依赖的package包/类
public static void main(String[] args) {
   /*
    * This is out ot date - Just keeping
    * it in case it's helpful...
    */
   final String authUser = "username"; 
   final String authPassword = "password"; 
   CredentialsProvider credsProvider = new BasicCredentialsProvider();
   credsProvider.setCredentials(new AuthScope("10.10.10.10", 8080),
         new UsernamePasswordCredentials(authUser, authPassword)); 

   HttpHost myProxy = new HttpHost("10.10.10.10", 8080);
   
   
   HttpClientBuilder clientBuilder = HttpClientBuilder.create(); 
   clientBuilder
      .setProxy(myProxy)
      .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy())
      .setDefaultCredentialsProvider(credsProvider) 
      .disableCookieManagement(); 
   CloseableHttpClient httpClient = clientBuilder.build();
   
   FhirContext ctx = new FhirContext(); 
   String serverBase = "http://spark.furore.com/fhir/"; 
   ctx.getRestfulClientFactory().setHttpClient(httpClient); 
   IGenericClient client = ctx.newRestfulGenericClient(serverBase); 

   IdDt id = new IdDt("Patient", "123"); 
   client.read(Patient.class, id); 
   
}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:32,代码来源:HttpProxy.java

示例5: getHttpClient

import org.apache.http.impl.client.ProxyAuthenticationStrategy; //导入依赖的package包/类
@Override
public synchronized HttpClient getHttpClient() {
	if (myHttpClient == null) {

		PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);

		//@formatter:off
		RequestConfig defaultRequestConfig = RequestConfig.custom()
			    .setSocketTimeout(mySocketTimeout)
			    .setConnectTimeout(myConnectTimeout)
			    .setConnectionRequestTimeout(myConnectionRequestTimeout)
			    .setStaleConnectionCheckEnabled(true)
			    .setProxy(myProxy)
			    .build();
		
		HttpClientBuilder builder = HttpClients.custom()
			.setConnectionManager(connectionManager)
			.setDefaultRequestConfig(defaultRequestConfig)
			.disableCookieManagement();
		
		if (myProxy != null && StringUtils.isNotBlank(myProxyUsername) && StringUtils.isNotBlank(myProxyPassword)) {
			CredentialsProvider credsProvider = new BasicCredentialsProvider();
			credsProvider.setCredentials(new AuthScope(myProxy.getHostName(), myProxy.getPort()), new UsernamePasswordCredentials(myProxyUsername, myProxyPassword));
			builder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());
			builder.setDefaultCredentialsProvider(credsProvider);
		}
		
		myHttpClient = builder.build();
		//@formatter:on

	}

	return myHttpClient;
}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:35,代码来源:RestfulClientFactory.java

示例6: getNativeHttpClient

import org.apache.http.impl.client.ProxyAuthenticationStrategy; //导入依赖的package包/类
public synchronized HttpClient getNativeHttpClient() {
	if (myHttpClient == null) {

		//FIXME potential resoource leak
		PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000,
				TimeUnit.MILLISECONDS);
		connectionManager.setMaxTotal(getPoolMaxTotal());
		connectionManager.setDefaultMaxPerRoute(getPoolMaxPerRoute());

		// @formatter:off
		//TODO: Use of a deprecated method should be resolved.
		RequestConfig defaultRequestConfig = RequestConfig.custom().setSocketTimeout(getSocketTimeout())
				.setConnectTimeout(getConnectTimeout()).setConnectionRequestTimeout(getConnectionRequestTimeout())
				.setStaleConnectionCheckEnabled(true).setProxy(myProxy).build();

		HttpClientBuilder builder = HttpClients.custom().setConnectionManager(connectionManager)
				.setDefaultRequestConfig(defaultRequestConfig).disableCookieManagement();

		if (myProxy != null && StringUtils.isNotBlank(getProxyUsername()) && StringUtils.isNotBlank(getProxyPassword())) {
			CredentialsProvider credsProvider = new BasicCredentialsProvider();
			credsProvider.setCredentials(new AuthScope(myProxy.getHostName(), myProxy.getPort()),
					new UsernamePasswordCredentials(getProxyUsername(), getProxyPassword()));
			builder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());
			builder.setDefaultCredentialsProvider(credsProvider);
		}

		myHttpClient = builder.build();
		// @formatter:on

	}

	return myHttpClient;
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:34,代码来源:ApacheRestfulClientFactory.java


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