Apache httpclient:get"收到致命警报:protocol_version"有时

时间:2016-02-24 20:15:32

标签: spring apache-httpclient-4.x tls1.2

我需要帮助!

我使用Java 8在Tomcat 8上运行CentOS 6上的应用程序。

我在Apache httpclient(版本4)中配置TLSv1.2如下:

HttpComponentsHttpInvokerRequestExecutor httpInvokerRequestExecutor = new HttpComponentsHttpInvokerRequestExecutor();

SSLContext sslcontext= SSLContexts.custom().loadTrustMaterial(null,
            new TrustSelfSignedStrategy()).build();

// Allow TLSv1.2 protocol, use NoopHostnameVerifier to trust self-singed cert
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext,
        new String[] { "TLSv1" , "TLSv1.1", "TLSv1.2"  }, null, new NoopHostnameVerifier());


CloseableHttpClient httpClient = HttpClients.custom().
            setSSLSocketFactory(sslsf).build();
httpInvokerRequestExecutor.setHttpClient(httpClient);

我使用上面的代码连接到可能配置了TLSv1或TLSv1.2的服务器。

不幸的是,当服务器配置了TLSv1.2时,我有时会遇到以下异常:Received fatal alert: protocol_version

它的工作时间但我希望它能够始终

有什么问题?

我错过了什么配置?

是负载问题吗?

我们在测试期间发现,在异常的情况下,客户端开始与TLSv1协商而不使用TLSv1.2。

我们的配置有什么问题?

Caused by: javax.net.ssl.SSLException: Received fatal alert: protocol_version
        at sun.security.ssl.Alerts.getSSLException(Alerts.java:208) ~[?:1.8.0_71]
        at sun.security.ssl.Alerts.getSSLException(Alerts.java:154) ~[?:1.8.0_71]
        at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2023) ~[?:1.8.0_71]
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1125) ~[?:1.8.0_71]
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375) ~[?:1.8.0_71]
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403) ~[?:1.8.0_71]
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387) ~[?:1.8.0_71]
        at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:394) ~[httpclient-4.4.1.jar:4.4.1]
        at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353) ~[httpclient-4.4.1.jar:4.4.1]
        at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134) ~[httpclient-4.4.1.jar:4.4.1]
        at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353) ~[httpclient-4.4.1.jar:4.4.1]
        at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380) ~[httpclient-4.4.1.jar:4.4.1]
        at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) ~[httpclient-4.4.1.jar:4.4.1]
        at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184) ~[httpclient-4.4.1.jar:4.4.1]
        at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88) ~[httpclient-4.4.1.jar:4.4.1]
        at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) ~[httpclient-4.4.1.jar:4.4.1]
        at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) ~[httpclient-4.4.1.jar:4.4.1]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) ~[httpclient-4.4.1.jar:4.4.1]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107) ~[httpclient-4.4.1.jar:4.4.1]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55) ~[httpclient-4.4.1.jar:4.4.1]
        at org.springframework.remoting.httpinvoker.HttpComponentsHttpInvokerRequestExecutor.executeHttpPost(HttpComponentsHttpInvokerRequestExecutor.java:312) ~[spring-web-4.1.9.RELEASE.jar:4.1.9.RELEASE]
        at org.springframework.remoting.httpinvoker.HttpComponentsHttpInvokerRequestExecutor.doExecuteRequest(HttpComponentsHttpInvokerRequestExecutor.java:230) ~[spring-web-4.1.9.RELEASE.jar:4.1.9.RELEASE]
        at org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor.executeRequest(AbstractHttpInvokerRequestExecutor.java:138) ~[spring-web-4.1.9.RELEASE.jar:4.1.9.RELEASE]
        at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.executeRequest(HttpInvokerClientInterceptor.java:194) ~[spring-web-4.1.9.RELEASE.jar:4.1.9.RELEASE]
        at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.executeRequest(HttpInvokerClientInterceptor.java:176) ~[spring-web-4.1.9.RELEASE.jar:4.1.9.RELEASE]
        at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.invoke(HttpInvokerClientInterceptor.java:144) ~[spring-web-4.1.9.RELEASE.jar:4.1.9.RELEASE]
        ... 27 more

0 个答案:

没有答案