Example usage for org.springframework.http.client HttpComponentsAsyncClientHttpRequestFactory HttpComponentsAsyncClientHttpRequestFactory

List of usage examples for org.springframework.http.client HttpComponentsAsyncClientHttpRequestFactory HttpComponentsAsyncClientHttpRequestFactory

Introduction

In this page you can find the example usage for org.springframework.http.client HttpComponentsAsyncClientHttpRequestFactory HttpComponentsAsyncClientHttpRequestFactory.

Prototype

public HttpComponentsAsyncClientHttpRequestFactory(CloseableHttpAsyncClient asyncClient) 

Source Link

Document

Create a new instance of the HttpComponentsAsyncClientHttpRequestFactory with the given CloseableHttpAsyncClient instance and a default HttpClient .

Usage

From source file: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()));
            }/*from www  .  j  a v  a 2 s  .c  o m*/

            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;
    }
}

From source file:com.orange.ngsi.client.HttpConfiguration.java

@Bean
public AsyncClientHttpRequestFactory clientHttpRequestFactory(
        CloseableHttpAsyncClient closeableHttpAsyncClient) {
    return new HttpComponentsAsyncClientHttpRequestFactory(closeableHttpAsyncClient);
}

From source file:com.linecorp.platform.channel.sample.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();//from   ww w .  jav a2  s  .co m

    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);
}