com.typesafe.config.ConfigList Java Examples

The following examples show how to use com.typesafe.config.ConfigList. 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: VcapServicesStringParser.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
private static ConfigObject getAsConfigObject(final ConfigList configList) {
    final Map<String, ConfigValue> flattenedConfigValues = new HashMap<>(configList.size());

    for (int i = 0; i < configList.size(); i++) {
        final ConfigValue configValue = configList.get(i);
        final String configPath;
        if (ConfigValueType.OBJECT == configValue.valueType()) {
            configPath = getName((ConfigObject) configValue);
        } else {
            configPath = String.valueOf(i);
        }
        flattenedConfigValues.put(configPath, configValue);
    }

    return ConfigValueFactory.fromMap(flattenedConfigValues);
}
 
Example #2
Source File: FlattenJsonBolt.java    From cognition with Apache License 2.0 6 votes vote down vote up
void parseJson(String jsonString, LogRecord logRecord) {
  String cleanedJsonString = IngestUtilities.removeUnprintableCharacters(jsonString);
  Config cfg = ConfigFactory.parseString(cleanedJsonString);
  for (Map.Entry<String, ConfigValue> entry : cfg.entrySet()) {
    String key = entry.getKey();
    ConfigValue value = entry.getValue();
    switch (value.valueType()) {
      case BOOLEAN:
      case NUMBER:
      case OBJECT:
      case STRING:
        logRecord.setValue(key, ObjectUtils.toString(value.unwrapped()));
        break;
      case LIST:
        ConfigList list = (ConfigList) value;
        Gson gson = new Gson();
        String json = gson.toJson(list.unwrapped());
        logRecord.setValue(key, json);
        break;
      case NULL:
      default:
        // skip
    }
  }
}
 
Example #3
Source File: Runner.java    From envelope with Apache License 2.0 5 votes vote down vote up
void initializeUDFs(Config config) {
  if (!config.hasPath(UDFS_SECTION_CONFIG)) return;

  ConfigList udfList = config.getList(UDFS_SECTION_CONFIG);

  for (ConfigValue udfValue : udfList) {
    ConfigValueType udfValueType = udfValue.valueType();
    if (!udfValueType.equals(ConfigValueType.OBJECT)) {
      throw new RuntimeException("UDF list must contain UDF objects");
    }

    Config udfConfig = ((ConfigObject)udfValue).toConfig();

    for (String path : Lists.newArrayList(UDFS_NAME, UDFS_CLASS)) {
      if (!udfConfig.hasPath(path)) {
        throw new RuntimeException("UDF entries must provide '" + path + "'");
      }
    }

    String name = udfConfig.getString(UDFS_NAME);
    String className = udfConfig.getString(UDFS_CLASS);

    // null third argument means that registerJava will infer the return type
    Contexts.getSparkSession().udf().registerJava(name, className, null);

    LOG.info("Registered Spark SQL UDF: " + name);
  }
}
 
Example #4
Source File: HoconNodeCursor.java    From jackson-dataformat-hocon with Apache License 2.0 5 votes vote down vote up
@Override
public boolean currentHasChildren() {
	if(currentNode() instanceof ConfigList) {
		return !((ConfigList)currentNode()).isEmpty();
	} else if (currentNode() instanceof ConfigObject) {
		return !((ConfigObject)currentNode()).isEmpty();
	} else {
		return false;
	}
}
 
Example #5
Source File: HoconNodeCursor.java    From jackson-dataformat-hocon with Apache License 2.0 5 votes vote down vote up
@Override
public boolean currentHasChildren() {
    if(currentNode() instanceof ConfigList) {
        return !((ConfigList)currentNode()).isEmpty();
    } else if (currentNode() instanceof ConfigObject) {
        return !((ConfigObject)currentNode()).isEmpty();
    } else {
        return false;
    }
}
 
Example #6
Source File: HoconNodeCursor.java    From jackson-dataformat-hocon with Apache License 2.0 5 votes vote down vote up
@Override
public boolean currentHasChildren() {
	if(currentNode() instanceof ConfigList) {
		return !((ConfigList)currentNode()).isEmpty();
	} else if (currentNode() instanceof ConfigObject) {
		return !((ConfigObject)currentNode()).isEmpty();
	} else {
		return false;
	}
}
 
