当前位置: 首页>>代码示例>>Java>>正文


Java CloseableHttpAsyncClient.execute方法代码示例

本文整理汇总了Java中org.apache.http.impl.nio.client.CloseableHttpAsyncClient.execute方法的典型用法代码示例。如果您正苦于以下问题:Java CloseableHttpAsyncClient.execute方法的具体用法?Java CloseableHttpAsyncClient.execute怎么用?Java CloseableHttpAsyncClient.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.impl.nio.client.CloseableHttpAsyncClient的用法示例。


在下文中一共展示了CloseableHttpAsyncClient.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: send

import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
public void send(List<Map<Object, Object>> events, AsyncSuccessCallback<ProducedEventsResult> onSuccess, AsyncFailCallback onFail, AsyncCancelledCallback onCancel) throws IOException, InterruptedException {
    CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
    httpClient.start();

    String url = String.format("%s/%s/bulk-produce", this.endpoint, this.topicId);
    System.out.println(url);
    HttpPost httpPost = new HttpPost(url);
    httpPost.addHeader("Authorization", this.writeApiKey);
    httpPost.addHeader("Content-type", this.format);

    String jsonString = MAPPER.writeValueAsString(events);
    HttpEntity entity = new ByteArrayEntity(jsonString.getBytes());
    httpPost.setEntity(entity);

    ResponseParser<ProducedEventsResult> parser = new BulkProduceEventsParser();
    AsyncCallback cb = new AsyncCallback(httpClient, parser, MAPPER, onSuccess, onFail, onCancel);
    httpClient.execute(httpPost, cb);
}
 
开发者ID:PyroclastIO,项目名称:pyroclast-java,代码行数:19,代码来源:PyroclastProducer.java

示例2: 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:yunpian,项目名称:yunpian-java-sdk,代码行数:17,代码来源:AsyncClientExecuteProxy.java

示例3: 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:yunpian,项目名称:yunpian-java-sdk,代码行数:19,代码来源:AsyncClientHttpExchangeStreaming.java

示例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("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:yunpian,项目名称:yunpian-java-sdk,代码行数:19,代码来源:AsyncClientAuthentication.java

示例5: 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:yunpian,项目名称:yunpian-java-sdk,代码行数:21,代码来源:AsyncClientProxyAuthentication.java

示例6: get

import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
public final static HttpResponse get(String url, List<NameValuePair> parameters) throws Throwable {
    CloseableHttpAsyncClient client = HttpAsyncClients.createDefault();

    StringBuffer sb = new StringBuffer("?");
    for (NameValuePair pair : parameters) {
        sb.append(pair.getName());
        sb.append("=");
        sb.append(URLEncoder.encode(pair.getValue(), "UTF-8"));
        sb.append("&");
    }

    client.start();
    final HttpGet httpGet = new HttpGet(url + sb.toString());
    httpGet.removeHeaders("X-FORWARDED-FOR");
    httpGet.setHeader("X-FORWARDED-FOR", Environment.LOCAL_IP_ADDR);

    logger.debug("-> GET " + (url + sb.toString()));

    Future<HttpResponse> future = client.execute(httpGet, null);
    HttpResponse resp = future.get();

    return resp;
}
 
开发者ID:Wangzr,项目名称:micro-service-framework,代码行数:24,代码来源:RestClient.java

示例7: post

import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
public final static HttpResponse post(String url, List<NameValuePair> parameters) throws Throwable {
    CloseableHttpAsyncClient client = HttpAsyncClients.createDefault();

    client.start();
    final HttpPost httpPost = new HttpPost(url);
    httpPost.removeHeaders("X-FORWARDED-FOR");
    httpPost.setHeader("X-FORWARDED-FOR", Environment.LOCAL_IP_ADDR);
    UrlEncodedFormEntity encodedFormEntity = new UrlEncodedFormEntity(parameters, "UTF-8");
    httpPost.setEntity(encodedFormEntity);

    logger.debug("-> POST " + url + " Parameters " + JsonUtil.toString(parameters));

    Future<HttpResponse> future = client.execute(httpPost, null);
    HttpResponse resp = future.get();

    return resp;
}
 
开发者ID:Wangzr,项目名称:micro-service-framework,代码行数:18,代码来源:RestClient.java

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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);
    }
}
 
开发者ID:glowroot,项目名称:glowroot,代码行数:17,代码来源:ApacheHttpAsyncClientPluginIT.java

示例13: 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;
        }
    };
}
 
开发者ID:debop,项目名称:debop4j,代码行数:27,代码来源:FutureWebCacheRepository.java

示例14: testHttpAsyncClient

import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
@Test
public void testHttpAsyncClient() throws InterruptedException, IOException {
    CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();

    final CountDownLatch latch1 = new CountDownLatch(1);
    final HttpGet request2 = new HttpGet("http://www.apache.org/");
    httpclient.execute(request2, new FutureCallback<HttpResponse>() {

        public void completed(final HttpResponse response2) {
            latch1.countDown();
            System.out.println(request2.getRequestLine() + "->" + response2.getStatusLine());
        }

        public void failed(final Exception ex) {
            latch1.countDown();
            System.out.println(request2.getRequestLine() + "->" + ex);
        }

        public void cancelled() {
            latch1.countDown();
            System.out.println(request2.getRequestLine() + " cancelled");
        }

    });

    latch1.await();
}
 
开发者ID:aliyun,项目名称:HiTSDB-Client,代码行数:28,代码来源:TestHttpAsyncClient.java

示例15: 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();
	}
}
 
开发者ID:yunpian,项目名称:yunpian-java-sdk,代码行数:34,代码来源:AsyncClientCustomContext.java


注:本文中的org.apache.http.impl.nio.client.CloseableHttpAsyncClient.execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。