HttpClientBuilder问题:无法初始化类sun.security.ssl.SSLContextImpl $ CustomizedTLSContext

时间:2019-06-10 17:48:24

标签: java ssl

在下面的Java代码中,我随机收到以下错误。

 final HttpClient client = HttpClientBuilder.create().build();
         final HttpGet request = new HttpGet(requestParameters);
         final HttpResponse response = client.execute(request);

错误:

java.lang.NoClassDefFoundError: Could not initialize class sun.security.ssl.SSLContextImpl$CustomizedTLSContext
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:291)
    at java.base/java.security.Provider$Service.getImplClass(Provider.java:1848)
    at java.base/java.security.Provider$Service.newInstance(Provider.java:1824)
    at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:236)
    at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:164)
    at java.base/javax.net.ssl.SSLContext.getInstance(SSLContext.java:168)
    at org.apache.http.ssl.SSLContexts.createDefault(SSLContexts.java:51)
    at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:977)

我无法重现该问题,因为它是随机的。这是否意味着ssl / tls握手失败?

实施重试政策是否可以帮助纠正此问题?

  public DefaultHttpRequestRetryHandler() {
        this(3, false);
    }

https://jar-download.com/artifacts/org.apache.httpcomponents/httpclient/4.5.2/source-code/org/apache/http/impl/client/DefaultHttpRequestRetryHandler.java

以下是我正在使用的Java库: enter image description here

更新:虽然我认为我可以通过从HttpClientBuilder转到java.net.HttpUrlConnection摆脱这个问题,但不幸的是,我遇到了同样的错误:

java.lang.NoClassDefFoundError: Could not initialize class sun.security.ssl.SSLContextImpl$DefaultSSLContext
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:291)
    at java.base/java.security.Provider$Service.getImplClass(Provider.java:1848)
    at java.base/java.security.Provider$Service.newInstance(Provider.java:1824)
    at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:236)
    at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:164)
    at java.base/javax.net.ssl.SSLContext.getInstance(SSLContext.java:168)
    at java.base/javax.net.ssl.SSLContext.getDefault(SSLContext.java:99)
    at java.base/javax.net.ssl.SSLSocketFactory.getDefault(SSLSocketFactory.java:123)
    at java.base/javax.net.ssl.HttpsURLConnection.getDefaultSSLSocketFactory(HttpsURLConnection.java:335)
    at java.base/javax.net.ssl.HttpsURLConnection.<init>(HttpsURLConnection.java:292)
    at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.<init>(HttpsURLConnectionImpl.java:95)
    at java.base/sun.net.www.protocol.https.Handler.openConnection(Handler.java:62)
    at java.base/sun.net.www.protocol.https.Handler.openConnection(Handler.java:57)
    at java.base/java.net.URL.openConnection(URL.java:1051)

1 个答案:

答案 0 :(得分:-1)

我的Java版本是1.8.0_171。通过升级到1.8.0_261,解决了相同的问题。