Example #7
Source File: IgnoredRequestMatcher.java    From para with Apache License 2.0 5 votes vote down vote up
private IgnoredRequestMatcher() {
	ConfigList c = Config.getConfig().getList("security.ignored");
	List<RequestMatcher> list = new ArrayList<>(c.size());
	for (ConfigValue configValue : c) {
		list.add(new AntPathRequestMatcher((String) configValue.unwrapped()));
	}
	orMatcher = new OrRequestMatcher(list);
}
 
Example #8
Source File: SecurityConfig.java    From para with Apache License 2.0 5 votes vote down vote up
private void parseProtectedResources(HttpSecurity http, ConfigObject protectedResources) throws Exception {
	for (ConfigValue cv : protectedResources.values()) {
		LinkedList<String> patterns = new LinkedList<>();
		LinkedList<String> roles = new LinkedList<>();
		HashSet<HttpMethod> methods = new HashSet<>();

		for (ConfigValue configValue : (ConfigList) cv) {
			try {
				if (configValue instanceof ConfigList) {
					for (ConfigValue role : (ConfigList) configValue) {
						String r = ((String) role.unwrapped()).toUpperCase().trim();
						// check if any HTTP methods appear here
						HttpMethod m = HttpMethod.resolve(r);
						if (m != null) {
							methods.add(m);
						} else {
							roles.add(r);
						}
					}
				} else {
					patterns.add((String) configValue.unwrapped());
				}
			} catch (Exception e) {
				logger.error("Invalid config syntax for protected resource: {}.", configValue.render(), e);
			}
		}
		String[] rolz = (roles.isEmpty()) ? DEFAULT_ROLES : roles.toArray(new String[0]);
		String[] patternz = patterns.toArray(new String[0]);
		if (methods.isEmpty()) {
			http.authorizeRequests().antMatchers(patternz).hasAnyRole(rolz);
		} else {
			for (HttpMethod method : methods) {
				http.authorizeRequests().antMatchers(method, patternz).hasAnyRole(rolz);
			}
		}
	}
}
 
Example #9
Source File: TemporaryJobs.java    From helios with Apache License 2.0 5 votes vote down vote up
private static List<String> getListByKey(final String key, final Config config) {
  final ConfigList endpointList = config.getList(key);
  final List<String> stringList = Lists.newArrayList();
  for (final ConfigValue v : endpointList) {
    if (v.valueType() != ConfigValueType.STRING) {
      throw new RuntimeException("Item in " + key + " list [" + v + "] is not a string");
    }
    stringList.add((String) v.unwrapped());
  }
  return stringList;
}
 
Example #10
Source File: ConfigBeanImpl.java    From mpush with Apache License 2.0 5 votes vote down vote up
private static ConfigValueType getValueTypeOrNull(Class<?> parameterClass) {
    if (parameterClass == Boolean.class || parameterClass == boolean.class) {
        return ConfigValueType.BOOLEAN;
    } else if (parameterClass == Integer.class || parameterClass == int.class) {
        return ConfigValueType.NUMBER;
    } else if (parameterClass == Double.class || parameterClass == double.class) {
        return ConfigValueType.NUMBER;
    } else if (parameterClass == Long.class || parameterClass == long.class) {
        return ConfigValueType.NUMBER;
    } else if (parameterClass == String.class) {
        return ConfigValueType.STRING;
    } else if (parameterClass == Duration.class) {
        return null;
    } else if (parameterClass == ConfigMemorySize.class) {
        return null;
    } else if (parameterClass == List.class) {
        return ConfigValueType.LIST;
    } else if (parameterClass == Map.class) {
        return ConfigValueType.OBJECT;
    } else if (parameterClass == Config.class) {
        return ConfigValueType.OBJECT;
    } else if (parameterClass == ConfigObject.class) {
        return ConfigValueType.OBJECT;
    } else if (parameterClass == ConfigList.class) {
        return ConfigValueType.LIST;
    } else {
        return null;
    }
}
 
