Java 类org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory 实例源码

项目:jcurl    文件:HCNIOEngine.java   
@Override
public ResponseEntity<String> submit(JCurlRequestOptions requestOptions) throws Exception {
    ResponseEntity<String> stringResponseEntity = null;
    try (CloseableHttpAsyncClient hc = createCloseableHttpAsyncClient()) {
        for (int i = 0; i < requestOptions.getCount(); i++) {
            final HttpHeaders headers = new HttpHeaders();
            for (Map.Entry<String, String> e : requestOptions.getHeaderMap().entrySet()) {
                headers.put(e.getKey(), Collections.singletonList(e.getValue()));
            }

            final HttpEntity<Void> requestEntity = new HttpEntity<>(headers);

            AsyncRestTemplate template = new AsyncRestTemplate(new HttpComponentsAsyncClientHttpRequestFactory(hc));
            final ListenableFuture<ResponseEntity<String>> exchange = template.exchange(requestOptions.getUrl(), HttpMethod.GET, requestEntity, String.class);
            stringResponseEntity = exchange.get();
            System.out.println(stringResponseEntity.getBody());

        }
        return stringResponseEntity;
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:AbstractEmbeddedServletContainerFactoryTests.java   
@Test
public void restartWithKeepAlive() throws Exception {
    AbstractEmbeddedServletContainerFactory factory = getFactory();
    this.container = factory
            .getEmbeddedServletContainer(exampleServletRegistration());
    this.container.start();
    HttpComponentsAsyncClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsAsyncClientHttpRequestFactory();
    ListenableFuture<ClientHttpResponse> response1 = clientHttpRequestFactory
            .createAsyncRequest(new URI(getLocalUrl("/hello")), HttpMethod.GET)
            .executeAsync();
    assertThat(response1.get(10, TimeUnit.SECONDS).getRawStatusCode()).isEqualTo(200);

    this.container.stop();
    this.container = factory
            .getEmbeddedServletContainer(exampleServletRegistration());
    this.container.start();

    ListenableFuture<ClientHttpResponse> response2 = clientHttpRequestFactory
            .createAsyncRequest(new URI(getLocalUrl("/hello")), HttpMethod.GET)
            .executeAsync();
    assertThat(response2.get(10, TimeUnit.SECONDS).getRawStatusCode()).isEqualTo(200);
    clientHttpRequestFactory.destroy();
}
项目:spring-boot-concourse    文件:AbstractEmbeddedServletContainerFactoryTests.java   
@Test
public void restartWithKeepAlive() throws Exception {
    AbstractEmbeddedServletContainerFactory factory = getFactory();
    this.container = factory
            .getEmbeddedServletContainer(exampleServletRegistration());
    this.container.start();
    HttpComponentsAsyncClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsAsyncClientHttpRequestFactory();
    ListenableFuture<ClientHttpResponse> response1 = clientHttpRequestFactory
            .createAsyncRequest(new URI(getLocalUrl("/hello")), HttpMethod.GET)
            .executeAsync();
    assertThat(response1.get(10, TimeUnit.SECONDS).getRawStatusCode()).isEqualTo(200);

    this.container.stop();
    this.container = factory
            .getEmbeddedServletContainer(exampleServletRegistration());
    this.container.start();

    ListenableFuture<ClientHttpResponse> response2 = clientHttpRequestFactory
            .createAsyncRequest(new URI(getLocalUrl("/hello")), HttpMethod.GET)
            .executeAsync();
    assertThat(response2.get(10, TimeUnit.SECONDS).getRawStatusCode()).isEqualTo(200);
    clientHttpRequestFactory.destroy();
}
项目:contestparser    文件:AbstractEmbeddedServletContainerFactoryTests.java   
@Test
public void restartWithKeepAlive() throws Exception {
    AbstractEmbeddedServletContainerFactory factory = getFactory();
    this.container = factory
            .getEmbeddedServletContainer(exampleServletRegistration());
    this.container.start();
    HttpComponentsAsyncClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsAsyncClientHttpRequestFactory();
    ListenableFuture<ClientHttpResponse> response1 = clientHttpRequestFactory
            .createAsyncRequest(new URI(getLocalUrl("/hello")), HttpMethod.GET)
            .executeAsync();
    assertThat(response1.get(10, TimeUnit.SECONDS).getRawStatusCode(), equalTo(200));

    this.container.stop();
    this.container = factory
            .getEmbeddedServletContainer(exampleServletRegistration());
    this.container.start();

    ListenableFuture<ClientHttpResponse> response2 = clientHttpRequestFactory
            .createAsyncRequest(new URI(getLocalUrl("/hello")), HttpMethod.GET)
            .executeAsync();
    assertThat(response2.get(10, TimeUnit.SECONDS).getRawStatusCode(), equalTo(200));
}
项目:async-servlet-examples    文件:SleepServerApiClient.java   
public SleepServerApiClient() throws Exception {
    connectionManager = new PoolingNHttpClientConnectionManager(
            new DefaultConnectingIOReactor(IOReactorConfig.DEFAULT));
    connectionManager.setMaxTotal(20000);
    connectionManager.setDefaultMaxPerRoute(20000);

    RequestConfig config = RequestConfig.custom().setConnectTimeout(120000)
            .build();

    CloseableHttpAsyncClient httpClient = HttpAsyncClientBuilder.create()
            .setConnectionManager(connectionManager)
            .setDefaultRequestConfig(config).build();

    HttpComponentsAsyncClientHttpRequestFactory requestFactory = new HttpComponentsAsyncClientHttpRequestFactory(
            httpClient);
    client = new AsyncRestTemplate(requestFactory);
}
项目:bc-quick-start-guide    文件:ApiHttpClient.java   
public ApiHttpClient(final String channelAccessToken) {

        RequestConfig requestConfig = RequestConfig.custom()
                .setConnectionRequestTimeout(timeoutInMillis)
                .setConnectTimeout(timeoutInMillis)
                .build();

        CloseableHttpAsyncClient asyncClient = HttpAsyncClientBuilder.create()
                .setDefaultRequestConfig(requestConfig)
                .addInterceptorLast((HttpRequest httpRequest, HttpContext httpContext) -> {
                    httpRequest.addHeader("X-Line-ChannelToken", channelAccessToken);
                    httpRequest.addHeader("Content-Type", "application/json; charser=UTF-8");
                    httpRequest.removeHeaders("Accept");
                    httpRequest.addHeader("Accept", "application/json; charset=UTF-8");
                })
                .setMaxConnTotal(maxConnections)
                .setMaxConnPerRoute(maxConnections)
                .disableCookieManagement()
                .build();

        asyncRestTemplate = new AsyncRestTemplate(new HttpComponentsAsyncClientHttpRequestFactory(asyncClient));
        asyncRestTemplate.setErrorHandler(new ApiResponseErrorHandler());

        httpHeaders = new HttpHeaders();
        httpHeaders.set("X-Line-ChannelToken", channelAccessToken);
        httpHeaders.setContentType(new MediaType("application", "json", Charset.forName("UTF-8")));
        List<MediaType> list = new ArrayList<>();
        list.add(new MediaType("application", "json", Charset.forName("UTF-8")));
        httpHeaders.setAccept(list);

        objectMapper = new ObjectMapper();
        objectMapper.configure(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME, true);
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
        objectMapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()));
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    }
项目:micro-server    文件:SpringConfig.java   
@Bean
public NIORestClient restClient(){
    HttpComponentsAsyncClientHttpRequestFactory rest = new HttpComponentsAsyncClientHttpRequestFactory();
    rest.setConnectionRequestTimeout(connectionRequestTimeout);
    rest.setReadTimeout(readTimeout);
    rest.setConnectTimeout(connectTimeout);
    return new NIORestClient(new AsyncRestTemplate(rest));
}
项目:searchahouse.com    文件:RestTemplateConfiguration.java   
@Bean
public AsyncRestTemplate asyncRestTemplateSupportHal(MappingJackson2HttpMessageConverter jackson2ConverterSupportHal) throws Exception {
    // HttpComponentsAsyncClientHttpRequestFactory internally uses NIO
    AsyncRestTemplate asyncRestTemplate = new AsyncRestTemplate(new HttpComponentsAsyncClientHttpRequestFactory(asyncHttpClient()));
    asyncRestTemplate.setMessageConverters( Arrays.asList(jackson2ConverterSupportHal) );
    return asyncRestTemplate;
}
项目:alpha-vantage    文件:AppConfig.java   
@Bean
RestTemplate restTemplate() {
    return new RestTemplate(new HttpComponentsAsyncClientHttpRequestFactory());
}
项目:fiware-ngsi-api    文件:HttpConfiguration.java   
@Bean
public AsyncClientHttpRequestFactory clientHttpRequestFactory(CloseableHttpAsyncClient closeableHttpAsyncClient) {
    return new HttpComponentsAsyncClientHttpRequestFactory(closeableHttpAsyncClient);
}
项目:buildTube    文件:RestUtil.java   
private AsyncRestTemplate buildRestTemplateWithBasicAuth(String username, String password) {
  HttpAsyncClientBuilder clientBuilder = HttpAsyncClientBuilder.create();
  clientBuilder.setDefaultCredentialsProvider(buildBasicAuthProvider(username, password));
  CloseableHttpAsyncClient client = clientBuilder.build();
  return new AsyncRestTemplate(new HttpComponentsAsyncClientHttpRequestFactory(client));
}
项目:grassroot-platform    文件:GrassrootIntegrationConfig.java   
@Bean
public AsyncClientHttpRequestFactory asyncHttpRequestFactory() {
    return new HttpComponentsAsyncClientHttpRequestFactory(asyncHttpClient());
}