本文整理汇总了Java中io.dropwizard.configuration.ConfigurationFactory.build方法的典型用法代码示例。如果您正苦于以下问题:Java ConfigurationFactory.build方法的具体用法?Java ConfigurationFactory.build怎么用?Java ConfigurationFactory.build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.dropwizard.configuration.ConfigurationFactory
的用法示例。
在下文中一共展示了ConfigurationFactory.build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConfiguration
import io.dropwizard.configuration.ConfigurationFactory; //导入方法依赖的package包/类
@Override
public RestlerConfig getConfiguration() {
ObjectMapper objectMapper = Jackson.newObjectMapper();
ValidatorFactory validatorFactory = Validation
.byProvider(HibernateValidator.class)
.configure()
.addValidatedValueHandler(new OptionalValidatedValueUnwrapper())
.buildValidatorFactory();
final ConfigurationFactory<RestlerConfig> configurationFactory =
new DefaultConfigurationFactoryFactory<RestlerConfig>().create(RestlerConfig.class, validatorFactory.getValidator(), objectMapper, "dw");
try {
return configurationFactory.build(new FileConfigurationSourceProvider(), TEST_CONFIG_FILE);
} catch (Exception e) {
throw new RuntimeException("Cannot get test configuration", e);
}
}
示例2: testParsing
import io.dropwizard.configuration.ConfigurationFactory; //导入方法依赖的package包/类
@Test
public void testParsing() throws Exception {
ConfigurationFactory<MacroBaseConf> cfFactory = new ConfigurationFactory<>(MacroBaseConf.class,
null,
Jackson.newObjectMapper(),
"");
MacroBaseConf conf = cfFactory.build(new File("src/test/resources/conf/simple.yaml"));
assertEquals((Double) 0.1, conf.getDouble("this.is.a.double"));
assertEquals((Integer) 100, conf.getInt("this.is.an.integer"));
assertEquals((Long) 10000000000000L, conf.getLong("this.is.a.long"));
assertEquals("Test", conf.getString("this.is.a.string"));
List<String> stringList = Lists.newArrayList("T1", "T2", "T3", "T4");
assertArrayEquals(stringList.toArray(), conf.getStringList("this.is.a.stringList").toArray());
assertArrayEquals(stringList.toArray(), conf.getStringList("this.is.a.stringList.without.spaces").toArray());
assertArrayEquals(stringList.toArray(), conf.getStringList("this.is.a.stringList.with.mixed.spaces").toArray());
}
示例3: createConfiguration
import io.dropwizard.configuration.ConfigurationFactory; //导入方法依赖的package包/类
public static OregamiConfiguration createConfiguration(String configFilename) {
ConfigurationFactory<OregamiConfiguration> factory =
new ConfigurationFactory<>(
OregamiConfiguration.class,
Validation.buildDefaultValidatorFactory().getValidator(),
Jackson.newObjectMapper(),
""
);
OregamiConfiguration configuration;
try {
configuration = factory.build(new File(configFilename));
} catch (Exception e) {
throw new RuntimeException(e);
}
System.out.println(ToStringBuilder.reflectionToString(configuration, ToStringStyle.MULTI_LINE_STYLE));
System.out.println(ToStringBuilder.reflectionToString(configuration.getDatabaseConfiguration(), ToStringStyle.MULTI_LINE_STYLE));
return configuration;
}
示例4: loadSupportedMsaVersions
import io.dropwizard.configuration.ConfigurationFactory; //导入方法依赖的package包/类
public SupportedMsaVersions loadSupportedMsaVersions(final URL url) {
final ConfigurationFactory<SupportedMsaVersions> factory = supportedMsaVersionsFactoryFactory.create(
SupportedMsaVersions.class,
buildDefaultValidatorFactory().getValidator(),
objectMapper,
"");
try {
SupportedMsaVersions supportedMsaVersions = factory.build(
configurationSourceProvider,
url.toString());
return supportedMsaVersions;
} catch (IOException | ConfigurationException e) {
throw propagate(e);
}
}
示例5: loadConfigFile
import io.dropwizard.configuration.ConfigurationFactory; //导入方法依赖的package包/类
private EmoConfiguration loadConfigFile(File configFile)
throws IOException, ConfigurationException {
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
ObjectMapper mapper = CustomJsonObjectMapperFactory.build(new YAMLFactory());
ConfigurationFactory<EmoConfiguration> configurationFactory = new ConfigurationFactory(EmoConfiguration.class, validator, mapper, "dw");
return configurationFactory.build(configFile);
}
示例6: getConfigurationFromResource
import io.dropwizard.configuration.ConfigurationFactory; //导入方法依赖的package包/类
protected EmoConfiguration getConfigurationFromResource() throws Exception {
URL url = BaseRoleConnectHelper.class.getResource(_configFileResource);
Preconditions.checkNotNull(url, _configFileResource);
File file = new File (url.toURI());
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
ObjectMapper mapper = CustomJsonObjectMapperFactory.build(new YAMLFactory());
ConfigurationFactory<EmoConfiguration> configFactory = new ConfigurationFactory<>(EmoConfiguration.class, validator, mapper, "dw");
return configFactory.build(file);
}
示例7: ensureSdkDefaultConfigDeserialization
import io.dropwizard.configuration.ConfigurationFactory; //导入方法依赖的package包/类
@Test
public void ensureSdkDefaultConfigDeserialization()
throws IOException, URISyntaxException, ConfigurationException {
// This test makes sure that we haven't forgotten to update the emodb sdk default config file when we add/remove properties
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
ObjectMapper mapper = CustomJsonObjectMapperFactory.build(new YAMLFactory());
ConfigurationFactory configurationFactory = new ConfigurationFactory(EmoConfiguration.class, validator, mapper, "dw");
// Make sure that our config files are up to date
configurationFactory.build(
new File(EmoStartMojo.class.getResource("/emodb-default-config.yaml").toURI()));
}
示例8: parse
import io.dropwizard.configuration.ConfigurationFactory; //导入方法依赖的package包/类
/**
* Parses the given configuration file and returns a configuration object.
*
* @param configurationFileName The name of the configuration file.
* @return A configuration object.
* @throws IOException The IO error that contains detail information.
* @throws ConfigurationException The configuration error that contains detail information.
*/
public static ApiConfiguration parse(String configurationFileName)
throws IOException, ConfigurationException {
if (StringUtils.isBlank(configurationFileName)) {
throw new IllegalArgumentException("Configuration file cannot be blank");
}
ObjectMapper objectMapper = null;
if (configurationFileName.endsWith("yml") || configurationFileName.endsWith("yaml")) {
objectMapper = Jackson.newObjectMapper(new YAMLFactory());
} else if (configurationFileName.endsWith("json")) {
objectMapper = Jackson.newObjectMapper(new JsonFactory());
} else {
throw new IllegalArgumentException("Unrecognized configuration file type");
}
ValidatorFactory validatorFactory = Validation
.byProvider(HibernateValidator.class)
.configure()
.addValidatedValueHandler(new OptionalValidatedValueUnwrapper())
.buildValidatorFactory();
final ConfigurationFactory<ApiConfiguration> configurationFactory =
new DefaultConfigurationFactoryFactory<ApiConfiguration>()
.create(ApiConfiguration.class, validatorFactory.getValidator(), objectMapper, "dw");
final File file = new File(configurationFileName);
if (!file.exists()) {
throw new FileNotFoundException("Configuration file " + configurationFileName + " not found");
}
return configurationFactory.build(file);
}
示例9: testViaDW
import io.dropwizard.configuration.ConfigurationFactory; //导入方法依赖的package包/类
@Test
public void testViaDW() throws Exception
{
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
ObjectMapper objectMapper = Jackson.newObjectMapper();
ConfigurationFactory<MyConfiguration> configurationFactory = new DefaultConfigurationFactoryFactory<MyConfiguration>().create(MyConfiguration.class, validator, objectMapper, "dw");
MyConfiguration configuration = configurationFactory.build(new FlexibleConfigurationSourceProvider(), "%{\"testValue\": \"override\"}");
Assert.assertEquals("override", configuration.testValue);
}
示例10: verifyConfigurable
import io.dropwizard.configuration.ConfigurationFactory; //导入方法依赖的package包/类
@Test
public void verifyConfigurable() throws Exception {
ObjectMapper mapper = Jackson.newObjectMapper();
// dropwizard 0.9.1 changed the validation wiring a bit..
Class<ValidatedValueUnwrapper> optValidatorClazz = (Class<ValidatedValueUnwrapper>) Class
.forName("io.dropwizard.validation.valuehandling.OptionalValidatedValueUnwrapper");
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
if (optValidatorClazz != null) {
validator = Validation.byProvider(HibernateValidator.class).configure()
.addValidatedValueHandler(optValidatorClazz.newInstance())
.buildValidatorFactory().getValidator();
}
ConfigurationFactory<CloudWatchReporterFactory> configFactory =
new ConfigurationFactory<>(CloudWatchReporterFactory.class,
validator, mapper, "dw");
CloudWatchReporterFactory f = configFactory.build(new File(Resources.getResource("cw.yml").getFile()));
assertEquals("[env=default]", f.getGlobalDimensions().toString());
assertEquals("us-east-1", f.getAwsRegion());
assertEquals("a.b", f.getNamespace());
assertEquals("XXXXX", f.getAwsSecretKey());
assertEquals("11111", f.getAwsAccessKeyId());
assertEquals("p.neustar.biz", f.getAwsClientConfiguration().getProxyHost());
assertNull(f.getAwsClientConfiguration().getProxyUsername());
}
示例11: createConfiguration
import io.dropwizard.configuration.ConfigurationFactory; //导入方法依赖的package包/类
public static PersistenceConfig createConfiguration(File configFile) {
ConfigurationFactory<PersistenceConfig> factory =
new ConfigurationFactory<>(PersistenceConfig.class,
Validation.buildDefaultValidatorFactory().getValidator(), Jackson.newObjectMapper(),
"");
PersistenceConfig configuration;
try {
configuration = factory.build(configFile);
} catch (Exception e) {
throw new RuntimeException(e);
}
return configuration;
}
示例12: getConfiguration
import io.dropwizard.configuration.ConfigurationFactory; //导入方法依赖的package包/类
/**
* Returns a configuration object read in from the {@code fileName}.
*/
protected <T extends Configuration> T getConfiguration(String filename,
Class<T> configurationClass) throws Exception {
final ConfigurationFactory<T> configurationFactory = new ConfigurationFactory<>(
configurationClass, validator, objectMapper, "dw");
if (filename != null) {
final File file = new File(Resources.getResource(filename).getFile());
if (!file.exists())
throw new FileNotFoundException("File " + file + " not found");
return configurationFactory.build(file);
}
return configurationFactory.build();
}
示例13: beforeEach
import io.dropwizard.configuration.ConfigurationFactory; //导入方法依赖的package包/类
@Before
public void beforeEach() throws Exception {
server = new TestingServer();
server.start();
final ConfigurationFactory<MutableSchedulerConfiguration> factory =
new ConfigurationFactory<>(
MutableSchedulerConfiguration.class,
BaseValidator.newValidator(),
Jackson.newObjectMapper().registerModule(
new GuavaModule())
.registerModule(new Jdk8Module()),
"dw");
config = factory.build(
new SubstitutingSourceProvider(
new FileConfigurationSourceProvider(),
new EnvironmentVariableSubstitutor(false, true)),
Resources.getResource("scheduler.yml").getFile());
ServiceConfig initial = config.createConfig().getServiceConfig();
final CassandraSchedulerConfiguration targetConfig = config.createConfig();
clusterTaskConfig = targetConfig.getClusterTaskConfig();
final CuratorFrameworkConfig curatorConfig = config.getCuratorConfig();
RetryPolicy retryPolicy =
(curatorConfig.getOperationTimeout().isPresent()) ?
new RetryUntilElapsed(
curatorConfig.getOperationTimeoutMs()
.get()
.intValue()
, (int) curatorConfig.getBackoffMs()) :
new RetryForever((int) curatorConfig.getBackoffMs());
stateStore = new CuratorStateStore(
targetConfig.getServiceConfig().getName(),
server.getConnectString(),
retryPolicy);
stateStore.storeFrameworkId(Protos.FrameworkID.newBuilder().setValue("1234").build());
identity = new IdentityManager(
initial,stateStore);
identity.register("test_id");
DefaultConfigurationManager configurationManager =
new DefaultConfigurationManager(CassandraSchedulerConfiguration.class,
config.createConfig().getServiceConfig().getName(),
server.getConnectString(),
config.createConfig(),
new ConfigValidator(),
stateStore);
Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
when(mockCapabilities.supportsNamedVips()).thenReturn(true);
configuration = new ConfigurationManager(
new CassandraDaemonTask.Factory(mockCapabilities),
configurationManager);
cassandraState = new CassandraState(
configuration,
clusterTaskConfig,
stateStore);
}
示例14: beforeAll
import io.dropwizard.configuration.ConfigurationFactory; //导入方法依赖的package包/类
@BeforeClass
public static void beforeAll() throws Exception {
server = new TestingServer();
server.start();
final ConfigurationFactory<MutableSchedulerConfiguration> factory =
new ConfigurationFactory<>(
MutableSchedulerConfiguration.class,
BaseValidator.newValidator(),
Jackson.newObjectMapper().registerModule(
new GuavaModule())
.registerModule(new Jdk8Module()),
"dw");
config = factory.build(
new SubstitutingSourceProvider(
new FileConfigurationSourceProvider(),
new EnvironmentVariableSubstitutor(false, true)),
Resources.getResource("scheduler.yml").getFile());
final CuratorFrameworkConfig curatorConfig = config.getCuratorConfig();
RetryPolicy retryPolicy =
(curatorConfig.getOperationTimeout().isPresent()) ?
new RetryUntilElapsed(
curatorConfig.getOperationTimeoutMs()
.get()
.intValue()
, (int) curatorConfig.getBackoffMs()) :
new RetryForever((int) curatorConfig.getBackoffMs());
stateStore = new CuratorStateStore(
config.createConfig().getServiceConfig().getName(),
server.getConnectString(),
retryPolicy);
final CassandraSchedulerConfiguration configuration = config.createConfig();
try {
final ConfigValidator configValidator = new ConfigValidator();
final DefaultConfigurationManager defaultConfigurationManager =
new DefaultConfigurationManager(CassandraSchedulerConfiguration.class,
configuration.getServiceConfig().getName(),
server.getConnectString(),
configuration,
configValidator,
stateStore);
Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
when(mockCapabilities.supportsNamedVips()).thenReturn(true);
configurationManager = new ConfigurationManager(
new CassandraDaemonTask.Factory(mockCapabilities),
defaultConfigurationManager);
} catch (ConfigStoreException e) {
throw new RuntimeException(e);
}
}
示例15: beforeAll
import io.dropwizard.configuration.ConfigurationFactory; //导入方法依赖的package包/类
@BeforeClass
public static void beforeAll() throws Exception {
server = new TestingServer();
server.start();
final ConfigurationFactory<MutableSchedulerConfiguration> factory =
new ConfigurationFactory<>(
MutableSchedulerConfiguration.class,
BaseValidator.newValidator(),
Jackson.newObjectMapper().registerModule(
new GuavaModule())
.registerModule(new Jdk8Module()),
"dw");
MutableSchedulerConfiguration mutable = factory.build(
new SubstitutingSourceProvider(
new FileConfigurationSourceProvider(),
new EnvironmentVariableSubstitutor(false, true)),
Resources.getResource("scheduler.yml").getFile());
config = mutable.createConfig();
final CuratorFrameworkConfig curatorConfig = mutable.getCuratorConfig();
RetryPolicy retryPolicy =
(curatorConfig.getOperationTimeout().isPresent()) ?
new RetryUntilElapsed(
curatorConfig.getOperationTimeoutMs()
.get()
.intValue()
, (int) curatorConfig.getBackoffMs()) :
new RetryForever((int) curatorConfig.getBackoffMs());
StateStore stateStore = new CuratorStateStore(
config.getServiceConfig().getName(),
server.getConnectString(),
retryPolicy);
configurationManager =
new DefaultConfigurationManager(CassandraSchedulerConfiguration.class,
config.getServiceConfig().getName(),
server.getConnectString(),
config,
new ConfigValidator(),
stateStore);
config = (CassandraSchedulerConfiguration) configurationManager.getTargetConfig();
}