本文整理匯總了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;
}