/** * Get Sub {@link Properties} * * @param propertySources {@link PropertySource} Iterable * @param prefix the prefix of property name * @return Map * @see Properties */ public static Map<String, Object> getSubProperties(Iterable<PropertySource<?>> propertySources, String prefix) { // Non-Extension AbstractEnvironment AbstractEnvironment environment = new AbstractEnvironment() { }; MutablePropertySources mutablePropertySources = environment.getPropertySources(); for (PropertySource<?> source : propertySources) { mutablePropertySources.addLast(source); } return getSubProperties(environment, prefix); }
/** * Get Sub {@link Properties} * * @param propertySources {@link PropertySource} Iterable * @param prefix the prefix of property name * @return Map * @see Properties */ public static Map<String, Object> getSubProperties(Iterable<PropertySource<?>> propertySources, String prefix) { // Non-Extension AbstractEnvironment AbstractEnvironment environment = new AbstractEnvironment() { }; MutablePropertySources mutablePropertySources = environment.getPropertySources(); for (PropertySource<?> source : propertySources) { mutablePropertySources.addLast(source); } return getSubProperties(environment, prefix); }
/** * get All properties */ public Map<String, Object> getAllProperties() { if (properties == null || properties.isEmpty()) { synchronized (SpringEnvironmentProperties.class) { if (properties == null || properties.isEmpty()) { Map<String, Object> map = new HashMap(); for (Iterator it = ((AbstractEnvironment) env).getPropertySources().iterator(); it.hasNext(); ) { PropertySource propertySource = (PropertySource) it.next(); if (propertySource instanceof MapPropertySource) { map.putAll(((MapPropertySource) propertySource).getSource()); } } //decrypt Map<String, Object> decryptedMap = new HashMap(); for (String k : map.keySet()) { decryptedMap.put(k, env.getProperty(k)); } properties = decryptedMap; } } } return properties; }
AbstractEnvironment ae = (AbstractEnvironment)env; org.springframework.core.env.PropertySource source = ae.getPropertySources().get("sample.props"); Properties props = (Properties)source.getSource();
return defaultConfiguration.getPropertySources().get(FIRST); return defaultConfiguration.getPropertySources().get(SECOND);
private Map<String, String> getCurrentEnvironmentProperties() { Map<String, String> currentEnvironment = new HashMap<>(); Set<String> keys = new HashSet<>(); for (PropertySource<?> propertySource : ((AbstractEnvironment) this.environment).getPropertySources()) { if (propertySource instanceof MapPropertySource) { keys.addAll(Arrays.asList(((MapPropertySource) propertySource).getPropertyNames())); } } for (String key : keys) { currentEnvironment.put(key, this.environment.getProperty(key)); } return currentEnvironment; } }
@Bean public static PropertySourcesPlaceholderConfigurer properties(Environment environment) throws IOException { AbstractEnvironment standardEnvironment = ((AbstractEnvironment) environment); MutablePropertySources propertySources = standardEnvironment.getPropertySources(); propertySources.addLast(new DurationValuePropertySource()); }
private Map<String, String> getCurrentEnvironmentProperties() { Map<String, String> currentEnvironment = new HashMap<>(); Set<String> keys = new HashSet<>(); for (PropertySource<?> propertySource : ((AbstractEnvironment) this.environment).getPropertySources()) { if (propertySource instanceof MapPropertySource) { keys.addAll(Arrays.asList(((MapPropertySource) propertySource).getPropertyNames())); } } for (String key : keys) { currentEnvironment.put(key, this.environment.getProperty(key)); } return currentEnvironment; } }
@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.trace("==========================================="); }
/** * get All properties */ public Map<String, Object> getAllProperties() { if (properties == null || properties.isEmpty()) { synchronized (SpringEnvironmentProperties.class) { if (properties == null || properties.isEmpty()) { Map<String, Object> map = new HashMap(); for (Iterator it = ((AbstractEnvironment) env).getPropertySources().iterator(); it.hasNext(); ) { PropertySource propertySource = (PropertySource) it.next(); if (propertySource instanceof MapPropertySource) { map.putAll(((MapPropertySource) propertySource).getSource()); } } //decrypt Map<String, Object> decryptedMap = new HashMap(); for (String k : map.keySet()) { decryptedMap.put(k, env.getProperty(k)); } properties = decryptedMap; } } } return properties; }
public SysEnvEnvironment() { PropertySource<?> source = new SysEnvPropertySource(); MutablePropertySources sources = super.getPropertySources(); sources.addFirst(source); }
@Override public void setEnvironment(Environment environment) { LOGGER.trace("Started setEnvironment"); env = environment; for (PropertySource<?> propertySource1 : ((AbstractEnvironment) env).getPropertySources()) { PropertySource propertySource = (PropertySource) propertySource1; if (propertySource instanceof MapPropertySource) { boolean blnValidSource = propertySource.getName().contains("applicationConfig"); if (blnValidSource) { LOGGER.info("Found Property Source {}", propertySource.getName()); blnFoundPropertySources = true; map.putAll(((MapPropertySource) propertySource).getSource()); } } } LOGGER.trace("Finished setEnvironment"); if (blnFoundPropertySources) { readPropertySources(); } }
/** * Get Sub {@link Properties} * * @param propertySources {@link PropertySource} Iterable * @param prefix the prefix of property name * @return Map * @see Properties */ public static Map<String, Object> getSubProperties(Iterable<PropertySource<?>> propertySources, String prefix) { // Non-Extension AbstractEnvironment AbstractEnvironment environment = new AbstractEnvironment() { }; MutablePropertySources mutablePropertySources = environment.getPropertySources(); for (PropertySource<?> source : propertySources) { mutablePropertySources.addLast(source); } return getSubProperties(environment, prefix); }
/** * Get Sub {@link Properties} * * @param propertySources {@link PropertySource} Iterable * @param prefix the prefix of property name * @return Map * @see Properties */ public static Map<String, Object> getSubProperties(Iterable<PropertySource<?>> propertySources, String prefix) { // Non-Extension AbstractEnvironment AbstractEnvironment environment = new AbstractEnvironment() { }; MutablePropertySources mutablePropertySources = environment.getPropertySources(); for (PropertySource<?> source : propertySources) { mutablePropertySources.addLast(source); } return getSubProperties(environment, prefix); }
/** * Get Sub {@link Properties} * * @param propertySources {@link PropertySource} Iterable * @param prefix the prefix of property name * @return Map * @see Properties */ public static Map<String, Object> getSubProperties(Iterable<PropertySource<?>> propertySources, String prefix) { // Non-Extension AbstractEnvironment AbstractEnvironment environment = new AbstractEnvironment() { }; MutablePropertySources mutablePropertySources = environment.getPropertySources(); for (PropertySource<?> source : propertySources) { mutablePropertySources.addLast(source); } return getSubProperties(environment, prefix); }
/** * Create an environment based on <code>properties</code> */ public PropertiesEnvironment(Properties properties) { this.properties = ImmutableProperties.copyOf(properties); super.getPropertySources().addLast(new PropertiesPropertySource(NAME, properties)); }
public PropertiesEnvironment(String name, Properties properties) { this.properties = ImmutableProperties.copyOf(properties); super.getPropertySources().addLast(new PropertiesPropertySource(name, properties)); }
@Override public void handle(RoutingContext ctx) { HttpServerResponse response = ctx.response(); response.setStatusCode(HttpStatusCode.OK_200); response.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); response.setChunked(true); PropertiesPropertySource source = (PropertiesPropertySource) environment.getPropertySources().get("graviteeConfiguration"); try { TreeMap<String, Object> properties = Arrays .stream(source.getPropertyNames()) .collect(Collectors.toMap( s -> s, source::getProperty, (v1, v2) -> { throw new RuntimeException(String.format("Duplicate key for values %s and %s", v1, v2)); }, TreeMap::new)); Json.prettyMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); response.write(Json.prettyMapper.writeValueAsString(properties)); } catch (JsonProcessingException jpe) { response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR_500); LOGGER.error("Unable to transform data object to JSON", jpe); } response.end(); }
@PostConstruct public void init() { id = resolveId(); enabled = resolveEnabled(); port = resolvePort(); host = resolveHost(); if (isHTTPS()) { keyStoreFile = resolveKeyStoreFile(); keyStorePass = resolveKeyStorePass(); certPass = resolveKeyCertPass(); } for (Iterator it = ((AbstractEnvironment) env).getPropertySources().iterator(); it.hasNext(); ) { Object propertySource = it.next(); if (propertySource instanceof MapPropertySource && SpringConstants.APPLICATION_PROPERTIES.equals(((MapPropertySource) propertySource).getName())) { MapPropertySource mapPropertySource = (MapPropertySource) propertySource; for (Map.Entry<String, Object> entry : mapPropertySource.getSource().entrySet()) { String key = entry.getKey(); if (key.startsWith(getScheme()) && key.contains(SpringConstants.PARAMETER_STR)) { parameters.put(key.substring(key.indexOf(SpringConstants.PARAMETER_STR) + 11), (String) entry .getValue()); } } } } }