@Test public void shouldUseCachedSslContextForTheSameConfiguration() throws Exception { SSLConfig sslConfig1 = new SSLConfig(); sslConfig1.setKeyStoreName("keystore"); sslConfig1.setKeyStorePassword("password".toCharArray()); sslConfig1.setKeyStoreType("JKS"); sslConfig1.setKeyManagerFactoryAlgorithm("SunX509"); SSLContext sslContext1 = SSLContextFactory.getInstance(sslConfig1); SSLConfig sslConfig2 = new SSLConfig(); sslConfig2.setKeyStoreName("keystore"); sslConfig2.setKeyStorePassword("password".toCharArray()); sslConfig2.setKeyStoreType("JKS"); sslConfig2.setKeyManagerFactoryAlgorithm("SunX509"); SSLContext sslContext2 = SSLContextFactory.getInstance(sslConfig2); assertSame(sslContext1, sslContext2); }
public static SSLContext getInstance(SSLConfig sslConfig) throws GeneralSecurityException { synchronized (contextCache) { SSLContext context = contextCache.get(sslConfig); if (context == null) { try { context = createSSLContext(sslConfig); contextCache.put(sslConfig, context); } catch (Exception ioe) { throw new GeneralSecurityException("Can't create SSLContext", ioe); } } return context; } }
SSLContextFactory { public static SSLContext getInstance(SSLConfig sslConfig) throws GeneralSecurityException { synchronized (contextCache) { SSLContext context = contextCache.get(sslConfig); if (context == null) { try { context = createSSLContext(sslConfig); contextCache.put(sslConfig, context); } catch (Exception ioe) { throw new GeneralSecurityException("Can't create SSLContext", ioe); } } return context; } } }
SSLContextFactory { public static SSLContext getInstance(SSLConfig sslConfig) throws GeneralSecurityException { synchronized (contextCache) { SSLContext context = contextCache.get(sslConfig); if (context == null) { try { context = createSSLContext(sslConfig); contextCache.put(sslConfig, context); } catch (Exception ioe) { throw new GeneralSecurityException("Can't create SSLContext", ioe); } } return context; } }  }
SSLContextFactory { public static SSLContext getInstance(SSLConfig sslConfig) throws GeneralSecurityException { synchronized (contextCache) { SSLContext context = contextCache.get(sslConfig); if (context == null) { try { context = createSSLContext(sslConfig); contextCache.put(sslConfig, context); } catch (Exception ioe) { throw new GeneralSecurityException("Can't create SSLContext", ioe); } } return context; } }  static SSLContext getInstance(SSLConfig sslConfig); }
SSLContextFactory { public static SSLContext getInstance(SSLConfig sslConfig) throws GeneralSecurityException { synchronized (contextCache) { SSLContext context = contextCache.get(sslConfig); if (context == null) { try { context = createSSLContext(sslConfig); contextCache.put(sslConfig, context); } catch (Exception ioe) { throw new GeneralSecurityException("Can't create SSLContext", ioe); } } return context; } }  static SSLContext getInstance(SSLConfig sslConfig);  }