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


Java Netty4ClientHttpRequestFactory.setConnectTimeout方法代码示例

本文整理汇总了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;
}
 
开发者ID:spring-projects,项目名称:spring-credhub,代码行数:18,代码来源:ClientHttpRequestFactoryFactory.java

示例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);
        }
    }
 
开发者ID:eeichinger,项目名称:jcurl,代码行数:42,代码来源:NNIOEngine.java

示例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;
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:34,代码来源:ClientHttpRequestFactoryFactory.java


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