use of org.springframework.cloud.service.ServiceConnectorCreationException in project spring-cloud-connectors by spring-cloud.
the class MongoDbFactoryCreator method create.
@Override
public MongoDbFactory create(MongoServiceInfo serviceInfo, ServiceConnectorConfig config) {
try {
MongoClientOptions.Builder mongoOptionsToUse = getMongoOptions((MongoDbFactoryConfig) config);
SimpleMongoDbFactory mongoDbFactory = createMongoDbFactory(serviceInfo, mongoOptionsToUse);
return configure(mongoDbFactory, (MongoDbFactoryConfig) config);
} catch (UnknownHostException e) {
throw new ServiceConnectorCreationException(e);
} catch (MongoException e) {
throw new ServiceConnectorCreationException(e);
}
}
use of org.springframework.cloud.service.ServiceConnectorCreationException in project spring-cloud-connectors by spring-cloud.
the class DataSourceCreator method create.
@Override
public DataSource create(SI serviceInfo, ServiceConnectorConfig serviceConnectorConfig) {
try {
DataSource ds = createPooledDataSource(serviceInfo, serviceConnectorConfig);
if (ds != null) {
return ds;
}
// Only for testing outside Tomcat/CloudFoundry
logger.warning("No connection pooling DataSource implementation found on the classpath - no pooling is in effect.");
return new UrlDecodingDataSource(serviceInfo.getJdbcUrl());
} catch (Exception e) {
throw new ServiceConnectorCreationException("Failed to created cloud datasource for " + serviceInfo.getId() + " service", e);
}
}
use of org.springframework.cloud.service.ServiceConnectorCreationException in project spring-cloud-connectors by spring-cloud.
the class RedisConnectionFactoryCreator method create.
@Override
public RedisConnectionFactory create(RedisServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) {
RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
configuration.setHostName(serviceInfo.getHost());
configuration.setPort(serviceInfo.getPort());
configuration.setPassword(RedisPassword.of(serviceInfo.getPassword()));
if (hasClass(JEDIS_CLASS_NAME)) {
JedisClientConfigurationBuilder builder = JedisClientConfiguration.builder();
RedisJedisClientConfigurer clientConfigurer = new RedisJedisClientConfigurer();
if (serviceConnectorConfig instanceof RedisConnectionFactoryConfig) {
clientConfigurer.configure(builder, (RedisConnectionFactoryConfig) serviceConnectorConfig);
} else {
clientConfigurer.configure(builder, (PooledServiceConnectorConfig) serviceConnectorConfig);
}
if (connectionIsSecure(serviceInfo)) {
builder.useSsl();
}
JedisConnectionFactory connectionFactory = new JedisConnectionFactory(configuration, builder.build());
connectionFactory.afterPropertiesSet();
return connectionFactory;
} else if (hasClass(LETTUCE_CLASS_NAME)) {
LettuceClientConfigurationBuilder builder;
if (serviceConnectorConfig != null && ((PooledServiceConnectorConfig) serviceConnectorConfig).getPoolConfig() != null) {
if (!hasClass(APACHE_COMMONS_POOL_CLASS_NAME)) {
throw new ServiceConnectorCreationException(String.format("Failed to create cloud Redis " + "connection factory for %s service. Apache Commons Pool must be available on " + "the classpath if pooling parameters are provided.", serviceInfo.getId()));
}
builder = LettucePoolingClientConfiguration.builder();
} else {
builder = LettuceClientConfiguration.builder();
}
if (connectionIsSecure(serviceInfo)) {
builder.useSsl();
}
RedisLettuceClientConfigurer clientConfigurer = new RedisLettuceClientConfigurer();
if (serviceConnectorConfig instanceof RedisConnectionFactoryConfig) {
clientConfigurer.configure(builder, (RedisConnectionFactoryConfig) serviceConnectorConfig);
} else {
clientConfigurer.configure(builder, (PooledServiceConnectorConfig) serviceConnectorConfig);
}
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(configuration, builder.build());
connectionFactory.afterPropertiesSet();
return connectionFactory;
} else {
throw new ServiceConnectorCreationException(String.format("Failed to create cloud Redis " + "connection factory for %s service. No client implementation classes " + " of Jedis or Lettuce clients implementation (%s, %s) not found", serviceInfo.getId(), JEDIS_CLASS_NAME, LETTUCE_CLASS_NAME));
}
}
use of org.springframework.cloud.service.ServiceConnectorCreationException in project spring-cloud-connectors by spring-cloud.
the class SpringData1RedisConnectionFactoryCreator method create.
@Override
public RedisConnectionFactory create(RedisServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) {
if (hasClass(JEDIS_CLASS_NAME)) {
SpringData1RedisConnectionFactoryConfigurer configurer = new SpringData1RedisConnectionFactoryConfigurer();
JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
connectionFactory.setHostName(serviceInfo.getHost());
connectionFactory.setPort(serviceInfo.getPort());
connectionFactory.setPassword(serviceInfo.getPassword());
if (serviceConnectorConfig instanceof RedisConnectionFactoryConfig) {
configurer.configure(connectionFactory, (RedisConnectionFactoryConfig) serviceConnectorConfig);
} else {
configurer.configure(connectionFactory, (PooledServiceConnectorConfig) serviceConnectorConfig);
}
connectionFactory.afterPropertiesSet();
return connectionFactory;
} else if (hasClass(LETTUCE_CLASS_NAME)) {
SpringData1RedisLettuceConnectionFactoryConfigurer configurer = new SpringData1RedisLettuceConnectionFactoryConfigurer();
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory();
connectionFactory.setHostName(serviceInfo.getHost());
connectionFactory.setPort(serviceInfo.getPort());
connectionFactory.setPassword(serviceInfo.getPassword());
configurer.configure(connectionFactory, (RedisConnectionFactoryConfig) serviceConnectorConfig);
connectionFactory.afterPropertiesSet();
return connectionFactory;
} else {
throw new ServiceConnectorCreationException(String.format("Failed to create cloud Redis connection factory " + "for %s service. No client implementation classes " + " of jedis or lettuce clients implementation (%s, %s) not found", serviceInfo.getId(), JEDIS_CLASS_NAME, LETTUCE_CLASS_NAME));
}
}
use of org.springframework.cloud.service.ServiceConnectorCreationException in project spring-cloud-connectors by spring-cloud.
the class TomcatDbcpPooledDataSourceCreator method createDataSource.
private DataSource createDataSource(String className, RelationalServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig, String driverClassName, String validationQuery) {
try {
DataSource dataSource = (DataSource) Class.forName(className).newInstance();
setBasicDataSourceProperties(dataSource, serviceInfo, serviceConnectorConfig, driverClassName, validationQuery);
return new UrlDecodingDataSource(dataSource, "url");
} catch (Throwable e) {
throw new ServiceConnectorCreationException("Error instantiating Tomcat DBCP connection pool", e);
}
}
Aggregations