org.springframework.core.env.EnumerablePropertySource Java Examples

The following examples show how to use org.springframework.core.env.EnumerablePropertySource. 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: IntegrationTestConfiguration.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
private Map<String, String> getAllKnownProperties(Environment env) {
    Map<String, String> rtn = new HashMap<>();
    if (env instanceof ConfigurableEnvironment) {
        for (PropertySource<?> propertySource : ((ConfigurableEnvironment) env).getPropertySources()) {
            if (propertySource instanceof EnumerablePropertySource) {
                LOGGER.info("processing property source ::: " + propertySource.getName());
                for (String key : ((EnumerablePropertySource) propertySource).getPropertyNames()) {
                    String value = propertySource.getProperty(key).toString();
                    LOGGER.debug("{} = {}", key, value);
                    if (!StringUtils.isEmpty(value) && !rtn.containsKey(key)) {
                        rtn.put(key, propertySource.getProperty(key).toString());
                    }
                }
            }
        }
    }
    return rtn;
}
 
Example #2
Source File: EnvironmentConfigurationLogger.java    From kubernetes-crash-course with MIT License 6 votes vote down vote up
@SuppressWarnings("rawtypes")
@EventListener
public void handleContextRefresh(ContextRefreshedEvent event) {
	final Environment environment = event.getApplicationContext().getEnvironment();
	LOGGER.info("====== Environment and configuration ======");
	LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles()));
	final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources();
	StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource)
			.map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct()
			.forEach(prop -> {
				Object resolved = environment.getProperty(prop, Object.class);
				if (resolved instanceof String) {
					LOGGER.info("{} - {}", prop, environment.getProperty(prop));
				} else {
					LOGGER.info("{} - {}", prop, "NON-STRING-VALUE");
				}
				
			});
	LOGGER.debug("===========================================");
}
 
Example #3
Source File: EnvironmentConfigurationLogger.java    From kubernetes-crash-course with MIT License 6 votes vote down vote up
@SuppressWarnings("rawtypes")
@EventListener
public void handleContextRefresh(ContextRefreshedEvent event) {
	final Environment environment = event.getApplicationContext().getEnvironment();
	LOGGER.info("====== Environment and configuration ======");
	LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles()));
	final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources();
	StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource)
			.map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct()
			.forEach(prop -> {
				Object resolved = environment.getProperty(prop, Object.class);
				if (resolved instanceof String) {
					LOGGER.info("{} - {}", prop, environment.getProperty(prop));
				} else {
					LOGGER.info("{} - {}", prop, "NON-STRING-VALUE");
				}
				
			});
	LOGGER.debug("===========================================");
}
 
Example #4
Source File: EnvironmentConfigurationLogger.java    From kubernetes-crash-course with MIT License 6 votes vote down vote up
@SuppressWarnings("rawtypes")
@EventListener
public void handleContextRefresh(ContextRefreshedEvent event) {
	final Environment environment = event.getApplicationContext().getEnvironment();
	LOGGER.info("====== Environment and configuration ======");
	LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles()));
	final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources();
	StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource)
			.map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct()
			.forEach(prop -> {
				Object resolved = environment.getProperty(prop, Object.class);
				if (resolved instanceof String) {
					LOGGER.info("{} - {}", prop, environment.getProperty(prop));
				} else {
					LOGGER.info("{} - {}", prop, "NON-STRING-VALUE");
				}
				
			});
	LOGGER.debug("===========================================");
}
 
Example #5
Source File: EnvironmentConfigurationLogger.java    From kubernetes-crash-course with MIT License 6 votes vote down vote up
@SuppressWarnings("rawtypes")
@EventListener
public void handleContextRefresh(ContextRefreshedEvent event) {
	final Environment environment = event.getApplicationContext().getEnvironment();
	LOGGER.info("====== Environment and configuration ======");
	LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles()));
	final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources();
	StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource)
			.map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct()
			.forEach(prop -> {
				Object resolved = environment.getProperty(prop, Object.class);
				if (resolved instanceof String) {
					LOGGER.info("{} - {}", prop, environment.getProperty(prop));
				} else {
					LOGGER.info("{} - {}", prop, "NON-STRING-VALUE");
				}
				
			});
	LOGGER.debug("===========================================");
}
 
