本文整理汇总了Java中org.apache.http.HttpHost.create方法的典型用法代码示例。如果您正苦于以下问题:Java HttpHost.create方法的具体用法?Java HttpHost.create怎么用?Java HttpHost.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.HttpHost
的用法示例。
在下文中一共展示了HttpHost.create方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: httpContext
import org.apache.http.HttpHost; //导入方法依赖的package包/类
private HttpContext httpContext() {
BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider();
if (isNotBlank(this.username) && this.password != null) {
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(this.username, this.password);
HttpHost httpHost = HttpHost.create(this.rootConfluenceUrl);
AuthScope authScope = new AuthScope(httpHost);
basicCredentialsProvider.setCredentials(authScope, credentials);
BasicAuthCache basicAuthCache = new BasicAuthCache();
basicAuthCache.put(httpHost, new BasicScheme());
HttpClientContext httpClientContext = HttpClientContext.create();
httpClientContext.setCredentialsProvider(basicCredentialsProvider);
httpClientContext.setAuthCache(basicAuthCache);
return httpClientContext;
} else {
return null;
}
}
示例2: setCredentials
import org.apache.http.HttpHost; //导入方法依赖的package包/类
private void setCredentials() {
AuthState authState = httpClientContext.getTargetAuthState();
if (authState != null) {
CredentialsProvider credentialsProvider = httpClientContext.getCredentialsProvider();
AuthScope authScope = new AuthScope(HttpHost.create(getBaseUrl()));
org.apache.http.auth.Credentials credentials = credentialsProvider.getCredentials(authScope);
if (credentials != null) {
authState.update(new BasicScheme(), credentials);
authState.setState(AuthProtocolState.CHALLENGED);
}
}
}
示例3: EsRestClient
import org.apache.http.HttpHost; //导入方法依赖的package包/类
@Inject
public EsRestClient(JkesProperties jkesProperties) {
SniffOnFailureListener sniffOnFailureListener = new SniffOnFailureListener();
Header[] defaultHeaders = {new BasicHeader("Content-Type", "application/json")};
String[] urls = jkesProperties.getEsBootstrapServers().split("\\s*,");
HttpHost[] hosts = new HttpHost[urls.length];
for (int i = 0; i < urls.length; i++) {
hosts[i] = HttpHost.create(urls[i]);
}
RestClient restClient = RestClient.builder(hosts)
.setRequestConfigCallback(requestConfigBuilder -> {
return requestConfigBuilder.setConnectTimeout(5000) // default 1s
.setSocketTimeout(60000); // defaults to 30 seconds
}).setHttpClientConfigCallback(httpClientBuilder -> {
return httpClientBuilder.setDefaultIOReactorConfig(
IOReactorConfig.custom().setIoThreadCount(2).build()); // because only used for admin, so not necessary to hold many worker threads
})
.setMaxRetryTimeoutMillis(60000) // defaults to 30 seconds
.setDefaultHeaders(defaultHeaders)
.setFailureListener(sniffOnFailureListener)
.build();
Sniffer sniffer = Sniffer.builder(restClient).build();
sniffOnFailureListener.setSniffer(sniffer);
this.sniffer = sniffer;
this.restClient = restClient;
}
示例4: EsRestClient
import org.apache.http.HttpHost; //导入方法依赖的package包/类
@Autowired
public EsRestClient(JkesSearchProperties jkesProperties) {
SniffOnFailureListener sniffOnFailureListener = new SniffOnFailureListener();
Header[] defaultHeaders = {new BasicHeader("Content-Type", "application/json")};
String[] urls = jkesProperties.getEs().getServers().split("\\s*,");
HttpHost[] hosts = new HttpHost[urls.length];
for (int i = 0; i < urls.length; i++) {
hosts[i] = HttpHost.create(urls[i]);
}
RestClient restClient = RestClient.builder(hosts)
.setRequestConfigCallback(requestConfigBuilder -> {
return requestConfigBuilder.setConnectTimeout(5000) // default 1s
.setSocketTimeout(60000); // defaults to 30 seconds
}).setHttpClientConfigCallback(httpClientBuilder -> {
return httpClientBuilder.setDefaultIOReactorConfig(
IOReactorConfig.custom().setIoThreadCount(2).build()); // because only used for admin, so not necessary to hold many worker threads
})
.setMaxRetryTimeoutMillis(60000) // defaults to 30 seconds
.setDefaultHeaders(defaultHeaders)
.setFailureListener(sniffOnFailureListener)
.build();
Sniffer sniffer = Sniffer.builder(restClient).build();
sniffOnFailureListener.setSniffer(sniffer);
this.sniffer = sniffer;
this.restClient = restClient;
}