com.typesafe.config.ConfigException Java Examples
The following examples show how to use
com.typesafe.config.ConfigException.
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: ConfigUtils.java From envelope with Apache License 2.0 | 6 votes |
public static boolean canBeCoerced(Config config, String path, ConfigValueType type) { if (type == ConfigValueType.BOOLEAN) { try { config.getBoolean(path); } catch (ConfigException.WrongType e) { return false; } } else { // Other data type coercions could be added here in the future return false; } return true; }
Example #2
Source File: Main.java From billow with Apache License 2.0 | 6 votes |
public static void main(String[] args) { try { final Config config = ConfigFactory.load().getConfig("billow"); try { System.setProperty("aws.accessKeyId", config.getString("aws.accessKeyId")); System.setProperty("aws.secretKey", config.getString("aws.secretKeyId")); } catch (ConfigException.Missing _) { System.clearProperty("aws.accessKeyId"); System.clearProperty("aws.secretKey"); } Main.log.debug("Loaded config: {}", config); new Main(config); } catch (Throwable t) { Main.log.error("Failure in main thread, getting out!", t); System.exit(1); } }
Example #3
Source File: ConfigUtils.java From envelope with Apache License 2.0 | 6 votes |
public static Config configFromPath(String path) { File configFile = new File(path); Config config; try { config = ConfigFactory.parseFile(configFile); } catch (ConfigException.Parse e) { // The tell-tale sign is the magic bytes "PK" that is at the start of all jar files if (e.getMessage().contains("Key '\"PK")) { throw new RuntimeException(JAR_FILE_EXCEPTION_MESSAGE); } else { throw e; } } return config; }
Example #4
Source File: MorphlineTest.java From kite with Apache License 2.0 | 6 votes |
@Test public void testIsTrue() throws Exception { System.setProperty("MY_VARIABLE", "true"); morphline = createMorphline("test-morphlines/isTrue"); Record record = new Record(); record.put("isTooYoung", "true"); processAndVerifySuccess(record, record); System.setProperty("MY_VARIABLE", "false"); morphline = createMorphline("test-morphlines/isTrue"); processAndVerifyFailure(createBasicRecord()); System.clearProperty("MY_VARIABLE"); try { morphline = createMorphline("test-morphlines/isTrue"); fail(); } catch (ConfigException.UnresolvedSubstitution e) { ; } }
Example #5
Source File: ConfigsTest.java From kite with Apache License 2.0 | 6 votes |
@Test public void testDurations() throws Exception { Config config = ConfigFactory.parseString("duration : 2seconds"); Configs configs = new Configs(); assertEquals(2000, configs.getMilliseconds(config, "duration", 1000)); config = ConfigFactory.parseString("xxx : 2seconds"); assertEquals(1000, configs.getMilliseconds(config, "duration", 1000)); try { assertEquals(1000, configs.getMilliseconds(config, "duration")); fail(); } catch (ConfigException e) { ; // expected } }
Example #6
Source File: HoconProcessorTest.java From vertx-config with Apache License 2.0 | 6 votes |
@Test public void testWithTextFile(TestContext tc) { Async async = tc.async(); retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore( new ConfigStoreOptions() .setType("file") .setFormat("hocon") .setConfig(new JsonObject().put("path", "src/test/resources/some-text.txt")))); retriever.getConfig(ar -> { assertThat(ar.failed()).isTrue(); assertThat(ar.cause()).isNotNull().isInstanceOf(ConfigException.class); async.complete(); }); }
Example #7
Source File: AbstractBackgroundStreamingActorWithConfigWithStatusReport.java From ditto with Eclipse Public License 2.0 | 6 votes |
@Override public Config setConfig(final Config config) { final C previousConfig = this.config; // TODO Ditto issue #439: replace ConfigWithFallback - it breaks AbstractConfigValue.withFallback! // Workaround: re-parse my config final Config fallback = ConfigFactory.parseString(getConfig().root().render(ConfigRenderOptions.concise())); try { this.config = parseConfig(config.withFallback(fallback)); } catch (final DittoConfigError | ConfigException e) { log.error(e, "Failed to set config"); } if (!previousConfig.isEnabled() && this.config.isEnabled()) { scheduleWakeUp(); } return this.config.getConfig(); }
Example #8
Source File: Controller.java From J-Kinopoisk2IMDB with Apache License 2.0 | 6 votes |
@FXML protected void handleStartAction(ActionEvent event) { try { clientExecutor.setListeners(Arrays.asList(new ProgressBarUpdater(), new RunButtonUpdater())); clientExecutor.setConfig(configMap); clientExecutor.run(); } catch (IllegalArgumentException | NullPointerException | ConfigException e) { Alert alert = new Alert(Alert.AlertType.ERROR); alert.initModality(Modality.APPLICATION_MODAL); alert.initStyle(StageStyle.UTILITY); alert.setTitle("Ошибка"); alert.setHeaderText("Произошла ошибка"); alert.setContentText(e.getMessage()); alert.showAndWait(); } }
Example #9
Source File: RelationExtractionRunner.java From Graphene with GNU General Public License v3.0 | 6 votes |
public RelationExtractionRunner(Config config) { // load boolean values this.exploitCore = config.getBoolean("exploit-core"); this.exploitContexts = config.getBoolean("exploit-contexts"); this.separateNounBased = config.getBoolean("separate-noun-based"); this.separatePurposes = config.getBoolean("separate-purposes"); this.separateAttributions = config.getBoolean("separate-attributions"); // instantiate extractor String extractorClassName = config.getString("relation-extractor"); try { Class<?> extractorClass = Class.forName(extractorClassName); Constructor<?> extractorConst = extractorClass.getConstructor(); this.extractor = (RelationExtractor) extractorConst.newInstance(); } catch (InstantiationException | InvocationTargetException | NoSuchMethodException | IllegalAccessException | ClassNotFoundException e) { logger.error("Failed to create instance of {}", extractorClassName); throw new ConfigException.BadValue("relation-extractor." + extractorClassName, "Failed to create instance."); } this.elementCoreExtractionMap = new LinkedHashMap<>(); }
Example #10
Source File: SecretManager.java From gcp-token-broker with Apache License 2.0 | 6 votes |
/** * Download all secrets specified in the settings. */ public static void downloadSecrets() { List<? extends Config> downloads = AppSettings.getInstance().getConfigList(AppSettings.SECRET_MANAGER_DOWNLOADS); if (downloads.size() > 0) { // Download all secrets specified in the settings for (Config download : downloads) { boolean required; try { required = download.getBoolean("required"); } catch (ConfigException.Missing e) { required = true; } downloadSecret(download.getString("secret"), download.getString("file"), required); } } }
Example #11
Source File: ProxyUserValidation.java From gcp-token-broker with Apache License 2.0 | 6 votes |
private static boolean isWhitelistedByUsername(Config proxyConfig, String impersonated) { // Check if user is whitelisted directly by name List<String> proxyableUsers; try { proxyableUsers = proxyConfig.getStringList(CONFIG_USERS); } catch (ConfigException.Missing e) { // No users setting specified return false; } if (proxyableUsers.contains("*")) { // Any users can be impersonated return true; } return proxyableUsers.contains(impersonated); }
Example #12
Source File: WaveServerModule.java From swellrt with Apache License 2.0 | 5 votes |
@Inject WaveServerModule(Config config, @WaveletLoadExecutor Executor waveletLoadExecutor, @StorageContinuationExecutor Executor storageContinuationExecutor) { this.enableFederation = config.getBoolean("federation.enable_federation"); int deltaCountForPersistSnapshots = 250; try { deltaCountForPersistSnapshots = config.getInt("core.persist_snapshots_on_deltas_count"); } catch (ConfigException.Missing e) { e.printStackTrace(); } this.persistSnapshotOnDeltasCount = deltaCountForPersistSnapshots; this.waveletLoadExecutor = waveletLoadExecutor; this.storageContinuationExecutor = storageContinuationExecutor; }
Example #13
Source File: TypeSafeConfWrapper.java From parsec-libraries with Apache License 2.0 | 5 votes |
@Override public List<? extends ParsecConfig> getConfigList(String path) { try { List<TypeSafeConfWrapper> confWrappers = new ArrayList<>(); List<? extends Config> configList = configDelegate.getConfigList(path); for (Config config : configList) { TypeSafeConfWrapper conf = new TypeSafeConfWrapper(config); confWrappers.add(conf); } return confWrappers; } catch (ConfigException e) { throw new RuntimeException(e); } }
Example #14
Source File: ConfigValidatorTest.java From J-Kinopoisk2IMDB with Apache License 2.0 | 5 votes |
@Test public void checkDocumentSourceTypes() throws Exception { checkValid(parseMap(configMap)); configMap.replace("document_source_types", Collections.singletonList("not existing document_source_type")); assertThatThrownBy(() -> checkValid(parseMap(configMap))) .isInstanceOf(ConfigException.class); configMap.remove("document_source_types"); assertThatThrownBy(() -> checkValid(parseMap(configMap))) .isInstanceOf(ConfigException.class); }
Example #15
Source File: TypeSafeConfWrapper.java From parsec-libraries with Apache License 2.0 | 5 votes |
@Override public List<Duration> getDurationList(String path) { try { return configDelegate.getDurationList(path); } catch (ConfigException e) { throw new RuntimeException(e); } }
Example #16
Source File: EagleServiceClientImpl.java From eagle with Apache License 2.0 | 5 votes |
/** * Try to get eagle service port from config by key: service.port no matter STRING or INT. */ private static int tryGetPortFromConfig(Config config) { if (config.hasPath(SERVICE_PORT_KEY)) { try { return config.getInt(SERVICE_PORT_KEY); } catch (ConfigException.WrongType wrongType) { String portStr = config.getString(SERVICE_PORT_KEY); if (StringUtils.isNotBlank(portStr)) { return Integer.valueOf(portStr); } } } return 9090; }
Example #17
Source File: ConnectivityCachingSignalEnrichmentProviderTest.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Test public void loadProviderWithIncorrectConfig() { createActorSystem(CONFIG.withValue("ditto.connectivity.signal-enrichment.provider-config.ask-timeout", ConfigValueFactory.fromAnyRef("This is not a duration"))); assertThatExceptionOfType(ConfigException.class) .isThrownBy(() -> ConnectivitySignalEnrichmentProvider.get(actorSystem)); }
Example #18
Source File: ConnectivityByRoundTripSignalEnrichmentProviderTest.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Test public void loadProviderWithIncorrectConfig() { createActorSystem(withValue("ditto.connectivity.signal-enrichment.provider-config.ask-timeout", "This is not a duration")); assertThatExceptionOfType(ConfigException.class) .isThrownBy(() -> ConnectivitySignalEnrichmentProvider.get(actorSystem)); }
Example #19
Source File: InjectorBuilderTest.java From Guice-configuration with Apache License 2.0 | 5 votes |
@Test(expected = ConfigException.class) public void bind_config_with_invalid_path_must_throw_a_exception() { when(config.getConfig("path")) .thenThrow(ConfigException.BadPath.class); injectorBuilder.build(WithPath.class); }
Example #20
Source File: TypeSafeConfWrapper.java From parsec-libraries with Apache License 2.0 | 5 votes |
@Override public List<String> getStringList(String path) { try { return configDelegate.getStringList(path); } catch (ConfigException e) { throw new RuntimeException(e); } }
Example #21
Source File: DefaultScopedConfigTest.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Test public void tryToGetInstanceWithConfigWithWrongTypeAtConfigPath() { final Config config = ConfigFactory.parseMap(Collections.singletonMap(KNOWN_CONFIG_PATH, "bar")); assertThatExceptionOfType(DittoConfigError.class) .isThrownBy(() -> DefaultScopedConfig.newInstance(config, KNOWN_CONFIG_PATH)) .withMessage("Failed to get nested Config at <%s>!", KNOWN_CONFIG_PATH) .withCauseInstanceOf(ConfigException.WrongType.class); }
Example #22
Source File: DefaultScopedConfigTest.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Test public void tryToGetInstanceWithMissingConfigAtConfigPath() { final Config config = ConfigFactory.parseMap(Collections.singletonMap("foo", "bar")); assertThatExceptionOfType(DittoConfigError.class) .isThrownBy(() -> DefaultScopedConfig.newInstance(config, KNOWN_CONFIG_PATH)) .withMessage("Failed to get nested Config at <%s>!", KNOWN_CONFIG_PATH) .withCauseInstanceOf(ConfigException.Missing.class); }
Example #23
Source File: DefaultEbeanConfig.java From play-ebean with Apache License 2.0 | 5 votes |
private void addModelClassesToServerConfig(String key, ServerConfig serverConfig, Set<String> classes) { for (String clazz: classes) { try { serverConfig.addClass(Class.forName(clazz, true, environment.classLoader())); } catch (Exception e) { throw new ConfigException.BadValue( "ebean." + key, "Cannot register class [" + clazz + "] in Ebean server", e ); } } }
Example #24
Source File: TypeSafeConfWrapper.java From parsec-libraries with Apache License 2.0 | 5 votes |
@Override public long getLong(String path) { try { return configDelegate.getLong(path); } catch (ConfigException e) { throw new RuntimeException(e); } }
Example #25
Source File: DefaultScopedConfig.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Override public List<Duration> getDurationList(final String path) { try { return config.getDurationList(path); } catch (final ConfigException.Missing | ConfigException.WrongType e) { final String msgPattern = "Failed to get List of Durations for path <{0}>!"; throw new DittoConfigError(MessageFormat.format(msgPattern, appendToConfigPath(path)), e); } }
Example #26
Source File: DefaultScopedConfig.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Override public List<Long> getDurationList(final String path, final TimeUnit unit) { try { return config.getDurationList(path, unit); } catch (final ConfigException.Missing | ConfigException.WrongType e) { final String msgPattern = "Failed to get List of duration long values for path <{0}>!"; throw new DittoConfigError(MessageFormat.format(msgPattern, appendToConfigPath(path)), e); } }
Example #27
Source File: DefaultScopedConfig.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Override public List<ConfigMemorySize> getMemorySizeList(final String path) { try { return config.getMemorySizeList(path); } catch (final ConfigException.Missing | ConfigException.WrongType e) { final String msgPattern = "Failed to get List of memory sizes for path <{0}>!"; throw new DittoConfigError(MessageFormat.format(msgPattern, appendToConfigPath(path)), e); } }
Example #28
Source File: DefaultScopedConfig.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Override public List<Long> getBytesList(final String path) { try { return config.getBytesList(path); } catch (final ConfigException.Missing | ConfigException.WrongType e) { final String msgPattern = "Failed to get List of byte sizes for path <{0}>!"; throw new DittoConfigError(MessageFormat.format(msgPattern, appendToConfigPath(path)), e); } }
Example #29
Source File: DefaultScopedConfig.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Override public List<? extends Object> getAnyRefList(final String path) { try { return config.getAnyRefList(path); } catch (final ConfigException.Missing | ConfigException.WrongType e) { final String msgPattern = "Failed to get List with elements of any kind for path <{0}>!"; throw new DittoConfigError(MessageFormat.format(msgPattern, appendToConfigPath(path)), e); } }
Example #30
Source File: DefaultScopedConfig.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Override public List<? extends Config> getConfigList(final String path) { try { return config.getConfigList(path); } catch (final ConfigException.Missing | ConfigException.WrongType e) { final String msgPattern = "Failed to get List of Configs for path <{0}>!"; throw new DittoConfigError(MessageFormat.format(msgPattern, appendToConfigPath(path)), e); } }