Search in sources :

Example 1 with ConfigException

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;
    }
}
Also used : HoconTreeTraversingParser(com.jasonclawson.jackson.dataformat.hocon.HoconTreeTraversingParser) Config(com.typesafe.config.Config) ConfigException(com.typesafe.config.ConfigException) ConfigParseOptions(com.typesafe.config.ConfigParseOptions)

Example 2 with ConfigException

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;
    }
}
Also used : HoconTreeTraversingParser(com.jasonclawson.jackson.dataformat.hocon.HoconTreeTraversingParser) Config(com.typesafe.config.Config) ConfigException(com.typesafe.config.ConfigException) ConfigParseOptions(com.typesafe.config.ConfigParseOptions)

Example 3 with ConfigException

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 + "'");
    }
}
Also used : ConfigException(com.typesafe.config.ConfigException) ChronoUnit(java.time.temporal.ChronoUnit)

Example 4 with ConfigException

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
    }
}
Also used : HashMap(java.util.HashMap) ConfigException(com.typesafe.config.ConfigException) Client(com.linkedin.r2.transport.common.Client) ExecutionException(java.util.concurrent.ExecutionException) ConfigException(com.typesafe.config.ConfigException)

Example 5 with ConfigException

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();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) HashMap(java.util.HashMap) ConfigException(com.typesafe.config.ConfigException) Client(com.linkedin.r2.transport.common.Client) ExecutionException(java.util.concurrent.ExecutionException) ConfigException(com.typesafe.config.ConfigException)

Aggregations

ConfigException (com.typesafe.config.ConfigException)8 HoconTreeTraversingParser (com.jasonclawson.jackson.dataformat.hocon.HoconTreeTraversingParser)2 Client (com.linkedin.r2.transport.common.Client)2 Config (com.typesafe.config.Config)2 ConfigParseOptions (com.typesafe.config.ConfigParseOptions)2 HashMap (java.util.HashMap)2 ExecutionException (java.util.concurrent.ExecutionException)2 ConfigValue (com.typesafe.config.ConfigValue)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 ChronoUnit (java.time.temporal.ChronoUnit)1 TimeUnit (java.util.concurrent.TimeUnit)1 TestingServer (org.apache.curator.test.TestingServer)1