我应该使用哪个ClientHttpRequestFactory在Spring 3.0.x中配置协议版本

时间:2019-04-16 06:31:52

标签: java spring ssl apache-commons-httpclient clienthttprequest

美好的一天,

我的Web应用程序在Spring 3.0.x版本中运行。

我需要打出restTemplate协议版本为TLSv1.2的电话,我从这篇帖子How to enforce TLS1.2 to Rest client using Rest Template找到了建议。这是我的一些代码:

SSLContext context = SSLContext.getInstance("TLSv1.2");
context.init(null, null, null);

org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient();

SSLSocketFactory ssf = new SSLSocketFactory(context);
HttpConnectionManager ccm = httpClient.getHttpConnectionManager();
SchemeRegistry sr = ( (ClientConnectionManager) ccm ).getSchemeRegistry();
sr.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
sr.register(new Scheme("https", 443, ssf));

Proxy proxy = new Proxy( Type.HTTP, new InetSocketAddress(
                    proxyServerIP, proxyServerPort ) );
httpClient.getParams( ).setParameter( ConnRoutePNames.DEFAULT_PROXY, proxy );
CommonsClientHttpRequestFactory c = new CommonsClientHttpRequestFactory(httpClient);
restTemplate = new RestTemplate( c );

我相信我使用的HttpClient很老了,org.apache.commons.httpclient.HttpClient。因为我发现CommonsClientHttpRequestFactory需要使用这个旧的HttpClient

而我为此java.lang.reflect.InvocationTargetException击中HttpClient

请告知我该使用哪个HttpClient和哪个ClientHttpRequestFactory

0 个答案:

没有答案