Example #6
Source File: EnvironmentConfigurationLogger.java    From pcf-crash-course-with-spring-boot with MIT License 6 votes vote down vote up
@SuppressWarnings("rawtypes")
	@EventListener
	public void handleContextRefresh(ContextRefreshedEvent event) {
		final Environment environment = event.getApplicationContext().getEnvironment();
		LOGGER.info("====== Environment and configuration ======");
		LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles()));
		final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources();
		StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource)
				.map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct()
				.forEach(prop -> {
					LOGGER.info("{}", prop);
//					Object resolved = environment.getProperty(prop, Object.class);
//					if (resolved instanceof String) {
//						LOGGER.info("{}", environment.getProperty(prop));
//					}
				});
		LOGGER.info("===========================================");
	}
 
Example #7
Source File: EnvironmentConfigurationLogger.java    From kubernetes-crash-course with MIT License 6 votes vote down vote up
@SuppressWarnings("rawtypes")
@EventListener
public void handleContextRefresh(ContextRefreshedEvent event) {
	final Environment environment = event.getApplicationContext().getEnvironment();
	LOGGER.info("====== Environment and configuration ======");
	LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles()));
	final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources();
	StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource)
			.map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct()
			.forEach(prop -> {
				Object resolved = environment.getProperty(prop, Object.class);
				if (resolved instanceof String) {
					LOGGER.info("{} - {}", prop, environment.getProperty(prop));
				} else {
					LOGGER.info("{} - {}", prop, "NON-STRING-VALUE");
				}
				
			});
	LOGGER.debug("===========================================");
}
 
Example #8
Source File: EnvironmentConfigurationLogger.java    From pcf-crash-course-with-spring-boot with MIT License 6 votes vote down vote up
@SuppressWarnings("rawtypes")
	@EventListener
	public void handleContextRefresh(ContextRefreshedEvent event) {
		final Environment environment = event.getApplicationContext().getEnvironment();
		LOGGER.info("====== Environment and configuration ======");
		LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles()));
		final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources();
		StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource)
				.map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct()
				.forEach(prop -> {
					LOGGER.info("{}", prop);
//					Object resolved = environment.getProperty(prop, Object.class);
//					if (resolved instanceof String) {
//						LOGGER.info("{}", environment.getProperty(prop));
//					}
				});
		LOGGER.info("===========================================");
	}
 
Example #9
Source File: MqEnvProp.java    From pmq with Apache License 2.0 6 votes vote down vote up
public Map<String, Map<String, Object>> getAllEnv() {  
	Map<String, Map<String, Object>> result = new LinkedHashMap<String, Map<String, Object>>();		
	for (Entry<String, PropertySource<?>> entry : getPropertySources().entrySet()) {
		PropertySource<?> source = entry.getValue();
		String sourceName = entry.getKey();
		if (source instanceof EnumerablePropertySource) {
			EnumerablePropertySource<?> enumerable = (EnumerablePropertySource<?>) source;
			Map<String, Object> properties = new LinkedHashMap<String, Object>();
			for (String name : enumerable.getPropertyNames()) {
				properties.put(name, sanitize(name, enumerable.getProperty(name)));
			}
			result.put(sourceName, properties);				
		}
	}
	return result;
}
 
Example #10
Source File: EnvironmentConfigurationLogger.java    From kubernetes-crash-course with MIT License 6 votes vote down vote up
@SuppressWarnings("rawtypes")
@EventListener
public void handleContextRefresh(ContextRefreshedEvent event) {
	final Environment environment = event.getApplicationContext().getEnvironment();
	LOGGER.info("====== Environment and configuration ======");
	LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles()));
	final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources();
	StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource)
			.map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct()
			.forEach(prop -> {
				Object resolved = environment.getProperty(prop, Object.class);
				if (resolved instanceof String) {
					LOGGER.info("{} - {}", prop, environment.getProperty(prop));
				} else {
					LOGGER.info("{} - {}", prop, "NON-STRING-VALUE");
				}
				
			});
	LOGGER.debug("===========================================");
}
 
