org.springframework.cloud.config.client.ConfigServicePropertySourceLocator Java Examples

The following examples show how to use org.springframework.cloud.config.client.ConfigServicePropertySourceLocator. 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: ConfigClientTestConfiguration.java    From rabbitmq-mock with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
    RestTemplate configServerClient = new RestTemplate();
    MockRestServiceServer mockConfigServer = MockRestServiceServer.bindTo(configServerClient).build();
    configServerClient.getInterceptors().add(0, new LoggingHttpInterceptor());
    // {@code putIfAbsent} here is important as we do not want to override values when context is refreshed
    ConfigServerValues configServerValues = new ConfigServerValues(mockConfigServer)
        .putIfAbsent(ConfigClient.USER_ROLE_KEY, "admin");

    ConfigurableListableBeanFactory beanFactory = configurableApplicationContext.getBeanFactory();

    try {
        beanFactory
            .getBean(ConfigServicePropertySourceLocator.class)
            .setRestTemplate(configServerClient);

        beanFactory.registerSingleton("configServerClient", configServerClient);
        beanFactory.registerSingleton("mockConfigServer", mockConfigServer);
        beanFactory.registerSingleton("configServerValues", configServerValues);

    } catch (NoSuchBeanDefinitionException e) {
        // too soon, ConfigServicePropertySourceLocator is not defined
    }
}
 
Example #2
Source File: ConfigClientOAuth2BootstrapConfigurationTest.java    From spring-cloud-services-starters with Apache License 2.0 6 votes vote down vote up
@Test
public void configServicePropertySourceLocatorHasOAuth2AuthorizedClientHttpRequestInterceptor() throws Exception {
	this.contextRunner.withPropertyValues("spring.cloud.config.client.oauth2.client-id=" + CLIENT_ID,
			"spring.cloud.config.client.oauth2.client-secret=" + CLIENT_SECRET,
			"spring.cloud.config.client.oauth2.access-token-uri=" + TOKEN_URI).run(context -> {
				assertThat(context).hasSingleBean(ConfigServicePropertySourceLocator.class);
				ConfigServicePropertySourceLocator locator = context
						.getBean(ConfigServicePropertySourceLocator.class);
				RestTemplate restTemplate = (RestTemplate) ReflectionTestUtils.getField(locator, "restTemplate");
				assertThat(restTemplate).isNotNull();
				assertThat(restTemplate.getInterceptors()).hasSize(1);
				assertThat(restTemplate.getInterceptors().get(0))
						.isInstanceOf(OAuth2AuthorizedClientHttpRequestInterceptor.class);
				OAuth2AuthorizedClientHttpRequestInterceptor interceptor = (OAuth2AuthorizedClientHttpRequestInterceptor) restTemplate
						.getInterceptors().get(0);
				ClientRegistration clientRegistration = interceptor.clientRegistration;
				assertThat(clientRegistration.getClientId()).isEqualTo(CLIENT_ID);
				assertThat(clientRegistration.getClientSecret()).isEqualTo(CLIENT_SECRET);
				assertThat(clientRegistration.getProviderDetails().getTokenUri()).isEqualTo(TOKEN_URI);
				assertThat(clientRegistration.getAuthorizationGrantType())
						.isEqualTo(AuthorizationGrantType.CLIENT_CREDENTIALS);
			});
}
 
Example #3
Source File: PeriodRefreshAutoConfiguration.java    From spring-cloud-formula with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public PeriodCheckRefreshEventEmitter refreshEventEmitter(ConfigServicePropertySourceLocator locator,
                                                          ContextRefresher refresher, Environment environment) {
    return new PeriodCheckRefreshEventEmitter((MultiModuleConfigServicePropertySourceLocator) locator,
            refresher, environment);
}
 
Example #4
Source File: MultiModuleConfigServiceBootstrapConfiguration.java    From spring-cloud-formula with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(ConfigServicePropertySourceLocator.class)
@ConditionalOnProperty(value = "spring.cloud.config.enabled", matchIfMissing = true)
public ConfigServicePropertySourceLocator configServicePropertySource(
        ConfigClientProperties client, ObjectProvider<ConfigEnvironmentPreprocessor> preprocessorObjectProvider) {
    MultiModuleConfigServicePropertySourceLocator l = new MultiModuleConfigServicePropertySourceLocator(client);
    preprocessorObjectProvider.ifAvailable(l::setPreprocessor);
    return l;
}
 
