use of com.typesafe.config.ConfigException in project oap by oaplatform.
the class HoconFactoryWithFallback method _createParser.
@Override
protected HoconTreeTraversingParser _createParser(Reader r, IOContext ctxt) throws IOException {
ConfigParseOptions options = ConfigParseOptions.defaults();
Config config = ConfigFactory.parseReader(r, options);
final Config unresolvedConfig = additinal.withFallback(config).withFallback(ConfigFactory.systemProperties());
try {
Config resolvedConfig = unresolvedConfig.resolve();
return new HoconTreeTraversingParser(resolvedConfig.root(), _objectCodec);
} catch (ConfigException e) {
log.error(unresolvedConfig.root().render());
throw e;
}
}
use of com.typesafe.config.ConfigException in project oap by oaplatform.
the class HoconFactoryWithSystemProperties method _createParser.
@Override
protected HoconTreeTraversingParser _createParser(Reader r, IOContext ctxt) throws IOException {
final ConfigParseOptions options = ConfigParseOptions.defaults();
final Config config = ConfigFactory.parseReader(r, options);
final Config unresolvedConfig = config.withFallback(ConfigFactory.systemProperties());
// log.trace( unresolvedConfig.root().render() );
try {
final Config resolvedConfig = unresolvedConfig.resolve();
return new HoconTreeTraversingParser(resolvedConfig.root(), _objectCodec);
} catch (ConfigException e) {
log.error(unresolvedConfig.root().render());
throw e;
}
}
use of com.typesafe.config.ConfigException in project config by typesafehub.
the class SimpleConfig method parsePeriod.
/**
* Parses a period string. If no units are specified in the string, it is
* assumed to be in days. The returned period is in days.
* The purpose of this function is to implement the period-related methods
* in the ConfigObject interface.
*
* @param input
* the string to parse
* @param originForException
* origin of the value being parsed
* @param pathForException
* path to include in exceptions
* @return duration in days
* @throws ConfigException
* if string is invalid
*/
public static Period parsePeriod(String input, ConfigOrigin originForException, String pathForException) {
String s = ConfigImplUtil.unicodeTrim(input);
String originalUnitString = getUnits(s);
String unitString = originalUnitString;
String numberString = ConfigImplUtil.unicodeTrim(s.substring(0, s.length() - unitString.length()));
ChronoUnit units;
// is more helpful if we check it here.
if (numberString.length() == 0)
throw new ConfigException.BadValue(originForException, pathForException, "No number in period value '" + input + "'");
if (unitString.length() > 2 && !unitString.endsWith("s"))
unitString = unitString + "s";
// note that this is deliberately case-sensitive
if (unitString.equals("") || unitString.equals("d") || unitString.equals("days")) {
units = ChronoUnit.DAYS;
} else if (unitString.equals("w") || unitString.equals("weeks")) {
units = ChronoUnit.WEEKS;
} else if (unitString.equals("m") || unitString.equals("mo") || unitString.equals("months")) {
units = ChronoUnit.MONTHS;
} else if (unitString.equals("y") || unitString.equals("years")) {
units = ChronoUnit.YEARS;
} else {
throw new ConfigException.BadValue(originForException, pathForException, "Could not parse time unit '" + originalUnitString + "' (try d, w, mo, y)");
}
try {
return periodOf(Integer.parseInt(numberString), units);
} catch (NumberFormatException e) {
throw new ConfigException.BadValue(originForException, pathForException, "Could not parse duration number '" + numberString + "'");
}
}
use of com.typesafe.config.ConfigException in project incubator-gobblin by apache.
the class R2ClientFactoryTest method testHttpClient.
public void testHttpClient() {
R2ClientFactory factory = new R2ClientFactory(R2ClientFactory.Schema.HTTP);
Map<String, Object> values = new HashMap<>();
// No SSL
Client client = factory.createInstance(ConfigFactory.parseMap(values));
shutdown(client);
// With SSL
values.put(R2ClientFactory.SSL_ENABLED, true);
values.put(SSLContextFactory.KEY_STORE_FILE_PATH, "identity.p12");
values.put(SSLContextFactory.TRUST_STORE_FILE_PATH, "certs");
values.put(SSLContextFactory.KEY_STORE_PASSWORD, "keyStorePassword");
values.put(SSLContextFactory.TRUST_STORE_PASSWORD, "trustStorePassword");
values.put(SSLContextFactory.KEY_STORE_TYPE, "PKCS12");
try {
factory.createInstance(ConfigFactory.parseMap(values));
} catch (ConfigException | IllegalArgumentException e) {
Assert.fail();
} catch (Exception e) {
// OK
}
}
use of com.typesafe.config.ConfigException in project incubator-gobblin by apache.
the class R2ClientFactoryTest method testD2Client.
public void testD2Client() throws Exception {
R2ClientFactory factory = new R2ClientFactory(R2ClientFactory.Schema.D2);
TestingServer zkServer = new TestingServer(-1);
Map<String, Object> values = new HashMap<>();
values.put("d2.zkHosts", zkServer.getConnectString());
// No SSL
Client client = factory.createInstance(ConfigFactory.parseMap(values));
shutdown(client);
// With SSL
final String confPrefix = "d2.";
values.put(confPrefix + R2ClientFactory.SSL_ENABLED, true);
values.put(confPrefix + SSLContextFactory.KEY_STORE_FILE_PATH, "identity.p12");
values.put(confPrefix + SSLContextFactory.TRUST_STORE_FILE_PATH, "certs");
values.put(confPrefix + SSLContextFactory.KEY_STORE_PASSWORD, "keyStorePassword");
values.put(confPrefix + SSLContextFactory.TRUST_STORE_PASSWORD, "trustStorePassword");
values.put(confPrefix + SSLContextFactory.KEY_STORE_TYPE, "PKCS12");
try {
factory.createInstance(ConfigFactory.parseMap(values));
} catch (ConfigException | IllegalArgumentException e) {
Assert.fail("Unexpected config exception");
} catch (Exception e) {
// OK
}
zkServer.close();
}
Aggregations