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


Java CloseableHttpAsyncClient.start方法代码示例

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


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

示例1: createHttpAsyncClient

import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
private CloseableHttpAsyncClient createHttpAsyncClient(YunpianConf conf) throws IOReactorException {
    IOReactorConfig ioReactorConfig = IOReactorConfig.custom().setIoThreadCount(Runtime.getRuntime().availableProcessors())
            .setConnectTimeout(conf.getConfInt(YunpianConf.HTTP_CONN_TIMEOUT, "10000"))
            .setSoTimeout(conf.getConfInt(YunpianConf.HTTP_SO_TIMEOUT, "30000")).build();
    ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(ioReactorConfig);

    PoolingNHttpClientConnectionManager connManager = new PoolingNHttpClientConnectionManager(ioReactor);
    ConnectionConfig connectionConfig = ConnectionConfig.custom().setMalformedInputAction(CodingErrorAction.IGNORE)
            .setUnmappableInputAction(CodingErrorAction.IGNORE)
            .setCharset(Charset.forName(conf.getConf(YunpianConf.HTTP_CHARSET, YunpianConf.HTTP_CHARSET_DEFAULT))).build();
    connManager.setDefaultConnectionConfig(connectionConfig);
    connManager.setMaxTotal(conf.getConfInt(YunpianConf.HTTP_CONN_MAXTOTAL, "100"));
    connManager.setDefaultMaxPerRoute(conf.getConfInt(YunpianConf.HTTP_CONN_MAXPERROUTE, "10"));

    CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom().setConnectionManager(connManager).build();
    httpclient.start();
    return httpclient;
}
 
开发者ID:yunpian,项目名称:yunpian-java-sdk,代码行数:19,代码来源:YunpianClient.java

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

示例3: generateClient

import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
@Override
public CloseableHttpAsyncClient generateClient ()
{
   CredentialsProvider credsProvider = new BasicCredentialsProvider();
   credsProvider.setCredentials(new AuthScope (AuthScope.ANY),
           new UsernamePasswordCredentials(serviceUser, servicePass));
   RequestConfig rqconf = RequestConfig.custom()
         .setCookieSpec(CookieSpecs.DEFAULT)
         .setSocketTimeout(Timeouts.SOCKET_TIMEOUT)
         .setConnectTimeout(Timeouts.CONNECTION_TIMEOUT)
         .setConnectionRequestTimeout(Timeouts.CONNECTION_REQUEST_TIMEOUT)
         .build();
   CloseableHttpAsyncClient res = HttpAsyncClients.custom ()
         .setDefaultCredentialsProvider (credsProvider)
         .setDefaultRequestConfig(rqconf)
         .build ();
   res.start ();
   return res;
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:20,代码来源:ODataProductSynchronizer.java

示例4: generateClient

import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
@Override
public CloseableHttpAsyncClient generateClient ()
{
   CredentialsProvider credsProvider = new BasicCredentialsProvider();
   credsProvider.setCredentials(new AuthScope (AuthScope.ANY),
            new UsernamePasswordCredentials(username, password));
   RequestConfig rqconf = RequestConfig.custom()
         .setCookieSpec(CookieSpecs.DEFAULT)
         .setSocketTimeout(Timeouts.SOCKET_TIMEOUT)
         .setConnectTimeout(Timeouts.CONNECTION_TIMEOUT)
         .setConnectionRequestTimeout(Timeouts.CONNECTION_REQUEST_TIMEOUT)
         .build();
   CloseableHttpAsyncClient res = HttpAsyncClients.custom ()
         .setDefaultCredentialsProvider (credsProvider)
         .setDefaultRequestConfig(rqconf)
         .build ();
   res.start ();
   return res;
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:20,代码来源:ODataClient.java

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

示例8: createCloseableHttpAsyncClient

import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
private CloseableHttpAsyncClient createCloseableHttpAsyncClient() throws Exception {
        HttpAsyncClientBuilder builder = HttpAsyncClientBuilder.create();
        builder.useSystemProperties();
        builder.setSSLContext(SSLContext.getDefault());
        builder.setConnectionReuseStrategy(DefaultConnectionReuseStrategy.INSTANCE);
        builder.setMaxConnPerRoute(2);
        builder.setMaxConnTotal(2);
        builder.setDefaultRequestConfig(RequestConfig
            .custom()
            .setConnectionRequestTimeout(1000)
            .setConnectTimeout(2000)
            .setSocketTimeout(2000)
        .build()
        );
//        builder.setHttpProcessor()
        CloseableHttpAsyncClient hc = builder.build();
        hc.start();
        return hc;
    }
 
开发者ID:eeichinger,项目名称:jcurl,代码行数:20,代码来源:HCNIOEngine.java

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

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

示例11: begin

import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的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

示例12: initDashboard

import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; //导入方法依赖的package包/类
private DashboardSetupStatus initDashboard(final String hostAddress, final int port) {
  final String dashboardURL = String.format("http://%s:%d/", hostAddress, port);
  try {
    // Create a pool of http client connection, which allow up to Integer.MAX_VALUE connections.
    final PoolingNHttpClientConnectionManager connectionManager
        = new PoolingNHttpClientConnectionManager(new DefaultConnectingIOReactor());
    connectionManager.setMaxTotal(Integer.MAX_VALUE);
    final CloseableHttpAsyncClient reusableHttpClient =
        HttpAsyncClients.custom().setConnectionManager(connectionManager).build();
    reusableHttpClient.start();

    // run another thread to send metrics.
    runMetricsSenderThread();

    return DashboardSetupStatus.getSuccessful(dashboardURL, reusableHttpClient);
  } catch (IOReactorException e) {
    LOG.log(Level.WARNING, "Dashboard: Fail on initializing connection to the dashboard server.", e);
    return DashboardSetupStatus.getFailed();
  }
}
 
开发者ID:snuspl,项目名称:cruise,代码行数:21,代码来源:DashboardConnector.java

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

示例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();
        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

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


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