本文整理匯總了Java中org.apache.http.impl.conn.DefaultProxyRoutePlanner類的典型用法代碼示例。如果您正苦於以下問題:Java DefaultProxyRoutePlanner類的具體用法?Java DefaultProxyRoutePlanner怎麽用?Java DefaultProxyRoutePlanner使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DefaultProxyRoutePlanner類屬於org.apache.http.impl.conn包,在下文中一共展示了DefaultProxyRoutePlanner類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
}
示例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();
}
示例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();
}
示例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;
}
示例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;
}
示例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 ;
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}