Example #11
Source File: EnvironmentConfigurationLogger.java    From kubernetes-crash-course with MIT License 6 votes vote down vote up
@SuppressWarnings("rawtypes")
@EventListener
public void handleContextRefresh(ContextRefreshedEvent event) {
	final Environment environment = event.getApplicationContext().getEnvironment();
	LOGGER.info("====== Environment and configuration ======");
	LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles()));
	final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources();
	StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource)
			.map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct()
			.forEach(prop -> {
				Object resolved = environment.getProperty(prop, Object.class);
				if (resolved instanceof String) {
					LOGGER.info("{} - {}", prop, environment.getProperty(prop));
				} else {
					LOGGER.info("{} - {}", prop, "NON-STRING-VALUE");
				}
				
			});
	LOGGER.debug("===========================================");
}
 
Example #12
Source File: EnvironmentConfigurationLogger.java    From kubernetes-crash-course with MIT License 6 votes vote down vote up
@SuppressWarnings("rawtypes")
@EventListener
public void handleContextRefresh(ContextRefreshedEvent event) {
	final Environment environment = event.getApplicationContext().getEnvironment();
	LOGGER.info("====== Environment and configuration ======");
	LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles()));
	final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources();
	StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource)
			.map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct()
			.forEach(prop -> {
				Object resolved = environment.getProperty(prop, Object.class);
				if (resolved instanceof String) {
					LOGGER.info("{} - {}", prop, environment.getProperty(prop));
				} else {
					LOGGER.info("{} - {}", prop, "NON-STRING-VALUE");
				}
				
			});
	LOGGER.debug("===========================================");
}
 
Example #13
Source File: EnvironmentConfigurationLogger.java    From kubernetes-crash-course with MIT License 6 votes vote down vote up
@SuppressWarnings("rawtypes")
@EventListener
public void handleContextRefresh(ContextRefreshedEvent event) {
	final Environment environment = event.getApplicationContext().getEnvironment();
	LOGGER.info("====== Environment and configuration ======");
	LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles()));
	final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources();
	StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource)
			.map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct()
			.forEach(prop -> {
				Object resolved = environment.getProperty(prop, Object.class);
				if (resolved instanceof String) {
					LOGGER.info("{} - {}", prop, environment.getProperty(prop));
				} else {
					LOGGER.info("{} - {}", prop, "NON-STRING-VALUE");
				}
				
			});
	LOGGER.debug("===========================================");
}
 
Example #14
Source File: EnvironmentConfigurationLogger.java    From docker-crash-course with MIT License 6 votes vote down vote up
@SuppressWarnings("rawtypes")
	@EventListener
	public void handleContextRefresh(ContextRefreshedEvent event) {
		final Environment environment = event.getApplicationContext().getEnvironment();
		LOGGER.debug("====== Environment and configuration ======");
		LOGGER.debug("Active profiles: {}", Arrays.toString(environment.getActiveProfiles()));
		final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources();
		StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource)
				.map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct()
				.forEach(prop -> {
					LOGGER.debug("{}", prop);
//					Object resolved = environment.getProperty(prop, Object.class);
//					if (resolved instanceof String) {
//						LOGGER.info("{}", environment.getProperty(prop));
//					}
				});
		LOGGER.debug("===========================================");
	}
 
Example #15
Source File: EnvironmentConfigurationLogger.java    From docker-crash-course with MIT License 6 votes vote down vote up
@SuppressWarnings("rawtypes")
	@EventListener
	public void handleContextRefresh(ContextRefreshedEvent event) {
		final Environment environment = event.getApplicationContext().getEnvironment();
		LOGGER.debug("====== Environment and configuration ======");
		LOGGER.debug("Active profiles: {}", Arrays.toString(environment.getActiveProfiles()));
		final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources();
		StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource)
				.map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct()
				.forEach(prop -> {
					LOGGER.debug("{}", prop);
//					Object resolved = environment.getProperty(prop, Object.class);
//					if (resolved instanceof String) {
//						LOGGER.info("{}", environment.getProperty(prop));
//					}
				});
		LOGGER.debug("===========================================");
	}
 
