本文整理汇总了Java中org.apache.http.impl.conn.DefaultProxyRoutePlanner类的典型用法代码示例。如果您正苦于以下问题:Java DefaultProxyRoutePlanner类的具体用法?Java DefaultProxyRoutePlanner怎么用?Java DefaultProxyRoutePlanner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultProxyRoutePlanner类属于org.apache.http.impl.conn包,在下文中一共展示了DefaultProxyRoutePlanner类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: customize
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; //导入依赖的package包/类
@Override
public void customize(RestTemplate restTemplate) {
HttpHost proxy = new HttpHost("proxy.example.com");
HttpClient httpClient = HttpClientBuilder.create()
.setRoutePlanner(new DefaultProxyRoutePlanner(proxy) {
@Override
public HttpHost determineProxy(HttpHost target,
HttpRequest request, HttpContext context)
throws HttpException {
if (target.getHostName().equals("192.168.0.5")) {
return null;
}
return super.determineProxy(target, request, context);
}
}).build();
restTemplate.setRequestFactory(
new HttpComponentsClientHttpRequestFactory(httpClient));
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:RestTemplateProxyCustomizationExample.java
示例2: initialize
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; //导入依赖的package包/类
public void initialize(){
requestConfig = RequestConfig.custom().setConnectTimeout(httpConnectTimeout).setSocketTimeout(httpReadTimeout).build();
if (StringUtils.isNotBlank(proxyScheme) && StringUtils.isNotBlank(proxyHost) && proxyPort != null) {
System.out.println("Initialising proxy settings");
HttpHost proxy = new HttpHost(proxyHost, proxyPort, proxyScheme);
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).setRoutePlanner(routePlanner).build();
} else {
httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();
}
String implementationVersion = this.getClass().getPackage().getImplementationVersion();
if (implementationVersion != null && implementationVersion.length() > 0){
clientVersion = implementationVersion;
}
customUserAgentHeaderValue = format("sentenial-java/%s", clientVersion);
}
开发者ID:sentenial,项目名称:nuapay-rest-client,代码行数:19,代码来源:HttpClientDefault.java
示例3: getHttpClient
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; //导入依赖的package包/类
/**
* Get a HTTP client. With proxy if a proxy is provided in the constructor.
* @return a HTTP client
*/
protected HttpClient getHttpClient(){
HttpClientBuilder builder = HttpClientBuilder.create();
if(proxyHost != null && proxyPort != 0) {
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
builder.setRoutePlanner(routePlanner);
}
RequestConfig.Builder config = RequestConfig.custom()
.setConnectTimeout(timeout)
.setConnectionRequestTimeout(timeout)
.setSocketTimeout(timeout);
builder.setDefaultRequestConfig(config.build());
return builder.build();
}
开发者ID:matomo-org,项目名称:piwik-java-tracker,代码行数:24,代码来源:PiwikTracker.java
示例4: QueryExecutor
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; //导入依赖的package包/类
private QueryExecutor(String userAgent, ObjectMapper mapper, HttpHost proxy)
{
checkNotNull(userAgent, "userAgent is null");
checkNotNull(mapper, "mapper is null");
this.userAgent = userAgent;
this.mapper = mapper;
HttpClientBuilder builder = HttpClients.custom();
HttpAsyncClientBuilder asyncBuilder = HttpAsyncClients.custom();
if (proxy != null) {
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
builder.setRoutePlanner(routePlanner);
asyncBuilder.setRoutePlanner(routePlanner);
}
this.httpClient = asyncBuilder.build();
this.httpClient.start();
}
开发者ID:prestodb,项目名称:presto-jdbc-java6,代码行数:21,代码来源:QueryExecutor.java
示例5: createClient
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; //导入依赖的package包/类
/**
* Creates asynchronous Apache HTTP client.
*
* @param settings
* settings to use to create client.
* @param conf
* configuration related to async connection.
* @return Instance of {@link CloseableHttpAsyncClient}.
*/
private CloseableHttpAsyncClient createClient(HttpSettings settings, ApacheHttpClientConfiguration conf) {
IOReactorConfig ioReactor = IOReactorConfig.custom().setIoThreadCount(conf.getMaxThreadCount()).build();
HttpAsyncClientBuilder httpClientBuilder = HttpAsyncClients.custom()
.useSystemProperties()
// allow POST redirects
.setRedirectStrategy(new LaxRedirectStrategy()).setMaxConnTotal(conf.getMaxTotalConnectionCount()).setMaxConnPerRoute(conf.getMaxRouteConnectionCount()).setDefaultIOReactorConfig(ioReactor)
.setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy()).setDefaultRequestConfig(createDefaultRequestConfig(settings));
if (settings.getProxyUrl() != null) {
DefaultProxyRoutePlanner routePlanner = createProxyRoutePlanner(settings, httpClientBuilder);
httpClientBuilder.setRoutePlanner(routePlanner);
}
CloseableHttpAsyncClient httpClient = httpClientBuilder.build();
httpClient.start();
return httpClient;
}
开发者ID:guardtime,项目名称:ksi-java-sdk,代码行数:25,代码来源:AbstractApacheHttpClient.java
示例6: generateHttpClientBuilder
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; //导入依赖的package包/类
/**
* Creates a HttpClientBuilder with the default settings of GERBIL.
*
* @return a HttpClientBuilder with the default settings of GERBIL.
*/
public HttpClientBuilder generateHttpClientBuilder() {
HttpClientBuilder builder = HttpClientBuilder.create();
builder.setUserAgent(userAgent);
String proxyHost = GerbilConfiguration.getInstance().getString(PROXY_HOST_KEY);
int proxyPort = GerbilConfiguration.getInstance().getInt(PROXY_PORT_KEY, DEFAULT_PROXY_PORT);
if (proxyHost != null) {
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
builder.setRoutePlanner(routePlanner);
}
return builder;
}
开发者ID:dice-group,项目名称:gerbil,代码行数:21,代码来源:HttpManagement.java
示例7: getHttpClient
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; //导入依赖的package包/类
public static CloseableHttpClient getHttpClient (HasProxySettings proxySetting) {
// http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d5e475
CloseableHttpClient httpclient = null ;
if (proxySetting != null && proxySetting.isActive()) {
logger.info("Set the http proxy (" + proxySetting.getHost() + ":" + proxySetting.getPort() + ")") ;
CredentialsProvider credsProvider = Preconditions.checkNotNull(proxySetting.getCredentialsProvider()) ;
HttpHost proxy = new HttpHost(proxySetting.getHost(), proxySetting.getPort());
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
httpclient = HttpClients.custom()
.setRoutePlanner(routePlanner).setDefaultCredentialsProvider(credsProvider)
.build();
} else {
httpclient = HttpClients.createDefault();
}
return httpclient ;
}
开发者ID:roikku,项目名称:drive-uploader,代码行数:18,代码来源:HttpClientUtils.java
示例8: configureProxy
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; //导入依赖的package包/类
protected void configureProxy(final HttpClientBuilder httpClientBuilder, final String proxy)
throws InitializationException {
final URL proxyUrl;
try {
proxyUrl = new URL(proxy);
} catch (final MalformedURLException e) {
throw new InitializationException("Invalid proxy url", e);
}
final String proxyHost = proxyUrl.getHost();
final int proxyPort = proxyUrl.getPort() != -1
? proxyUrl.getPort()
: proxyUrl.getDefaultPort();
LOG.info("Set proxy server to '{}:{}'", proxyHost, proxyPort);
httpClientBuilder.setRoutePlanner(new DefaultProxyRoutePlanner(new HttpHost(proxyHost, proxyPort)));
final String userInfo = proxyUrl.getUserInfo();
if (userInfo != null) {
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(proxyHost, proxyPort), buildCredentials(userInfo));
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
}
开发者ID:osiegmar,项目名称:japt-proxy,代码行数:26,代码来源:HttpClientConfigurer.java
示例9: afterPropertiesSet
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; //导入依赖的package包/类
/**
* プロパティの設定が終了したあとにHttpClientのインスタンスを生成し、プロキシの設定を行います。
* {@inheritDoc}
*/
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(proxyHost, "プロキシホスト(proxyHost)は必須です。");
Assert.notNull(proxyPort, "プロキシポート番号(proxyPort)は必須です。");
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(maxTotal);
connectionManager.setDefaultMaxPerRoute(defaultMaxPerRoute);
HttpClientBuilder builder = HttpClients.custom();
builder.setConnectionManager(connectionManager);
if (authentication) {
Assert.notNull(username, "ユーザ認証がtrueに設定された場合、ユーザ名(username)は必須です。");
Assert.notNull(password, "ユーザ認証がtrueに設定された場合、パスワード(password)は必須です。");
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(new HttpHost(proxyHost, Integer.parseInt(proxyPort)));
builder.setRoutePlanner(routePlanner);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(proxyHost, Integer.parseInt(proxyPort)), new UsernamePasswordCredentials(username, password));
builder.setDefaultCredentialsProvider(credsProvider);
}
builder.setDefaultRequestConfig(RequestConfig.custom().setSocketTimeout(readTimeout).build());
CloseableHttpClient client = builder.build();
setHttpClient(client);
}
开发者ID:ctc-g,项目名称:sinavi-jfw,代码行数:30,代码来源:ProxyClientHttpRequestFactory.java
示例10: createRestTemplate
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; //导入依赖的package包/类
private RestTemplate createRestTemplate() {
// jackson message converter
MappingJackson2HttpMessageConverter mappingJacksonHttpMessageConverter = new MappingJackson2HttpMessageConverter();
mappingJacksonHttpMessageConverter.setObjectMapper(objectMapper);
// create message converters list
List<HttpMessageConverter<?>> httpMessageConverters = new ArrayList<HttpMessageConverter<?>>();
httpMessageConverters.add(mappingJacksonHttpMessageConverter);
// create rest template
RestTemplate restTemplate = new RestTemplate();
restTemplate.setMessageConverters(httpMessageConverters);
// configure proxy
HttpHost httpHost = new HttpHost(System.getProperty("http.proxyHost"), Integer.parseInt(System.getProperty("http.proxyPort")), "http");
DefaultProxyRoutePlanner defaultProxyRoutePlanner = new DefaultProxyRoutePlanner(httpHost);
HttpClient httpClient = HttpClients.custom().setRoutePlanner(defaultProxyRoutePlanner).build();
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
return restTemplate;
}
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:22,代码来源:BookServiceSpringRestTemplateClient.java
示例11: createRequestFactory
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; //导入依赖的package包/类
public ClientHttpRequestFactory createRequestFactory(HttpProxyConfiguration httpProxyConfiguration, boolean
trustSelfSignedCerts) {
HttpClientBuilder httpClientBuilder = HttpClients.custom().useSystemProperties();
if (trustSelfSignedCerts) {
httpClientBuilder.setSslcontext(buildSslContext());
httpClientBuilder.setHostnameVerifier(BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
}
if (httpProxyConfiguration != null) {
HttpHost proxy = new HttpHost(httpProxyConfiguration.getProxyHost(), httpProxyConfiguration.getProxyPort());
httpClientBuilder.setProxy(proxy);
if (httpProxyConfiguration.isAuthRequired()) {
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(
new AuthScope(httpProxyConfiguration.getProxyHost(), httpProxyConfiguration.getProxyPort()),
new UsernamePasswordCredentials(httpProxyConfiguration.getUsername(), httpProxyConfiguration
.getPassword()));
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
HttpRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
httpClientBuilder.setRoutePlanner(routePlanner);
}
HttpClient httpClient = httpClientBuilder.build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
return requestFactory;
}
开发者ID:SAP,项目名称:cf-java-client-sap,代码行数:32,代码来源:RestUtil.java
示例12: setProxy
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; //导入依赖的package包/类
/**
* Adds proxy to the {@link HttpClient} created by this builder
*
* @param proxy A {@link Proxy} object to get the connection info from
* @return this object
*/
public SafechargeClientBuilder setProxy(Proxy proxy) {
if (proxy != null) {
HttpHost proxyHost = new HttpHost(proxy.getHost(), proxy.getPort(), proxy.getProtocol());
this.routePlanner = new DefaultProxyRoutePlanner(proxyHost);
}
return this;
}
开发者ID:SafeChargeInternational,项目名称:safecharge-java,代码行数:16,代码来源:SafechargeClientBuilder.java
示例13: getHttpClient
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; //导入依赖的package包/类
public CloseableHttpClient getHttpClient(HttpHost proxy) {
CloseableHttpClient client;
if (proxy == null) {
client = HttpClients.createDefault();
} else {
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
client = HttpClients.custom().setRoutePlanner(routePlanner).build();
}
return client;
}
开发者ID:JDanielT,项目名称:search-doc,代码行数:11,代码来源:ConsultaCpfService.java
示例14: build
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; //导入依赖的package包/类
@Override
public HttpClientBuilder build(final TranscriptListener listener, final LoginCallback prompt) {
final HttpClientBuilder builder = super.build(listener, prompt);
// Add filter to inject custom headers to authenticate with proxy
builder.setRequestExecutor(
new CustomHeaderHttpRequestExecutor(headers)
);
// Set proxy router planer
builder.setRoutePlanner(new DefaultProxyRoutePlanner(
new HttpHost(proxy.getHostname(), proxy.getPort(), proxy.getProtocol().getScheme().name()),
new DefaultSchemePortResolver()));
return builder;
}
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:14,代码来源:UDTProxyConfigurator.java
示例15: getHttpClient
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; //导入依赖的package包/类
private HttpClient getHttpClient() {
HttpClient client;
if (proxyHost != null)
{
client = HttpClientBuilder.create().setRoutePlanner(new DefaultProxyRoutePlanner(proxyHost)).build();
}
else
{
client = HttpClientBuilder.create().build();
}
return client;
}
开发者ID:riversun,项目名称:slacklet,代码行数:13,代码来源:SlackWebSocketSessionImpl.java
示例16: addProxy
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; //导入依赖的package包/类
private void addProxy(RESTPool pool, HttpClientBuilder builder) {
if (pool.getProxy() == null) return;
Proxy proxy = pool.getProxy();
if (proxy.getUsername() != null) {
CredentialsProvider provider = makeProxyCredentialsProvider(proxy);
builder.setDefaultCredentialsProvider(provider);
}
HttpHost proxyHost = new HttpHost(proxy.getHostname(), proxy.getPort());
builder.setRoutePlanner(new DefaultProxyRoutePlanner(proxyHost));
}
开发者ID:mercadolibre,项目名称:java-restclient,代码行数:14,代码来源:HTTPCBuilder.java
示例17: expectedSendGridBeanWithProxyCreated
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; //导入依赖的package包/类
@Test
public void expectedSendGridBeanWithProxyCreated() {
loadContext("spring.sendgrid.username:user", "spring.sendgrid.password:secret",
"spring.sendgrid.proxy.host:localhost",
"spring.sendgrid.proxy.port:5678");
SendGrid sendGrid = this.context.getBean(SendGrid.class);
assertThat(sendGrid).extracting("client").extracting("routePlanner")
.hasOnlyElementsOfType(DefaultProxyRoutePlanner.class);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:SendGridAutoConfigurationTests.java
示例18: HttpClientPojo
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; //导入依赖的package包/类
private HttpClientPojo(ProxyPojo proxyPojo) {
if (proxyPojo == null) {
this.proxy = null;
// logger.info("proxyPojo is null");
this.httpClient = HttpClients.custom().build();
} else {
this.proxyPojo = proxyPojo;
this.proxy = new HttpHost(proxyPojo.getIp(),proxyPojo.getPort());
if(proxyPojo.isAuthEnable()){
//需要验证的
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(proxyPojo.getIp(),
proxyPojo.getPort()), new UsernamePasswordCredentials(
proxyPojo.getUsername(), proxyPojo.getPassword()));
this.httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
}else{
//无需验证的
DefaultProxyRoutePlanner routePlanner= new DefaultProxyRoutePlanner(this.proxy);
this.httpClient = HttpClients.custom().setRoutePlanner(routePlanner).build();
}
RequestConfig.Builder config_builder = RequestConfig.custom();
config_builder.setProxy(proxy);
config_builder.setSocketTimeout(StaticValue.http_connection_timeout);
config_builder.setConnectTimeout(StaticValue.http_read_timeout);
this.requestConfig = config_builder.build();
}
}
开发者ID:cutoutsy,项目名称:miner,代码行数:28,代码来源:HttpClientPojoManager.java
示例19: TestProxyByBaidu
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; //导入依赖的package包/类
public static boolean TestProxyByBaidu(String proxyString){
String testString = "030173";
boolean reflag = true;
String ip = proxyString.split(":")[0];
int port = Integer.valueOf(proxyString.split(":")[1]);
try{
String url = "http://www.baidu.com/";
HttpClient httpClient = HttpClients.custom().build();
//211.144.72.154:8080
HttpHost proxy = new HttpHost(ip, port);
//无需验证的
DefaultProxyRoutePlanner routePlanner= new DefaultProxyRoutePlanner(proxy);
httpClient = HttpClients.custom().setRoutePlanner(routePlanner).build();
RequestConfig.Builder config_builder = RequestConfig.custom();
config_builder.setProxy(proxy);
config_builder.setSocketTimeout(StaticValue.http_connection_timeout);
config_builder.setConnectTimeout(StaticValue.http_read_timeout);
RequestConfig requestConfig = config_builder.build();
RequestBuilder rb = null;
rb = RequestBuilder.get().setUri(URI.create(url));
HttpUriRequest requestAll = null;
rb.setConfig(requestConfig);
requestAll = rb.build();
CloseableHttpResponse response = (CloseableHttpResponse)httpClient.execute(requestAll);
String re = Crawl4HttpClient.parserResponse_v2(response);
// System.out.println(Crawl4HttpClient.parserResponse_v2(response).substring(0,100));
if(!re.contains(testString)){
reflag = false;
System.out.println(re);
}
}catch (Exception ex){
ex.printStackTrace();
reflag = false;
}
return reflag;
}
开发者ID:cutoutsy,项目名称:miner,代码行数:41,代码来源:ProxyTest.java
示例20: getRoutePlanner
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; //导入依赖的package包/类
private HttpRoutePlanner getRoutePlanner() {
proxyHostname = Strings.nullToEmpty(proxyHostname);
if (proxyHostname.isEmpty()) {
proxyEnabled = false;
}
if (proxyEnabled) {
HttpHost proxy = new HttpHost(proxyHostname, proxyPort, proxyScheme);
HttpRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy) {
@Override
public HttpRoute determineRoute(
final HttpHost host,
final HttpRequest request,
final HttpContext context) throws HttpException {
String hostname = host.getHostName();
if (hostname.equals("127.0.0.1") || hostname.equalsIgnoreCase("localhost")) {
// Return direct route
return new HttpRoute(host);
}
return super.determineRoute(host, request, context);
}
};
return routePlanner;
}
return null;
}
开发者ID:HPInc,项目名称:printos-device-api-example-java,代码行数:28,代码来源:HttpClientFactoryBean.java
注:本文中的org.apache.http.impl.conn.DefaultProxyRoutePlanner类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论