io.dropwizard.configuration.ConfigurationValidationException Java Examples
The following examples show how to use
io.dropwizard.configuration.ConfigurationValidationException.
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: CreateKeyspacesCommand.java From emodb with Apache License 2.0 | 5 votes |
public static DdlConfiguration parseDdlConfiguration(File file) throws IOException, ConfigurationException { // Similar to Dropwizard's ConfigurationFactory but ignores System property overrides. ObjectMapper mapper = EmoServiceObjectMapperFactory.build(new YAMLFactory()); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true); DdlConfiguration ddlConfiguration = mapper.readValue(file, DdlConfiguration.class); Set<ConstraintViolation<DdlConfiguration>> errors = _validator.validate(ddlConfiguration); if (!errors.isEmpty()) { throw new ConfigurationValidationException(file.toString(), errors); } return ddlConfiguration; }
Example #2
Source File: SingularityRunnerConfigurationProvider.java From Singularity with Apache License 2.0 | 5 votes |
@Override public T get() { final Configuration configuration = clazz.getAnnotation(Configuration.class); try { final File baseFile = new File(configuration.filename()); final T baseConfig = baseFile.exists() ? objectMapper.readValue(baseFile, clazz) : clazz.newInstance(); final JsonNode overrideNode = filename.isPresent() ? loadYamlField(filename.get(), configuration.consolidatedField()) : objectMapper.createObjectNode(); final T config = objectMapper.readerForUpdating(baseConfig).readValue(overrideNode); final Set<ConstraintViolation<T>> violations = validator.validate(config); if (!violations.isEmpty()) { throw new ConfigurationValidationException( filename.orElse(configuration.filename()), violations ); } return config; } catch (Exception e) { throw new RuntimeException(e); } }