Example #16
Source File: EnvironmentConfigurationLogger.java    From docker-crash-course with MIT License 6 votes vote down vote up
@SuppressWarnings("rawtypes")
	@EventListener
	public void handleContextRefresh(ContextRefreshedEvent event) {
		final Environment environment = event.getApplicationContext().getEnvironment();
		LOGGER.debug("====== Environment and configuration ======");
		LOGGER.debug("Active profiles: {}", Arrays.toString(environment.getActiveProfiles()));
		final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources();
		StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource)
				.map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct()
				.forEach(prop -> {
					LOGGER.debug("{}", prop);
//					Object resolved = environment.getProperty(prop, Object.class);
//					if (resolved instanceof String) {
//						LOGGER.info("{}", environment.getProperty(prop));
//					}
				});
		LOGGER.debug("===========================================");
	}
 
Example #17
Source File: EnvProp.java    From radar with Apache License 2.0 6 votes vote down vote up
public Map<String, Map<String, Object>> getAllEnv() {
	Map<String, Map<String, Object>> result = new LinkedHashMap<String, Map<String, Object>>();		
	for (Entry<String, PropertySource<?>> entry : getPropertySources().entrySet()) {
		PropertySource<?> source = entry.getValue();
		String sourceName = entry.getKey();
		if (source instanceof EnumerablePropertySource) {
			EnumerablePropertySource<?> enumerable = (EnumerablePropertySource<?>) source;
			Map<String, Object> properties = new LinkedHashMap<String, Object>();
			for (String name : enumerable.getPropertyNames()) {
				properties.put(name, sanitize(name, enumerable.getProperty(name)));
			}
			result.put(sourceName, properties);				
		}
	}
	return result;
}
 
Example #18
Source File: Application.java    From Mahuta with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
@EventListener
public void handleContextRefresh(ContextRefreshedEvent event) {
    
    final Environment env = event.getApplicationContext().getEnvironment();
    log.trace("====== Environment and configuration ======");
    log.trace("Active profiles: {}", Arrays.toString(env.getActiveProfiles()));
    final MutablePropertySources sources = ((AbstractEnvironment) env).getPropertySources();
    StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource)
            .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct()
            .filter(prop -> !(prop.contains("credentials") || prop.contains("password")))
            .forEach(prop -> log.trace("{}: {}", prop, env.getProperty(prop)));
    
    log.info("===========================================");
    
    log.info("Application [{} - version: {}, build time: {}] Started !", 
            buildProperties.getGroup() + ":" + buildProperties.getArtifact(), 
            buildProperties.getVersion(),
            buildProperties.getTime());
    
    log.info("===========================================");
}
 
Example #19
Source File: ConfigurationSpringInitializer.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
/**
 * Get property names from {@link EnumerablePropertySource}, and get property value from {@link ConfigurableEnvironment#getProperty(String)}
 */
private void getProperties(ConfigurableEnvironment environment, PropertySource<?> propertySource,
    Map<String, Object> configFromSpringBoot) {
  if (propertySource instanceof CompositePropertySource) {
    // recursively get EnumerablePropertySource
    CompositePropertySource compositePropertySource = (CompositePropertySource) propertySource;
    compositePropertySource.getPropertySources().forEach(ps -> getProperties(environment, ps, configFromSpringBoot));
    return;
  }
  if (propertySource instanceof EnumerablePropertySource) {
    EnumerablePropertySource<?> enumerablePropertySource = (EnumerablePropertySource<?>) propertySource;
    for (String propertyName : enumerablePropertySource.getPropertyNames()) {
      try {
        configFromSpringBoot.put(propertyName, environment.getProperty(propertyName, Object.class));
      } catch (Exception e) {
        throw new RuntimeException(
            "set up spring property source failed.If you still want to start up the application and ignore errors, you can set servicecomb.config.ignoreResolveFailure to true.",
            e);
      }
    }
    return;
  }

  LOGGER.debug("a none EnumerablePropertySource is ignored, propertySourceName = [{}]", propertySource.getName());
}
 
Example #20
Source File: SpringConfig.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
/**
 * Based on the following recommendation: https://github.com/spring-projects/spring-framework/issues/14874
 */
private Map<String, Object> getAllProperties() {
    Map<String, Object> all = new HashMap<>();
    if (environment instanceof ConfigurableEnvironment) {
        for (PropertySource<?> propertySource : ((ConfigurableEnvironment) environment).getPropertySources()) {
            if (propertySource instanceof EnumerablePropertySource) {
                for (String key : ((EnumerablePropertySource) propertySource).getPropertyNames()) {
                    if (key.startsWith(prefix)) {
                        all.put(key.substring(prefix.length()), propertySource.getProperty(key));
                    }
                }
            }
        }
    }
    return all;
}
 