Example #5
Source File: ConfigClientConfiguration.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnProperty(value = "spring.cloud.config.enabled", matchIfMissing = true)
public ConfigServicePropertySourceLocator configServicePropertySource(ConfigClientProperties properties) {
	ConfigServicePropertySourceLocator locator = new ConfigServicePropertySourceLocator(properties);
	RestTemplate restTemplate = getSecureRestTemplate(properties);
	restTemplate.setMessageConverters(Arrays.asList(new ExtJackson2HttpMessageConverter()));
	locator.setRestTemplate(restTemplate);
	return locator;
}
 
Example #6
Source File: ConfigClientOAuth2BootstrapConfiguration.java    From spring-cloud-services-connector with Apache License 2.0 5 votes vote down vote up
@Autowired
public ConfigClientOAuth2Configurer(ConfigServicePropertySourceLocator locator, ConfigClientOAuth2ResourceDetails configClientOAuth2ResourceDetails) {
	Assert.notNull(locator, "Error injecting ConfigServicePropertySourceLocator, this can occur" +
			"using self signed certificates in Cloud Foundry without setting the TRUST_CERTS environment variable");
	this.locator = locator;
	this.configClientOAuth2ResourceDetails = configClientOAuth2ResourceDetails;
}
 
Example #7
Source File: ConfigClientOAuth2BootstrapConfiguration.java    From spring-cloud-services-starters with Apache License 2.0 5 votes vote down vote up
public ConfigClientOAuth2BootstrapConfiguration(ConfigServicePropertySourceLocator locator,
		ConfigClientOAuth2Properties configClientOAuth2Properties) {
	Assert.notNull(locator, "Error injecting ConfigServicePropertySourceLocator, this can occur"
			+ "using self signed certificates in Cloud Foundry without setting the TRUST_CERTS environment variable");
	this.locator = locator;
	this.configClientOAuth2Properties = configClientOAuth2Properties;
}
 
Example #8
Source File: ConfigClientOAuth2BootstrapConfigurationTest.java    From spring-cloud-services-starters with Apache License 2.0 5 votes vote down vote up
@Test
public void configServicePropertySourceLocatorIsUnchanged() throws Exception {
	this.contextRunner.run(context -> {
		assertThat(context).hasSingleBean(ConfigServicePropertySourceLocator.class);
		ConfigServicePropertySourceLocator locator = context.getBean(ConfigServicePropertySourceLocator.class);
		Field restTemplateField = ReflectionUtils.findField(ConfigServicePropertySourceLocator.class,
				"restTemplate");
		restTemplateField.setAccessible(true);
		assertThat(ReflectionUtils.getField(restTemplateField, locator)).isNull();
	});
}
 
Example #9
Source File: RefreshEventEmitter.java    From spring-cloud-formula with Apache License 2.0 4 votes vote down vote up
public RefreshEventEmitter(ConfigServicePropertySourceLocator locator, ContextRefresher refresher, Environment environment) {
    this.locator = locator;
    this.refresher = refresher;
    this.environment = environment;
}
 
Example #10
Source File: RefreshEventEmitter.java    From spring-cloud-formula with Apache License 2.0 4 votes vote down vote up
ConfigServicePropertySourceLocator getLocator() {
    return locator;
}
 
Example #11
Source File: ConfigClientOnIntegrationTests.java    From spring-cloud-config with Apache License 2.0 4 votes vote down vote up
@Test
public void configClientEnabled() throws Exception {
	assertThat(BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.context,
			ConfigServicePropertySourceLocator.class).length).isEqualTo(1);
}
 
Example #12
Source File: ConfigClientOffIntegrationTests.java    From spring-cloud-config with Apache License 2.0 4 votes vote down vote up
@Test
public void configClientDisabled() throws Exception {
	assertThat(BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.context,
			ConfigServicePropertySourceLocator.class).length).isEqualTo(0);
}