Example #11
Source File: DefaultScopedConfig.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ConfigList getList(final String path) {
    try {
        return config.getList(path);
    } catch (final ConfigException.Missing | ConfigException.WrongType e) {
        final String msgPattern = "Failed to get ConfigList for path <{0}>!";
        throw new DittoConfigError(MessageFormat.format(msgPattern, appendToConfigPath(path)), e);
    }
}
 
Example #12
Source File: NestedConfig.java    From Bats with Apache License 2.0 4 votes vote down vote up
@Override
public ConfigList getList(String path) {
  return c.getList(path);
}
 
Example #13
Source File: ConfigBeanImpl.java    From mpush with Apache License 2.0 4 votes vote down vote up
private static Object getValue(Class<?> beanClass, Type parameterType, Class<?> parameterClass, Config config,
                               String configPropName) {
    if (parameterClass == Boolean.class || parameterClass == boolean.class) {
        return config.getBoolean(configPropName);
    } else if (parameterClass == Integer.class || parameterClass == int.class) {
        return config.getInt(configPropName);
    } else if (parameterClass == Double.class || parameterClass == double.class) {
        return config.getDouble(configPropName);
    } else if (parameterClass == Long.class || parameterClass == long.class) {
        return config.getLong(configPropName);
    } else if (parameterClass == String.class) {
        return config.getString(configPropName);
    } else if (parameterClass == Duration.class) {
        return config.getDuration(configPropName);
    } else if (parameterClass == ConfigMemorySize.class) {
        return config.getMemorySize(configPropName);
    } else if (parameterClass == Object.class) {
        return config.getAnyRef(configPropName);
    } else if (parameterClass == List.class) {
        return getListValue(beanClass, parameterType, parameterClass, config, configPropName);
    } else if (parameterClass == Map.class) {
        // we could do better here, but right now we don't.
        Type[] typeArgs = ((ParameterizedType) parameterType).getActualTypeArguments();
        if (typeArgs[0] != String.class || typeArgs[1] != Object.class) {
            throw new ConfigException.BadBean("Bean property '" + configPropName + "' of class " + beanClass.getName() + " has unsupported Map<" + typeArgs[0] + "," + typeArgs[1] + ">, only Map<String,Object> is supported right now");
        }
        return config.getObject(configPropName).unwrapped();
    } else if (parameterClass == Config.class) {
        return config.getConfig(configPropName);
    } else if (parameterClass == ConfigObject.class) {
        return config.getObject(configPropName);
    } else if (parameterClass == ConfigValue.class) {
        return config.getValue(configPropName);
    } else if (parameterClass == ConfigList.class) {
        return config.getList(configPropName);
    } else if (hasAtLeastOneBeanProperty(parameterClass)) {
        return createInternal(config.getConfig(configPropName), parameterClass);
    } else {
        throw new ConfigException.BadBean("Bean property " + configPropName + " of class " + beanClass.getName() + " has unsupported type " + parameterType);
    }
}
 
Example #14
Source File: NestedConfig.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public ConfigList getList(String path) {
  return config.getList(path);
}
 
Example #15
Source File: VcapServicesStringParser.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
private static ConfigValue convertConfigListToConfigObject(final ConfigValue configValue) {
    if (ConfigValueType.LIST == configValue.valueType()) {
        return getAsConfigObject((ConfigList) configValue);
    }
    return configValue;
}
 
Example #16
Source File: HoconNodeCursor.java    From jackson-dataformat-hocon with Apache License 2.0 4 votes vote down vote up
public Array(ConfigValue n, HoconNodeCursor p) {
    super(JsonStreamContext.TYPE_ARRAY, p);
    _contents = ((ConfigList)n).iterator();
}
 
Example #17
Source File: ConfigWithFallback.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public ConfigList getList(final String path) {
    return baseConfig.getList(path);
}
 
Example #18
Source File: DittoServiceConfig.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public ConfigList getList(final String path) {
    return serviceScopedConfig.getList(path);
}