Example #21
Source File: VcapPropertySourceUnitTests.java    From spring-boot-data-geode with Apache License 2.0 6 votes vote down vote up
@Test
public void fromEnvironmentIsSuccessful() {

	ConfigurableEnvironment mockEnvironment = mock(ConfigurableEnvironment.class);

	MutablePropertySources propertySources = spy(new MutablePropertySources());

	PropertySource mockVcapPropertySource = mock(EnumerablePropertySource.class);

	when(mockEnvironment.getPropertySources()).thenReturn(propertySources);
	doReturn(mockVcapPropertySource).when(propertySources).get(eq("vcap"));
	when(mockVcapPropertySource.containsProperty(anyString())).thenReturn(true);
	when(mockVcapPropertySource.getName()).thenReturn("vcap");

	VcapPropertySource propertySource = VcapPropertySource.from(mockEnvironment);

	assertThat(propertySource).isNotNull();
	assertThat(propertySource.getSource()).isEqualTo(mockVcapPropertySource);

	verify(mockEnvironment, times(1)).getPropertySources();
	verify(propertySources, times(1)).get(eq("vcap"));
	verify(mockVcapPropertySource, times(1))
		.containsProperty(eq("vcap.application.name"));
	verify(mockVcapPropertySource, times(1))
		.containsProperty(eq("vcap.application.uris"));
}
 
Example #22
Source File: EnvironmentHelper.java    From jeesuite-libs with Apache License 2.0 6 votes vote down vote up
public static Map<String, Object> getAllProperties(String prefix){
	if(environment == null)init();
	MutablePropertySources propertySources = ((ConfigurableEnvironment)environment).getPropertySources();
	
	Map<String, Object> properties = new LinkedHashMap<String, Object>();
	for (PropertySource<?> source : propertySources) {
		if(source.getName().startsWith("servlet") || source.getName().startsWith("system")){
			continue;
		}
		if (source instanceof EnumerablePropertySource) {
			for (String name : ((EnumerablePropertySource<?>) source) .getPropertyNames()) {
				boolean match = StringUtils.isEmpty(prefix);
				if(!match){
					match = name.startsWith(prefix);
				}
				if(match){						
					Object value = source.getProperty(name);
					if(value != null){
						properties.put(name, value);
					}
				}
			}
		}
	}
	return Collections.unmodifiableMap(properties);
}
 
Example #23
Source File: SpringEnvironmentPolledConfigurationSource.java    From kork with Apache License 2.0 6 votes vote down vote up
@Override
public PollResult poll(boolean initial, Object checkPoint) throws Exception {
  Map<String, Object> result = new HashMap<>();
  environment
      .getPropertySources()
      .iterator()
      .forEachRemaining(
          source -> {
            if (source instanceof EnumerablePropertySource) {
              EnumerablePropertySource<?> enumerable = (EnumerablePropertySource<?>) source;
              for (String key : enumerable.getPropertyNames()) {
                result.putIfAbsent(key, enumerable.getProperty(key));
              }
            }
          });
  return PollResult.createFull(result);
}
 
Example #24
Source File: SecretBeanPostProcessor.java    From kork with Apache License 2.0 6 votes vote down vote up
SecretBeanPostProcessor(
    ConfigurableApplicationContext applicationContext, SecretManager secretManager) {
  this.applicationContext = applicationContext;
  this.secretManager = secretManager;
  MutablePropertySources propertySources =
      applicationContext.getEnvironment().getPropertySources();
  List<EnumerablePropertySource> enumerableSources = new ArrayList<>();

  for (PropertySource ps : propertySources) {
    if (ps instanceof EnumerablePropertySource) {
      enumerableSources.add((EnumerablePropertySource) ps);
    }
  }

  for (EnumerablePropertySource s : enumerableSources) {
    propertySources.replace(s.getName(), new SecretAwarePropertySource(s, secretManager));
  }
}
 
