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


Java HttpComponentsAsyncClientHttpRequestFactory类代码示例

本文整理汇总了Java中org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory的典型用法代码示例。如果您正苦于以下问题:Java HttpComponentsAsyncClientHttpRequestFactory类的具体用法?Java HttpComponentsAsyncClientHttpRequestFactory怎么用?Java HttpComponentsAsyncClientHttpRequestFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: submit

import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory; //导入依赖的package包/类
@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;
    }
}
 
开发者ID:eeichinger,项目名称:jcurl,代码行数:22,代码来源:HCNIOEngine.java

示例2: restartWithKeepAlive

import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory; //导入依赖的package包/类
@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();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:24,代码来源:AbstractEmbeddedServletContainerFactoryTests.java

示例3: restartWithKeepAlive

import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory; //导入依赖的package包/类
@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));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:23,代码来源:AbstractEmbeddedServletContainerFactoryTests.java

示例4: SleepServerApiClient

import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory; //导入依赖的package包/类
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);
}
 
开发者ID:henriklundahl,项目名称:async-servlet-examples,代码行数:18,代码来源:SleepServerApiClient.java

示例5: ApiHttpClient

import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory; //导入依赖的package包/类
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);
    }
 
开发者ID:line,项目名称:bc-quick-start-guide,代码行数:38,代码来源:ApiHttpClient.java

示例6: restClient

import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory; //导入依赖的package包/类
@Bean
public NIORestClient restClient(){
	HttpComponentsAsyncClientHttpRequestFactory rest = new HttpComponentsAsyncClientHttpRequestFactory();
	rest.setConnectionRequestTimeout(connectionRequestTimeout);
	rest.setReadTimeout(readTimeout);
	rest.setConnectTimeout(connectTimeout);
	return new NIORestClient(new AsyncRestTemplate(rest));
}
 
开发者ID:aol,项目名称:micro-server,代码行数:9,代码来源:SpringConfig.java

示例7: asyncRestTemplateSupportHal

import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory; //导入依赖的package包/类
@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;
}
 
开发者ID:gustavoorsi,项目名称:searchahouse.com,代码行数:8,代码来源:RestTemplateConfiguration.java

示例8: restTemplate

import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory; //导入依赖的package包/类
@Bean
RestTemplate restTemplate() {
    return new RestTemplate(new HttpComponentsAsyncClientHttpRequestFactory());
}
 
开发者ID:cautiontowind,项目名称:alpha-vantage,代码行数:5,代码来源:AppConfig.java

示例9: clientHttpRequestFactory

import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory; //导入依赖的package包/类
@Bean
public AsyncClientHttpRequestFactory clientHttpRequestFactory(CloseableHttpAsyncClient closeableHttpAsyncClient) {
    return new HttpComponentsAsyncClientHttpRequestFactory(closeableHttpAsyncClient);
}
 
开发者ID:Orange-OpenSource,项目名称:fiware-ngsi-api,代码行数:5,代码来源:HttpConfiguration.java

示例10: buildRestTemplateWithBasicAuth

import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory; //导入依赖的package包/类
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));
}
 
开发者ID:STeveShary,项目名称:buildTube,代码行数:7,代码来源:RestUtil.java

示例11: asyncHttpRequestFactory

import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory; //导入依赖的package包/类
@Bean
public AsyncClientHttpRequestFactory asyncHttpRequestFactory() {
    return new HttpComponentsAsyncClientHttpRequestFactory(asyncHttpClient());
}
 
开发者ID:grassrootza,项目名称:grassroot-platform,代码行数:5,代码来源:GrassrootIntegrationConfig.java


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