本文整理汇总了Java中org.apache.http.nio.client.methods.HttpAsyncMethods类的典型用法代码示例。如果您正苦于以下问题:Java HttpAsyncMethods类的具体用法?Java HttpAsyncMethods怎么用?Java HttpAsyncMethods使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpAsyncMethods类属于org.apache.http.nio.client.methods包,在下文中一共展示了HttpAsyncMethods类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.http.nio.client.methods.HttpAsyncMethods; //导入依赖的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:yunpian,项目名称:yunpian-java-sdk,代码行数:19,代码来源:AsyncClientHttpExchangeStreaming.java
示例2: begin
import org.apache.http.nio.client.methods.HttpAsyncMethods; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void begin() throws InterruptedException {
CloseableHttpAsyncClient httpclient = httpAsyncClientBuilder.build();
httpclient.start();
new Thread(() -> {
while (true) {
try {
Url url = this.urlQueue.take();
httpclient.execute(HttpAsyncMethods.createGet(url.url), new MyResponseConsumer(url), new MyFutureCallback(url));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
}
开发者ID:luohaha,项目名称:jlitespider,代码行数:18,代码来源:AsyncNetwork.java
示例3: sendBatchActivities
import org.apache.http.nio.client.methods.HttpAsyncMethods; //导入依赖的package包/类
@Override
public void sendBatchActivities(List<Activity> activities) throws PXException, IOException {
HttpAsyncRequestProducer producer = null;
try {
String requestBody = JsonUtils.writer.writeValueAsString(activities);
logger.info("Sending Activity: {}", requestBody);
HttpPost post = new HttpPost(this.pxConfiguration.getServerURL() + Constants.API_ACTIVITIES);
post.setEntity(new StringEntity(requestBody, UTF_8));
post.setConfig(PXCommonUtils.getRequestConfig(pxConfiguration.getConnectionTimeout(),pxConfiguration.getApiTimeout()));
post.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
post.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + pxConfiguration.getAuthToken());
producer = HttpAsyncMethods.create(post);
asyncHttpClient.execute(producer, new BasicAsyncResponseConsumer(), new PxClientAsyncHandler());
} catch (Exception e) {
throw new PXException(e);
} finally {
if (producer != null) {
producer.close();
}
}
}
开发者ID:PerimeterX,项目名称:perimeterx-java-sdk,代码行数:22,代码来源:PXHttpClient.java
示例4: sendEnforcerTelemetry
import org.apache.http.nio.client.methods.HttpAsyncMethods; //导入依赖的package包/类
@Override
public void sendEnforcerTelemetry(EnforcerTelemetry enforcerTelemetry) throws PXException, IOException{
HttpAsyncRequestProducer producer = null;
try {
String requestBody = JsonUtils.writer.writeValueAsString(enforcerTelemetry);
logger.info("Sending enforcer telemetry: {}", requestBody);
HttpPost post = new HttpPost(this.pxConfiguration.getServerURL() + Constants.API_ENFORCER_TELEMETRY);
post.setEntity(new StringEntity(requestBody, UTF_8));
PXCommonUtils.getDefaultHeaders(pxConfiguration.getAuthToken());
post.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
post.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + pxConfiguration.getAuthToken());
post.setConfig(PXCommonUtils.getRequestConfig(pxConfiguration.getConnectionTimeout(),pxConfiguration.getApiTimeout()));
producer = HttpAsyncMethods.create(post);
asyncHttpClient.execute(producer, new BasicAsyncResponseConsumer(), new PxClientAsyncHandler());
} catch (Exception e) {
e.printStackTrace();
} finally {
if (producer != null) {
producer.close();
}
}
}
开发者ID:PerimeterX,项目名称:perimeterx-java-sdk,代码行数:23,代码来源:PXHttpClient.java
示例5: main
import org.apache.http.nio.client.methods.HttpAsyncMethods; //导入依赖的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
示例6: executeRequest
import org.apache.http.nio.client.methods.HttpAsyncMethods; //导入依赖的package包/类
private Future<Response> executeRequest(Request request, HttpRequestBase method, HttpContext context, HTTPCallback<HttpResponse> callback) {
if (request.isDownload()) {
HttpAsyncRequestProducer producer = HttpAsyncMethods.create(method);
HttpAsyncResponseConsumer<HttpResponse> consumer = new BasicAsyncResponseConsumer();
return executeRequest(producer, consumer, context, callback);
} else
return executeRequest(method, context, callback);
}
开发者ID:mercadolibre,项目名称:java-restclient,代码行数:9,代码来源:HTTPCAsyncClient.java
示例7: connectToClient
import org.apache.http.nio.client.methods.HttpAsyncMethods; //导入依赖的package包/类
/**
* Send HttpRequest to Client
* @param uri - FPC Client Uri
*/
public void connectToClient(String uri){
this.clientUri = uri;
try{
client.start();
HttpAsyncRequestProducer get = HttpAsyncMethods.createGet(this.clientUri);
client.execute(get, new MyResponseConsumer(this.clientUri), null);
} catch (Exception e) {
ErrorLog.logError(e.getStackTrace());
}
}
开发者ID:opendaylight,项目名称:fpc,代码行数:15,代码来源:EventClient.java
示例8: postJSON
import org.apache.http.nio.client.methods.HttpAsyncMethods; //导入依赖的package包/类
public static Func1<String, Observable<ObservableHttpResponse>> postJSON(final String baseURL, final CloseableHttpAsyncClient httpClient) {
final URI baseURI = URI.create(baseURL);
return new Func1<String, Observable<ObservableHttpResponse>>() {
@Override
public Observable<ObservableHttpResponse> call(String json) {
try {
return ObservableHttp.createRequest(HttpAsyncMethods.createPost(baseURI, json, ContentType.APPLICATION_JSON), httpClient).toObservable();
} catch (UnsupportedEncodingException e) {
throw Exceptions.propagate(e);
}
}
};
}
开发者ID:OpenNMS,项目名称:newts,代码行数:16,代码来源:ImportRunner.java
示例9: retryOperation
import org.apache.http.nio.client.methods.HttpAsyncMethods; //导入依赖的package包/类
/**
* Retries given HTTP request. Called internally only, from the HttpFuture
*
* @param httpUriRequest the HttpUriRequest to retry
* @param responseConsumer the response consumer
* @return the resulting Future<HttpResponse> instance
*/
Future<HttpResponse> retryOperation( HttpUriRequest httpUriRequest, HttpAsyncResponseConsumer<HttpResponse> responseConsumer ) {
return responseConsumer == null ? asyncClient.execute( httpUriRequest, null ) : asyncClient.execute( HttpAsyncMethods.create( httpUriRequest ), responseConsumer, null, null );
}
开发者ID:tenable,项目名称:Tenable.io-SDK-for-Java,代码行数:11,代码来源:AsyncHttpService.java
注:本文中的org.apache.http.nio.client.methods.HttpAsyncMethods类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论