Example #25
Source File: GspAutoConfiguration.java    From grails-boot with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void updateFlatConfig() {
    super.updateFlatConfig();
    if(this.environment instanceof ConfigurableEnvironment) {
        ConfigurableEnvironment configurableEnv = ((ConfigurableEnvironment)environment);
        for(PropertySource<?> propertySource : configurableEnv.getPropertySources()) {
            if(propertySource instanceof EnumerablePropertySource) {
                EnumerablePropertySource<?> enumerablePropertySource = (EnumerablePropertySource)propertySource;
                for(String propertyName : enumerablePropertySource.getPropertyNames()) {
                    flatConfig.put(propertyName, enumerablePropertySource.getProperty(propertyName));
                }
            }
        }
    }
}
 
Example #26
Source File: CloudbreakTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
private Map<String, String> getAllKnownProperties(Environment env) {
    Map<String, String> rtn = new HashMap<>();
    if (env instanceof ConfigurableEnvironment) {
        for (PropertySource<?> propertySource : ((ConfigurableEnvironment) env).getPropertySources()) {
            if (propertySource instanceof EnumerablePropertySource) {
                LOGGER.info("processing property source ::: " + propertySource.getName());
                for (String key : ((EnumerablePropertySource) propertySource).getPropertyNames()) {
                    String value = propertySource.getProperty(key).toString();
                    if (!StringUtils.isEmpty(value)) {
                        rtn.put(key, propertySource.getProperty(key).toString());
                    }
                }
            }
        }
    }
    return rtn;
}
 
Example #27
Source File: EnvironmentConfigurationLogger.java    From pcf-crash-course-with-spring-boot with MIT License 6 votes vote down vote up
@SuppressWarnings("rawtypes")
	@EventListener
	public void handleContextRefresh(ContextRefreshedEvent event) {
		final Environment environment = event.getApplicationContext().getEnvironment();
		LOGGER.info("====== Environment and configuration ======");
		LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles()));
		final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources();
		StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource)
				.map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct()
				.forEach(prop -> {
					LOGGER.info("{}", prop);
//					Object resolved = environment.getProperty(prop, Object.class);
//					if (resolved instanceof String) {
//						LOGGER.info("{}", environment.getProperty(prop));
//					}
				});
		LOGGER.info("===========================================");
	}
 
Example #28
Source File: SpringPropertySource.java    From hub-detect with Apache License 2.0 5 votes vote down vote up
@Override
public Set<String> getPropertyKeys() {
    Set<String> keys = new HashSet<>();
    final MutablePropertySources mutablePropertySources = configurableEnvironment.getPropertySources();
    for (final org.springframework.core.env.PropertySource<?> propertySource : mutablePropertySources) {
        if (propertySource instanceof EnumerablePropertySource) {
            final EnumerablePropertySource<?> enumerablePropertySource = (EnumerablePropertySource<?>) propertySource;
            for (final String propertyName : enumerablePropertySource.getPropertyNames()) {
                keys.add(propertyName);
            }
        }
    }
    return keys;
}
 
Example #29
Source File: InlinedPropertiesTestPropertySourceTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void propertyNameOrderingIsPreservedInEnvironment() {
	final String[] expectedPropertyNames = new String[] { "foo", "baz", "enigma", "x.y.z", "server.url",
		"key.value.1", "key.value.2", "key.value.3" };
	EnumerablePropertySource eps = (EnumerablePropertySource) env.getPropertySources().get(
		INLINED_PROPERTIES_PROPERTY_SOURCE_NAME);
	assertArrayEquals(expectedPropertyNames, eps.getPropertyNames());
}
 
Example #30
Source File: MqEnvProp.java    From pmq with Apache License 2.0 5 votes vote down vote up
public Map<String, Object> getEnv(String prefix) {
	Map<String, Object> result = new LinkedHashMap<String, Object>();		
	for (Entry<String, PropertySource<?>> entry : getPropertySources().entrySet()) {
		PropertySource<?> source = entry.getValue();			
		if (source instanceof EnumerablePropertySource) {
			EnumerablePropertySource<?> enumerable = (EnumerablePropertySource<?>) source;
			for (String name : enumerable.getPropertyNames()) {
				if(!result.containsKey(name)&&name.startsWith(prefix)&&!prefix.equals(name)){
					result.put(name, sanitize(name, enumerable.getProperty(name)));
				}
			}				
		}
	}
	return result;
}