1

i write a java program which used the apache httpclient, the program run well on my windows, however error occured on my linux sever. The following is the exception.

The key code is :

CloseableHttpClient httpclient = HttpClients.createDefault(); 

With error

 Exception in thread "main" org.apache.http.ssl.SSLInitializationException: TLS SSLContext not available
        at org.apache.http.ssl.SSLContexts.createDefault(SSLContexts.java:58)
        at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:966)
        at org.apache.http.impl.client.HttpClients.createDefault(HttpClients.java:58)
        at yan.javatips.closure.HttpTest2.main(HttpTest2.java:26)
        Caused by: java.security.NoSuchAlgorithmException: TLS SSLContext not available
        at sun.security.jca.GetInstance.getInstance(GetInstance.java:159)
        at javax.net.ssl.SSLContext.getInstance(SSLContext.java:156)
        at org.apache.http.ssl.SSLContexts.createDefault(SSLContexts.java:54)
        ... 3 more

jar file httpclient 4.5.2
jdk version 1.8.0_101

This problem annoyed me for quite a while....

I work in eclipse on my windows( which the program runs well ) to attach the httpcore src and find the error code

    public static SSLContext createDefault() throws SSLInitializationException {
    try {
        final SSLContext sslcontext = SSLContext.getInstance(SSLContextBuilder.TLS);
        sslcontext.init(null, null, null);
        return sslcontext;
    } catch (final NoSuchAlgorithmException ex) {
        throw new SSLInitializationException(ex.getMessage(), ex);
    } catch (final KeyManagementException ex) {
        throw new SSLInitializationException(ex.getMessage(), ex);
    }
}

so I think the SSLContext.getInstance run error on my remote linux server, but I don't know the reason. it's weird however ok on windows.

0 Answers0