本文整理汇总了Java中org.apache.http.impl.nio.client.CloseableHttpAsyncClient.close方法的典型用法代码示例。如果您正苦于以下问题:Java CloseableHttpAsyncClient.close方法的具体用法?Java CloseableHttpAsyncClient.close怎么用?Java CloseableHttpAsyncClient.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.impl.nio.client.CloseableHttpAsyncClient
的用法示例。
在下文中一共展示了CloseableHttpAsyncClient.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
try {
httpclient.start();
HttpHost proxy = new HttpHost("someproxy", 8080);
RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
HttpGet request = new HttpGet("https://issues.apache.org/");
request.setConfig(config);
Future<HttpResponse> future = httpclient.execute(request, null);
HttpResponse response = future.get();
System.out.println("Response: " + response.getStatusLine());
System.out.println("Shutting down");
} finally {
httpclient.close();
}
}
示例2: main
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
try {
httpclient.start();
Future<Boolean> future = httpclient.execute(HttpAsyncMethods.createGet("http://localhost:8080/"),
new MyResponseConsumer(), null);
Boolean result = future.get();
if (result != null && result.booleanValue()) {
System.out.println("Request successfully executed");
} else {
System.out.println("Request failed");
}
System.out.println("Shutting down");
} finally {
httpclient.close();
}
System.out.println("Done");
}
示例3: main
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope("localhost", 443),
new UsernamePasswordCredentials("username", "password"));
CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom().setDefaultCredentialsProvider(credsProvider)
.build();
try {
HttpGet httpget = new HttpGet("http://localhost/");
System.out.println("Executing request " + httpget.getRequestLine());
Future<HttpResponse> future = httpclient.execute(httpget, null);
HttpResponse response = future.get();
System.out.println("Response: " + response.getStatusLine());
System.out.println("Shutting down");
} finally {
httpclient.close();
}
}
示例4: main
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope("someproxy", 8080),
new UsernamePasswordCredentials("username", "password"));
CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom().setDefaultCredentialsProvider(credsProvider)
.build();
try {
httpclient.start();
HttpHost proxy = new HttpHost("someproxy", 8080);
RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
HttpGet httpget = new HttpGet("https://issues.apache.org/");
httpget.setConfig(config);
Future<HttpResponse> future = httpclient.execute(httpget, null);
HttpResponse response = future.get();
System.out.println("Response: " + response.getStatusLine());
System.out.println("Shutting down");
} finally {
httpclient.close();
}
}
示例5: main
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
public static void main(String[] args)throws Exception {
CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
try {
httpclient.start();
HttpHost proxy = new HttpHost("someproxy", 8080);
RequestConfig config = RequestConfig.custom()
.setProxy(proxy)
.build();
HttpGet request = new HttpGet("https://issues.apache.org/");
request.setConfig(config);
Future<HttpResponse> future = httpclient.execute(request, null);
HttpResponse response = future.get();
System.out.println("Response: " + response.getStatusLine());
System.out.println("Shutting down");
} finally {
httpclient.close();
}
}
开发者ID:AndroidStudioTranslate,项目名称:Android-Studio-Translate-Tool,代码行数:19,代码来源:AsyncClientExecuteProxy.java
示例6: main
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
try {
httpclient.start();
Future<Boolean> future = httpclient.execute(
HttpAsyncMethods.createGet("http://localhost:8080/"),
new MyResponseConsumer(), null);
Boolean result = future.get();
if (result != null && result.booleanValue()) {
System.out.println("Request successfully executed");
} else {
System.out.println("Request failed");
}
System.out.println("Shutting down");
} finally {
httpclient.close();
}
System.out.println("Done");
}
开发者ID:AndroidStudioTranslate,项目名称:Android-Studio-Translate-Tool,代码行数:20,代码来源:AsyncClientHttpExchangeStreaming.java
示例7: main
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope("localhost", 443),
new UsernamePasswordCredentials("username", "password"));
CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
.setDefaultCredentialsProvider(credsProvider)
.build();
try {
HttpGet httpget = new HttpGet("http://localhost/");
System.out.println("Executing request " + httpget.getRequestLine());
Future<HttpResponse> future = httpclient.execute(httpget, null);
HttpResponse response = future.get();
System.out.println("Response: " + response.getStatusLine());
System.out.println("Shutting down");
} finally {
httpclient.close();
}
}
开发者ID:AndroidStudioTranslate,项目名称:Android-Studio-Translate-Tool,代码行数:21,代码来源:AsyncClientAuthentication.java
示例8: main
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
public static void main(String[] args)throws Exception {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope("someproxy", 8080),
new UsernamePasswordCredentials("username", "password"));
CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
.setDefaultCredentialsProvider(credsProvider)
.build();
try {
httpclient.start();
HttpHost proxy = new HttpHost("someproxy", 8080);
RequestConfig config = RequestConfig.custom()
.setProxy(proxy)
.build();
HttpGet httpget = new HttpGet("https://issues.apache.org/");
httpget.setConfig(config);
Future<HttpResponse> future = httpclient.execute(httpget, null);
HttpResponse response = future.get();
System.out.println("Response: " + response.getStatusLine());
System.out.println("Shutting down");
} finally {
httpclient.close();
}
}
开发者ID:AndroidStudioTranslate,项目名称:Android-Studio-Translate-Tool,代码行数:25,代码来源:AsyncClientProxyAuthentication.java
示例9: transactionMarker
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
@Override
public void transactionMarker() throws Exception {
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
httpClient.start();
HttpHost httpHost = new HttpHost("localhost", getPort());
HttpGet httpGet = new HttpGet("/hello2");
SimpleFutureCallback callback = new SimpleFutureCallback();
Future<HttpResponse> future = httpClient.execute(httpHost, httpGet, callback);
callback.latch.await();
httpClient.close();
int responseStatusCode = future.get().getStatusLine().getStatusCode();
if (responseStatusCode != 200) {
throw new IllegalStateException(
"Unexpected response status code: " + responseStatusCode);
}
}
示例10: getCacheLoader
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
private static synchronized CacheLoader<String, String> getCacheLoader() {
return new CacheLoader<String, String>() {
@Override
public String load(String key) throws Exception {
log.trace("URI=[{}] 의 웹 컨텐츠를 비동기 방식으로 다운로드 받아 캐시합니다.", key);
String responseStr = "";
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault(); //new DefaultHttpAsyncClient();
try {
httpClient.start();
HttpGet request = new HttpGet(key);
Future<HttpResponse> future = httpClient.execute(request, null);
HttpResponse response = future.get();
responseStr = EntityUtils.toString(response.getEntity(), Charsets.UTF_8.toString());
if (log.isDebugEnabled())
log.debug("URI=[{}]로부터 웹 컨텐츠를 다운로드 받았습니다. responseStr=[{}]",
key, StringTool.ellipsisChar(responseStr, 80));
} finally {
httpClient.close();
}
return responseStr;
}
};
}
示例11: main
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
public final static void main(String[] args) throws Exception {
CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
try {
// Create a local instance of cookie store
CookieStore cookieStore = new BasicCookieStore();
// Create local HTTP context
HttpClientContext localContext = HttpClientContext.create();
// Bind custom cookie store to the local context
localContext.setCookieStore(cookieStore);
HttpGet httpget = new HttpGet("http://localhost/");
System.out.println("Executing request " + httpget.getRequestLine());
httpclient.start();
// Pass local context as a parameter
Future<HttpResponse> future = httpclient.execute(httpget, localContext, null);
// Please note that it may be unsafe to access HttpContext instance
// while the request is still being executed
HttpResponse response = future.get();
System.out.println("Response: " + response.getStatusLine());
List<Cookie> cookies = cookieStore.getCookies();
for (int i = 0; i < cookies.size(); i++) {
System.out.println("Local cookie: " + cookies.get(i));
}
System.out.println("Shutting down");
} finally {
httpclient.close();
}
}
示例12: main
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
try {
httpclient.start();
File upload = new File(args[0]);
File download = new File(args[1]);
ZeroCopyPost httpost = new ZeroCopyPost("http://localhost:8080/", upload, ContentType.create("text/plain"));
ZeroCopyConsumer<File> consumer = new ZeroCopyConsumer<File>(download) {
@Override
protected File process(final HttpResponse response, final File file, final ContentType contentType)
throws Exception {
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
throw new ClientProtocolException("Upload failed: " + response.getStatusLine());
}
return file;
}
};
Future<File> future = httpclient.execute(httpost, consumer, null);
File result = future.get();
System.out.println("Response file length: " + result.length());
System.out.println("Shutting down");
} finally {
httpclient.close();
}
System.out.println("Done");
}
示例13: main
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(3000).setConnectTimeout(3000).build();
CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom().setDefaultRequestConfig(requestConfig).build();
try {
httpclient.start();
final HttpGet[] requests = new HttpGet[] { new HttpGet("http://www.apache.org/"),
new HttpGet("https://www.verisign.com/"), new HttpGet("http://www.google.com/") };
final CountDownLatch latch = new CountDownLatch(requests.length);
for (final HttpGet request : requests) {
httpclient.execute(request, new FutureCallback<HttpResponse>() {
@Override
public void completed(final HttpResponse response) {
latch.countDown();
System.out.println(request.getRequestLine() + "->" + response.getStatusLine());
}
@Override
public void failed(final Exception ex) {
latch.countDown();
System.out.println(request.getRequestLine() + "->" + ex);
}
@Override
public void cancelled() {
latch.countDown();
System.out.println(request.getRequestLine() + " cancelled");
}
});
}
latch.await();
System.out.println("Shutting down");
} finally {
httpclient.close();
}
System.out.println("Done");
}
示例14: main
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
try {
httpclient.start();
HttpGet request = new HttpGet("http://www.apache.org/");
Future<HttpResponse> future = httpclient.execute(request, null);
HttpResponse response = future.get();
System.out.println("Response: " + response.getStatusLine());
System.out.println("Shutting down");
} finally {
httpclient.close();
}
System.out.println("Done");
}
示例15: main
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
public final static void main(String[] args) throws Exception {
// KeyStore trustStore =
// KeyStore.getInstance(KeyStore.getDefaultType());
// FileInputStream instream = new FileInputStream(new
// File("my.keystore"));
// try {
// trustStore.load(instream, "nopassword".toCharArray());
// } finally {
// instream.close();
// }
// // Trust own CA and all self-signed certs
// SSLContext sslcontext =
// SSLContexts.custom().loadTrustMaterial(trustStore, new
// TrustSelfSignedStrategy())
// .build();
SSLContext sslcontext = SSLContexts.createDefault();
// Allow TLSv1 protocol only
SSLIOSessionStrategy sslSessionStrategy = new SSLIOSessionStrategy(sslcontext, new String[] { "TLSv1" }, null,
SSLIOSessionStrategy.getDefaultHostnameVerifier());
CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom().setSSLStrategy(sslSessionStrategy).build();
try {
httpclient.start();
HttpGet request = new HttpGet("https://github.com/dzh");
Future<HttpResponse> future = httpclient.execute(request, null);
HttpResponse response = future.get();
System.out.println("Response: " + response.getStatusLine());
System.out.println("Shutting down");
} finally {
httpclient.close();
}
System.out.println("Done");
}