[英]Spring Boot AsyncRestTemplate SSLSocketFactory
在WebSphere中部署Spring Boot應用程序。 由於SSL配置,我們需要顯式指定SSLSocketFactory以確保應用程序使用WebSphere證書而不是默認的Java密鑰/信任存儲。
通過RestTemplate這樣做很簡單:
protected RestTemplate getRestTemplate() {
SSLSocketFactory sslSocketFactory = new SSLSocketFactory(
(javax.net.ssl.SSLSocketFactory) javax.net.ssl.SSLSocketFactory.getDefault(),
SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER
);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme(HTTP_SCHEME, HTTP_PORT, PlainSocketFactory.getSocketFactory()));
registry.register(new Scheme(HTTPS_SCHEME, HTTPS_PORT, sslSocketFactory));
BasicClientConnectionManager connectionManager = new BasicClientConnectionManager(registry);
DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);
ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
return new RestTemplate(requestFactory);
}
但是使用AsyncRestTemplate,我無法找到如何設置SSLSocketFactory:
protected AsyncRestTemplate getAsyncRestTemplate() throws IOReactorException, NoSuchAlgorithmException {
SSLIOSessionStrategy strategy = new SSLIOSessionStrategy(
SSLContext.getDefault(),
SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER
);
Registry<SchemeIOSessionStrategy> registry = RegistryBuilder.<SchemeIOSessionStrategy>create()
.register(HTTP_SCHEME, NoopIOSessionStrategy.INSTANCE)
.register(HTTPS_SCHEME, strategy)
.build();
PoolingNHttpClientConnectionManager connManager = new PoolingNHttpClientConnectionManager(
new DefaultConnectingIOReactor(),
registry
);
CloseableHttpAsyncClient httpClient = HttpAsyncClientBuilder
.create()
.setConnectionManager(connManager)
.build();
AsyncClientHttpRequestFactory requestFactory = new HttpComponentsAsyncClientHttpRequestFactory(httpClient);
return new AsyncRestTemplate(requestFactory);
}
從本質上講,我需要打電話:
(javax.net.ssl.SSLSocketFactory) javax.net.ssl.SSLSocketFactory.getDefault()
這會觸發WebSphere覆蓋SSL連接處理。
對我所缺少的任何想法都非常感謝 - 謝謝。
你不能。 javax.net.SocketFactory
與基於NIO的i / o模型不兼容。 無法使用SSLContext
進行非阻塞SSL。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.