use of javax.cache.configuration.Factory in project ignite by apache.
the class JdbcThinSSLUtil method getSSLSocketFactory.
/**
* @param connProps Connection properties.
* @return SSL socket factory.
* @throws SQLException On error.
*/
private static SSLSocketFactory getSSLSocketFactory(ConnectionProperties connProps) throws SQLException {
String sslFactory = connProps.getSslFactory();
String cipherSuites = connProps.getSslCipherSuites();
String cliCertKeyStoreUrl = connProps.getSslClientCertificateKeyStoreUrl();
String cliCertKeyStorePwd = connProps.getSslClientCertificateKeyStorePassword();
String cliCertKeyStoreType = connProps.getSslClientCertificateKeyStoreType();
String trustCertKeyStoreUrl = connProps.getSslTrustCertificateKeyStoreUrl();
String trustCertKeyStorePwd = connProps.getSslTrustCertificateKeyStorePassword();
String trustCertKeyStoreType = connProps.getSslTrustCertificateKeyStoreType();
String sslProtocol = connProps.getSslProtocol();
String keyAlgorithm = connProps.getSslKeyAlgorithm();
if (!F.isEmpty(sslFactory)) {
try {
Class<Factory<SSLSocketFactory>> cls = (Class<Factory<SSLSocketFactory>>) JdbcThinSSLUtil.class.getClassLoader().loadClass(sslFactory);
Factory<SSLSocketFactory> f = cls.newInstance();
return f.create();
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
throw new SQLException("Could not fount SSL factory class: " + sslFactory, SqlStateCode.CLIENT_CONNECTION_FAILED, e);
}
}
if (cliCertKeyStoreUrl == null && cliCertKeyStorePwd == null && cliCertKeyStoreType == null && trustCertKeyStoreUrl == null && trustCertKeyStorePwd == null && trustCertKeyStoreType == null && sslProtocol == null && cipherSuites == null) {
try {
return SSLContext.getDefault().getSocketFactory();
} catch (NoSuchAlgorithmException e) {
throw new SQLException("Could not create default SSL context", SqlStateCode.CLIENT_CONNECTION_FAILED, e);
}
}
if (cliCertKeyStoreUrl == null)
cliCertKeyStoreUrl = System.getProperty("javax.net.ssl.keyStore");
if (cliCertKeyStorePwd == null)
cliCertKeyStorePwd = System.getProperty("javax.net.ssl.keyStorePassword");
if (cliCertKeyStoreType == null)
cliCertKeyStoreType = System.getProperty("javax.net.ssl.keyStoreType", DFLT_STORE_TYPE);
if (trustCertKeyStoreUrl == null)
trustCertKeyStoreUrl = System.getProperty("javax.net.ssl.trustStore");
if (trustCertKeyStorePwd == null)
trustCertKeyStorePwd = System.getProperty("javax.net.ssl.trustStorePassword");
if (trustCertKeyStoreType == null)
trustCertKeyStoreType = System.getProperty("javax.net.ssl.trustStoreType", DFLT_STORE_TYPE);
if (sslProtocol == null)
sslProtocol = DFLT_SSL_PROTOCOL;
if (keyAlgorithm == null)
keyAlgorithm = DFLT_KEY_ALGORITHM;
SslContextFactory f = new SslContextFactory();
f.setProtocol(sslProtocol);
f.setKeyAlgorithm(keyAlgorithm);
f.setKeyStoreFilePath(cliCertKeyStoreUrl);
f.setKeyStoreType(cliCertKeyStoreType);
f.setKeyStorePassword((cliCertKeyStorePwd == null) ? EMPTY_CHARS : cliCertKeyStorePwd.toCharArray());
if (connProps.isSslTrustAll())
f.setTrustManagers(TRUST_ALL_MANAGER);
else {
f.setTrustStoreFilePath(trustCertKeyStoreUrl);
f.setTrustStoreType(trustCertKeyStoreType);
f.setTrustStorePassword((trustCertKeyStorePwd == null) ? EMPTY_CHARS : trustCertKeyStorePwd.toCharArray());
}
if (!F.isEmpty(cipherSuites))
f.setCipherSuites(cipherSuites.split(","));
try {
final SSLContext sslContext = f.create();
return sslContext.getSocketFactory();
} catch (IgniteException e) {
final Throwable cause = e.getCause();
// Unwrap.
if (cause instanceof SSLException)
throw new SQLException(cause.getMessage(), SqlStateCode.CLIENT_CONNECTION_FAILED, e);
else
throw new SQLException("Unknown error.", SqlStateCode.CLIENT_CONNECTION_FAILED, e);
}
}
use of javax.cache.configuration.Factory in project ignite by apache.
the class ConfigVariations method nearCacheConfigurationFactory.
/**
* @return Custom near cache config.
*/
private static Factory nearCacheConfigurationFactory() {
return new Factory() {
@Override
public Object create() {
NearCacheConfiguration cfg = new NearCacheConfiguration<>();
cfg.setNearEvictionPolicy(new FifoEvictionPolicy());
return cfg;
}
};
}
use of javax.cache.configuration.Factory in project ignite by apache.
the class GridP2PContinuousDeploymentClientDisconnectTest method testContinuousQueryRemoteTransformer.
/**
* Test starts 1 server node and 1 client node. Class-loading request for the {@link #P2P_TEST_OBJ_RSRC_NAME}
* resource blocks on the client node. The client node tries to deploy CQ with remote transformer for
* the cache {@link #DEFAULT_CACHE_NAME}.
* Expected that exception with 'Failed to unmarshal deployable object.' error message will be thrown and
* the server node wouldn't be failed.
*
* @throws Exception If failed.
*/
@Test
public void testContinuousQueryRemoteTransformer() throws Exception {
Class<Factory<IgniteClosure<CacheEntryEvent<? extends Integer, ? extends Integer>, String>>> rmtTransformerFactoryCls = (Class<Factory<IgniteClosure<CacheEntryEvent<? extends Integer, ? extends Integer>, String>>>) getExternalClassLoader().loadClass(REMOTE_TRANSFORMER_FACTORY_CLS_NAME);
ContinuousQueryWithTransformer<Integer, Integer, String> qry = new ContinuousQueryWithTransformer<Integer, Integer, String>().setLocalListener(evts -> {
// No-op.
}).setRemoteTransformerFactory(rmtTransformerFactoryCls.newInstance());
LogListener lsnr = LogListener.matches("Failed to initialize a continuous query.").build();
testLog.registerListener(lsnr);
IgniteCache<Integer, Integer> cache = grid(1).cache(DEFAULT_CACHE_NAME);
cache.query(qry);
assertTrue(lsnr.check());
// Check that the failure handler was not called.
assertFalse(failure.get());
}
use of javax.cache.configuration.Factory in project ignite by apache.
the class GridP2PContinuousDeploymentClientDisconnectTest method testContinuousQueryRemoteFilterFactory.
/**
* Test starts 1 server node and 1 client node. Class-loading request for the {@link #P2P_TEST_OBJ_RSRC_NAME}
* resource blocks on the client node. The client node tries to deploy CQ with remote filter factory for
* the cache {@link #DEFAULT_CACHE_NAME}.
* Expected that exception with 'Failed to initialize a continuous query.' error message will be thrown and
* the server node wouldn't be failed.
*
* @throws Exception If failed.
*/
@Test
public void testContinuousQueryRemoteFilterFactory() throws Exception {
final Class<Factory<? extends CacheEntryEventFilter<Integer, Integer>>> rmtFilterFactoryCls = (Class<Factory<? extends CacheEntryEventFilter<Integer, Integer>>>) getExternalClassLoader().loadClass(REMOTE_FILTER_FACTORY_CLS_NAME);
AbstractContinuousQuery<Integer, Integer> qry = new ContinuousQuery<Integer, Integer>().setLocalListener(evts -> {
// No-op.
}).setRemoteFilterFactory(rmtFilterFactoryCls.newInstance());
IgniteEx client = grid(1);
LogListener lsnr = LogListener.matches("Failed to initialize a continuous query.").build();
testLog.registerListener(lsnr);
IgniteCache<Integer, Integer> cache = client.cache(DEFAULT_CACHE_NAME);
cache.query(qry);
assertTrue(lsnr.check());
// Check that the failure handler was not called.
assertFalse(failure.get());
}
use of javax.cache.configuration.Factory in project ignite by apache.
the class CacheHibernateStoreSessionListenerSelfTest method sessionListenerFactory.
/**
* {@inheritDoc}
*/
@Override
protected Factory<CacheStoreSessionListener> sessionListenerFactory() {
return new Factory<CacheStoreSessionListener>() {
@Override
public CacheStoreSessionListener create() {
CacheHibernateStoreSessionListener lsnr = new CacheHibernateStoreSessionListener();
SessionFactory sesFactory = new Configuration().setProperty("hibernate.connection.url", URL).addAnnotatedClass(Table1.class).addAnnotatedClass(Table2.class).buildSessionFactory();
lsnr.setSessionFactory(sesFactory);
return lsnr;
}
};
}
Aggregations