title: SSLContextImpl is not initialized
body: <p>Below are my configurations</p>
  
  <p>java version "1.8.0_101"
  Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
  Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)</p>
  
  <p>Using Apache httpclient v4.4 to call the Restful service, The service URL has a valid certificate (SHA2)</p>
  
  <p>Using apache httpclient we are calling the service. Below is the code</p>
  
  <pre><code>private static CloseableHttpClient appHttpClient() throws Exception {
      if (null != httpclient) {
          return httpclient;
      }
      final Registry&lt;ConnectionSocketFactory&gt; socketFactoryRegistry = RegistryBuilder
              .&lt;ConnectionSocketFactory&gt; create().register("http", PlainConnectionSocketFactory.INSTANCE)
              .register("https", new SSLConnectionSocketFactory(trustAllSSLContext())).build();
  
      final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
      cm.setMaxTotal(HTTP_MAX_CON);
      cm.setDefaultMaxPerRoute(HTTP_CON_ROUTE);
  
      final RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(HTTP_CON_TO)
              .setConnectionRequestTimeout(HTTP_REQ_CON_TO).setSocketTimeout(HTTP_SO_TO).build();
  
      // final SSLConnectionSocketFactory factory = new
      // SSLConnectionSocketFactory(getSSLContext());
  
      httpclient = HttpClients.custom().setConnectionManager(cm).setDefaultRequestConfig(requestConfig).build();
  
      return httpclient;
  }
  
  public static SSLContext trustAllSSLContext() throws Exception {
      if (sslContext != null) {
          return sslContext;
      }
      sslContext = SSLContext.getInstance("TLSv1.2");
      sslContext.init(null, null, null);
      System.out.println(
              "SSLContext :: Protocol :: " + sslContext.getProtocol() + " Provider :: " + sslContext.getProvider());
      return sslContext;
  }
  </code></pre>
  
  <p>The service call is failing intermittently, there is batch process which calls our services in a loop, say 30 calls to services so some of them are failing and some of them are successful, for failed calls we are getting below exception.</p>
  
  <pre><code>java.lang.IllegalStateException: SSLContextImpl is not initialized
     at sun.security.ssl.SSLContextImpl.engineGetSocketFactory(SSLContextImpl.java:181)
     at javax.net.ssl.SSLContext.getSocketFactory(SSLContext.java:294)
     at org.apache.http.conn.ssl.SSLConnectionSocketFactory.&lt;init&gt;(SSLConnectionSocketFactory.java:262)
     at org.apache.http.conn.ssl.SSLConnectionSocketFactory.&lt;init&gt;(SSLConnectionSocketFactory.java:205)
     at com.wdpr.payment.helper.HttpHelper.appHttpClient(HttpHelper.java:63)
     at com.wdpr.payment.helper.HttpHelper.makePostCall(HttpHelper.java:142)...
  </code></pre>
  
  <p>Any one has any idea why it is failing for this exception intermittently.</p>