org.springframework.cloud.service.ServiceConnectorConfig Java Examples
The following examples show how to use
org.springframework.cloud.service.ServiceConnectorConfig.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractCloudServiceFactoryParser.java From spring-cloud-connectors with Apache License 2.0 | 6 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { try { Constructor<?> ctor = serviceConnectorFactoryType.getConstructor(String.class, ServiceConnectorConfig.class); AbstractCloudServiceConnectorFactory<?> serviceFactory = (AbstractCloudServiceConnectorFactory<?>)ctor.newInstance(serviceId, serviceConnectorConfig); serviceFactory.setServiceConnectorType((Class)serviceConnectorType); serviceFactory.setBeanFactory(beanFactory); serviceFactory.afterPropertiesSet(); // id is the beanId if specified, otherwise the serviceId if (StringUtils.hasText(beanId)) { beanFactory.registerSingleton(beanId, serviceFactory); } else { beanFactory.registerSingleton(serviceFactory.getServiceId(), serviceFactory); } } catch (Exception ex) { throw new BeanCreationException("Error registering service factory", ex); } }
Example #2
Source File: RabbitConnectionFactoryCreator.java From spring-cloud-connectors with Apache License 2.0 | 6 votes |
private CachingConnectionFactory createSpringConnectionFactory(AmqpServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfiguration, com.rabbitmq.client.ConnectionFactory connectionFactory) { CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(connectionFactory); if (serviceInfo.getUris() != null) { cachingConnectionFactory.setAddresses(getAddresses(serviceInfo)); } if (serviceConnectorConfiguration != null) { Integer channelCacheSize = ((RabbitConnectionFactoryConfig) serviceConnectorConfiguration).getChannelCacheSize(); if (channelCacheSize != null) { cachingConnectionFactory.setChannelCacheSize(channelCacheSize); } } return cachingConnectionFactory; }
Example #3
Source File: CloudantInstanceCreatorTest.java From bluemix-cloud-connectors with Apache License 2.0 | 6 votes |
@Test public void testCreate() { final CloudantServiceInfo badUrlServiceInfo = new CloudantServiceInfo( "id", "username", "password", "hostname", 443, "url" ); assertNull(creator.create(badUrlServiceInfo, new ServiceConnectorConfig() { })); final CloudantServiceInfo serviceInfo = new CloudantServiceInfo( "testId", "username", "password", "username.cloudant.com", 443, "https://username:[email protected]" ); assertTrue(creator.create(serviceInfo, new ServiceConnectorConfig() { }) instanceof CouchDbInstance); }
Example #4
Source File: DataSourceCreator.java From spring-cloud-connectors with Apache License 2.0 | 6 votes |
private Collection<PooledDataSourceCreator<SI>> filterPooledDataSourceCreators(ServiceConnectorConfig serviceConnectorConfig) { if (serviceConnectorConfig != null) { List<String> pooledDataSourceNames = ((DataSourceConfig) serviceConnectorConfig).getPooledDataSourceNames(); if (pooledDataSourceNames != null) { List<PooledDataSourceCreator<SI>> filtered = new ArrayList<>(); for (String name : pooledDataSourceNames) { for (String key : pooledDataSourceCreators.keySet()) { if (key.contains(name)) { filtered.add(pooledDataSourceCreators.get(key)); } } } return filtered; } } return pooledDataSourceCreators.values(); }
Example #5
Source File: EnterpriseMessagingConfig.java From cloud-espm-cloud-native with Apache License 2.0 | 5 votes |
@Bean public MessagingServiceFactory getMessagingServiceFactory() { ServiceConnectorConfig config = null; // currently there are no configurations for the MessagingService supported Cloud cloud = new CloudFactory().getCloud(); // get the MessagingService via the service connector MessagingService messagingService = cloud.getSingletonServiceConnector(MessagingService.class, config); if (messagingService == null) { throw new IllegalStateException("Unable to create the MessagingService."); } return MessagingServiceFactoryCreator.createFactory(messagingService); }
Example #6
Source File: AbstractCloudServiceFactoryParser.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
public CloudServiceIntroducer(Class<? extends CloudServiceConnectorFactory<?>> serviceConnectorFactoryType, String beanId, String serviceId, ServiceConnectorConfig serviceConnectorConfig) { this.serviceConnectorFactoryType = serviceConnectorFactoryType; this.beanId = beanId; this.serviceId = serviceId; this.serviceConnectorConfig = serviceConnectorConfig; }
Example #7
Source File: MailSenderCreator.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
@Override public JavaMailSender create(SmtpServiceInfo serviceInfo, ServiceConnectorConfig config) { JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost(serviceInfo.getHost()); mailSender.setPort(serviceInfo.getPort()); mailSender.setUsername(serviceInfo.getUserName()); mailSender.setPassword(serviceInfo.getPassword()); return mailSender; }
Example #8
Source File: HikariCpPooledDataSourceCreator.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
@Override public DataSource create(RelationalServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig, String driverClassName, String validationQuery) { if (hasClass(HIKARI_DATASOURCE)) { logger.info("Found HikariCP on the classpath. Using it for DataSource connection pooling."); HikariDataSource ds = new HikariDataSource(); setBasicDataSourceProperties(ds, serviceInfo, serviceConnectorConfig, driverClassName, validationQuery); return new UrlDecodingDataSource(ds, "jdbcUrl"); } else { return null; } }
Example #9
Source File: HikariCpPooledDataSourceCreator.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
protected void setBasicDataSourceProperties(DataSource basicDataSource, RelationalServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig, String driverClassName, String validationQuery) { BeanWrapper target = new BeanWrapperImpl(basicDataSource); target.setPropertyValue("driverClassName", driverClassName); target.setPropertyValue("jdbcUrl", serviceInfo.getJdbcUrl()); if (validationQuery != null) { target.setPropertyValue("connectionTestQuery", validationQuery); } configurer.configure(basicDataSource, (DataSourceConfig)serviceConnectorConfig); }
Example #10
Source File: BasicDbcpPooledDataSourceCreator.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
@Override public DataSource create(RelationalServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig, String driverClassName, String validationQuery) { if (hasClass(DBCP2_BASIC_DATASOURCE)) { logger.info("Found DBCP2 on the classpath. Using it for DataSource connection pooling."); org.apache.commons.dbcp2.BasicDataSource ds = new org.apache.commons.dbcp2.BasicDataSource(); setBasicDataSourceProperties(ds, serviceInfo, serviceConnectorConfig, driverClassName, validationQuery); return new UrlDecodingDataSource(ds, "url"); } return null; }
Example #11
Source File: DbcpLikePooledDataSourceCreator.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
protected void setBasicDataSourceProperties(DataSource basicDataSource, RelationalServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig, String driverClassName, String validationQuery) { BeanWrapper target = new BeanWrapperImpl(basicDataSource); target.setPropertyValue("driverClassName", driverClassName); target.setPropertyValue("url", serviceInfo.getJdbcUrl()); if (validationQuery != null) { target.setPropertyValue("validationQuery", validationQuery); target.setPropertyValue("testOnBorrow", true); } configurer.configure(basicDataSource, (DataSourceConfig)serviceConnectorConfig); }
Example #12
Source File: TomcatDbcpPooledDataSourceCreator.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
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); } }
Example #13
Source File: TomcatDbcpPooledDataSourceCreator.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
@Override public DataSource create(RelationalServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig, String driverClassName, String validationQuery) { if (hasClass(TOMCAT_7_DBCP)) { logger.info("Found Tomcat 7 DBCP connection pool on the classpath. Using it for DataSource connection pooling."); return createDataSource(TOMCAT_7_DBCP, serviceInfo, serviceConnectorConfig, driverClassName, validationQuery); } else if (hasClass(TOMCAT_8_DBCP)) { logger.info("Found Tomcat 8 DBCP connection pool on the classpath. Using it for DataSource connection pooling."); return createDataSource(TOMCAT_8_DBCP, serviceInfo, serviceConnectorConfig, driverClassName, validationQuery); } else { return null; } }
Example #14
Source File: TomcatJdbcPooledDataSourceCreator.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
@Override public DataSource create(RelationalServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig, String driverClassName, String validationQuery) { if (hasClass(TOMCAT_JDBC_DATASOURCE)) { logger.info("Found Tomcat JDBC connection pool on the classpath. Using it for DataSource connection pooling."); org.apache.tomcat.jdbc.pool.DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource(); setBasicDataSourceProperties(ds, serviceInfo, serviceConnectorConfig, driverClassName, validationQuery); return new UrlDecodingDataSource(ds, "url"); } else { return null; } }
Example #15
Source File: DataSourceCreator.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
@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); } }
Example #16
Source File: DataSourceCreator.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
private DataSource createPooledDataSource(SI serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { Collection<PooledDataSourceCreator<SI>> delegates = filterPooledDataSourceCreators(serviceConnectorConfig); for (PooledDataSourceCreator<SI> delegate : delegates) { DataSource ds = delegate.create(serviceInfo, serviceConnectorConfig, getDriverClassName(serviceInfo), validationQuery); if (ds != null) { return ds; } } return null; }
Example #17
Source File: Cloud.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
/** * Get the singleton service connector for the given connector type, configured with the given config * * @param <SC> The class of the service connector to return. * @param serviceConnectorType The expected class of service connector such as, DataSource.class. * @param serviceConnectorConfig service connector configuration (such as pooling parameters). * @return the single service connector of the specified type with the given configuration applied * */ public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType); if (matchingServiceInfos.size() != 1) { throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found " + matchingServiceInfos.size()); } ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0); return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig); }
Example #18
Source File: CloudantInstanceCreator.java From bluemix-cloud-connectors with Apache License 2.0 | 5 votes |
@Override public CouchDbInstance create(CloudantServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { HttpClient httpClient; try { httpClient = new StdHttpClient.Builder() .url(serviceInfo.getUrl()) .build(); return new StdCouchDbInstance(httpClient); } catch (MalformedURLException e) { LOG.logp(Level.WARNING, CloudantInstanceCreator.class.getName(), "create", "Error parsing URL", e); return null; } }
Example #19
Source File: EnterpriseMessagingConfig.java From cloud-espm-cloud-native with Apache License 2.0 | 5 votes |
@Bean public MessagingServiceFactory getMessagingServiceFactory() { ServiceConnectorConfig config = null; // currently there are no configurations for the MessagingService supported Cloud cloud = new CloudFactory().getCloud(); // get the MessagingService via the service connector MessagingService messagingService = cloud.getSingletonServiceConnector(MessagingService.class, config); if (messagingService == null) { throw new IllegalStateException("Unable to create the MessagingService."); } return MessagingServiceFactoryCreator.createFactory(messagingService); }
Example #20
Source File: KafkaConnectionCreator.java From kafka-service-broker with Apache License 2.0 | 5 votes |
@Override public KafkaRepository create(KafkaServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { log.info("creating kafka repo wth service info: " + serviceInfo); try { return new KafkaRepositoryFactory().create(serviceInfo); } catch (InterruptedException e) { log.error(e.getLocalizedMessage(), e); return null; } }
Example #21
Source File: RabbitConnectionFactoryFactoryTest.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
public RabbitConnectionFactoryFactory createTestCloudServiceConnectorFactory(String id, ServiceConnectorConfig config) { return new RabbitConnectionFactoryFactory(id, config); }
Example #22
Source File: RedisConnectionFactoryFactoryTest.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
public RedisConnectionFactoryFactory createTestCloudServiceConnectorFactory(String id, ServiceConnectorConfig config) { return new RedisConnectionFactoryFactory(id, config); }
Example #23
Source File: SpringData1RedisConnectionFactoryFactoryTest.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
public RedisConnectionFactoryFactory createTestCloudServiceConnectorFactory(String id, ServiceConnectorConfig config) { return new RedisConnectionFactoryFactory(id, config); }
Example #24
Source File: MailSenderFactoryTest.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
public MailSenderFactory createTestCloudServiceConnectorFactory(String id, ServiceConnectorConfig config) { return new MailSenderFactory(id, config); }
Example #25
Source File: CassandraClusterFactoryTest.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
public CassandraClusterFactory createTestCloudServiceConnectorFactory(String id, ServiceConnectorConfig config) { return new CassandraClusterFactory(id, config); }
Example #26
Source File: AbstractDataSourceFactoryTest.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
public CloudDataSourceFactory createTestCloudServiceConnectorFactory(String id, ServiceConnectorConfig config) { return new CloudDataSourceFactory(id, config); }
Example #27
Source File: PooledDataSourceCreatorsTest.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
private DataSource createMysqlDataSource(ServiceConnectorConfig config) { return mysqlDataSourceCreator.create(mockMysqlServiceInfo, config); }
Example #28
Source File: MongoDbFactoryFactoryTest.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
public MongoDbFactoryFactory createTestCloudServiceConnectorFactory(String id, ServiceConnectorConfig config) { return new MongoDbFactoryFactory(id, config); }
Example #29
Source File: CloudServiceConnectionFactory.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
@Override public <T> T service(String serviceId, Class<T> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig){ return cloud.getServiceConnector(serviceId, serviceConnectorType, serviceConnectorConfig); }
Example #30
Source File: MongoDbFactoryFactory.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
public MongoDbFactoryFactory(String serviceId, ServiceConnectorConfig serviceConnectorConfiguration) { super(serviceId, MongoDbFactory.class, serviceConnectorConfiguration); }