本文整理汇总了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;
}
}
示例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));
}
示例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);
}
示例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);
}
示例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));
}
示例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;
}
示例8: restTemplate
import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory; //导入依赖的package包/类
@Bean
RestTemplate restTemplate() {
return new RestTemplate(new HttpComponentsAsyncClientHttpRequestFactory());
}
示例9: clientHttpRequestFactory
import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory; //导入依赖的package包/类
@Bean
public AsyncClientHttpRequestFactory clientHttpRequestFactory(CloseableHttpAsyncClient closeableHttpAsyncClient) {
return new HttpComponentsAsyncClientHttpRequestFactory(closeableHttpAsyncClient);
}
示例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));
}
示例11: asyncHttpRequestFactory
import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory; //导入依赖的package包/类
@Bean
public AsyncClientHttpRequestFactory asyncHttpRequestFactory() {
return new HttpComponentsAsyncClientHttpRequestFactory(asyncHttpClient());
}