本文整理汇总了Java中org.springframework.http.client.Netty4ClientHttpRequestFactory.setConnectTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java Netty4ClientHttpRequestFactory.setConnectTimeout方法的具体用法?Java Netty4ClientHttpRequestFactory.setConnectTimeout怎么用?Java Netty4ClientHttpRequestFactory.setConnectTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.http.client.Netty4ClientHttpRequestFactory
的用法示例。
在下文中一共展示了Netty4ClientHttpRequestFactory.setConnectTimeout方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: usingNetty
import org.springframework.http.client.Netty4ClientHttpRequestFactory; //导入方法依赖的package包/类
static ClientHttpRequestFactory usingNetty(ClientOptions options)
throws IOException, GeneralSecurityException {
SslContext sslContext = new JdkSslContext(SSLContext.getDefault(), true, ClientAuth.REQUIRE);
final Netty4ClientHttpRequestFactory requestFactory = new Netty4ClientHttpRequestFactory();
requestFactory.setSslContext(sslContext);
if (options.getConnectionTimeout() != null) {
requestFactory.setConnectTimeout(options.getConnectionTimeout());
}
if (options.getReadTimeout() != null) {
requestFactory.setReadTimeout(options.getReadTimeout());
}
return requestFactory;
}
示例2: submit
import org.springframework.http.client.Netty4ClientHttpRequestFactory; //导入方法依赖的package包/类
@Override
public ResponseEntity<String> submit(JCurlRequestOptions requestOptions) throws Exception {
int ioWorkerCount = Runtime.getRuntime().availableProcessors() * 2;
NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(ioWorkerCount);
try {
final Netty4ClientHttpRequestFactory netty4ClientHttpRequestFactory = new Netty4ClientHttpRequestFactory(eventLoopGroup);
netty4ClientHttpRequestFactory.setConnectTimeout(2000);
netty4ClientHttpRequestFactory.setReadTimeout(2000);
/*
SslContext sslContext = SslContextBuilder
.forClient()
.sslProvider(SslProvider.JDK)
.build()
;
*/
if (requestOptions.getUrl().toLowerCase().startsWith("https://")) {
SslContext sslContext = new DefaultClientSslContext();
netty4ClientHttpRequestFactory.setSslContext(sslContext);
}
netty4ClientHttpRequestFactory.afterPropertiesSet();
ResponseEntity<String> stringResponseEntity = null;
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(netty4ClientHttpRequestFactory);
final ListenableFuture<ResponseEntity<String>> exchange = template.exchange(requestOptions.getUrl(), HttpMethod.GET, requestEntity, String.class);
stringResponseEntity = exchange.get();
System.out.println(stringResponseEntity.getBody());
}
return stringResponseEntity;
} finally {
eventLoopGroup.shutdownGracefully(100, 500, TimeUnit.MILLISECONDS);
}
}
示例3: usingNetty
import org.springframework.http.client.Netty4ClientHttpRequestFactory; //导入方法依赖的package包/类
static ClientHttpRequestFactory usingNetty(ClientOptions options,
SslConfiguration sslConfiguration) throws GeneralSecurityException,
IOException {
final Netty4ClientHttpRequestFactory requestFactory = new Netty4ClientHttpRequestFactory();
if (hasSslConfiguration(sslConfiguration)) {
SslContextBuilder sslContextBuilder = SslContextBuilder //
.forClient();
if (sslConfiguration.getTrustStoreConfiguration().isPresent()) {
sslContextBuilder
.trustManager(createTrustManagerFactory(sslConfiguration
.getTrustStoreConfiguration()));
}
if (sslConfiguration.getKeyStoreConfiguration().isPresent()) {
sslContextBuilder.keyManager(createKeyManagerFactory(sslConfiguration
.getKeyStoreConfiguration()));
}
requestFactory.setSslContext(sslContextBuilder.sslProvider(
SslProvider.JDK).build());
}
requestFactory.setConnectTimeout(Math.toIntExact(options
.getConnectionTimeout().toMillis()));
requestFactory.setReadTimeout(Math.toIntExact(options.getReadTimeout()
.toMillis()));
return requestFactory;
}