gpt4 book ai didi

io.dropwizard.configuration.YamlConfigurationFactory类的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 15:12:40 26 4
gpt4 key购买 nike

本文整理了Java中io.dropwizard.configuration.YamlConfigurationFactory类的一些代码示例,展示了YamlConfigurationFactory类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YamlConfigurationFactory类的具体详情如下:
包路径:io.dropwizard.configuration.YamlConfigurationFactory
类名称:YamlConfigurationFactory

YamlConfigurationFactory介绍

[英]A factory class for loading YAML configuration files, binding them to configuration objects, and validating their constraints. Allows for overriding configuration parameters from system properties.
[中]一个工厂类,用于加载YAML配置文件,将其绑定到配置对象,并验证其约束。允许从系统属性重写配置参数。

代码示例

代码示例来源:origin: dropwizard/dropwizard

@Override
public ConfigurationFactory<T> create(
    Class<T>     klass,
    Validator    validator,
    ObjectMapper objectMapper,
    String       propertyPrefix) {
  return new YamlConfigurationFactory<>(
    klass,
    validator,
    configureObjectMapper(objectMapper.copy()),
    propertyPrefix);
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testConfigurationNamespaces1() throws Exception {
  final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  assertEquals("/tmp/trellisData/namespaces.json", config.getNamespaces(), "Incorrect namespace location!");
}

代码示例来源:origin: performancecopilot/parfait

@Before
public void setUp() throws Exception {
  objectMapper.getSubtypeResolver().registerSubtypes(
      ConsoleReporterFactory.class,
      CsvReporterFactory.class,
      Slf4jReporterFactory.class,
      ParfaitReporterFactory.class);
  this.config = factory.build(new File(getClass().getResource("metric-app.yml").toURI()));
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testGetJwksAuthenticator() throws Exception {
  final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  assertTrue(TrellisUtils.getJwtAuthenticator(config.getAuth().getJwt()) instanceof JwksAuthenticator,
      "JWT auth not enabled!");
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testGetCORSConfig() throws Exception {
  final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  assertTrue(TrellisUtils.getCorsConfiguration(config).isPresent(), "CORS configuration is missing!");
  config.getCors().setEnabled(false);
  assertFalse(TrellisUtils.getCorsConfiguration(config).isPresent(), "CORS config persists after disabling it!");
}

代码示例来源:origin: dropwizard/dropwizard

} else if (customPropertyPrefix.isPresent()) {
  bootstrap.setConfigurationFactoryFactory((klass, validator, objectMapper, propertyPrefix) ->
    new YamlConfigurationFactory<>(klass, validator, objectMapper, customPropertyPrefix.get()));

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testConfigurationLocations() throws Exception {
  final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  assertEquals("http://localhost:8080/", config.getBaseUrl(), "Incorrect baseUrl!");
  assertEquals("http://hub.example.com/", config.getHubUrl(), "Incorrect hubUrl!");
}

代码示例来源:origin: soabase/soabase

@Override
  public ConfigurationFactory<T> create(Class<T> klass, Validator validator, ObjectMapper objectMapper, String propertyPrefix)
  {
    return new YamlConfigurationFactory<>(configurationClass, validator, objectMapper, propertyPrefix);
  }
};

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testGetWebacCache() throws Exception {
  final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  assertTrue(TrellisUtils.getWebacCache(config).isPresent(), "WebAC configuration not present!");
  config.getAuth().getWebac().setEnabled(false);
  assertFalse(TrellisUtils.getWebacCache(config).isPresent(), "WebAC config persists after disabling it!");
}

代码示例来源:origin: yammer/breakerbox

public YamlInstanceDiscovery(Path path,
               Validator validator,
               ObjectMapper objectMapper) {
  this.path = path;
  this.configurationFactory = new YamlConfigurationFactory<>(
      YamlInstanceConfiguration.class,
      validator,
      objectMapper,
      "dw");
  parseYamlInstanceConfiguration();
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testGetJwtAuthenticatorNoKeystore() throws Exception {
  final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  final String nonexistent = resourceFilePath("config1.yml").replaceAll("config1.yml", "nonexistent.yml");
  config.getAuth().getJwt().setJwks(null);
  config.getAuth().getJwt().setKeyStore(nonexistent);
  assertTrue(TrellisUtils.getJwtAuthenticator(config.getAuth().getJwt()) instanceof JwtAuthenticator,
      "JWT auth not disabled!");
}

代码示例来源:origin: bazaarvoice/ostrich

private static DictionaryConfiguration loadConfigFile(String configFile)
      throws IOException, ConfigurationException {
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    ConfigurationFactory<DictionaryConfiguration> configFactory = new YamlConfigurationFactory<>(
        DictionaryConfiguration.class, validator, Jackson.newObjectMapper(), "dictionary"
    );
    if (configFile != null) {
      return configFactory.build(new File(configFile));
    } else {
      return configFactory.build();
    }
  }
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testConfigurationAssets1() throws Exception {
  final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  assertEquals("org/trellisldp/rdfa/resource.mustache", config.getAssets().getTemplate(), "Bad assets/template");
  assertEquals("http://example.com/image.icon", config.getAssets().getIcon(), "Bad assets/icon value!");
  assertTrue(config.getAssets().getJs().contains("http://example.com/scripts1.js"), "Missing assets/js value!");
  assertTrue(config.getAssets().getCss().contains("http://example.com/styles1.css"), "Missing assets/css value!");
}

代码示例来源:origin: bazaarvoice/ostrich

private static CalculatorConfiguration loadConfigFile(String configFile) throws IOException,
      ConfigurationException {
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    ConfigurationFactory<CalculatorConfiguration> configFactory = new YamlConfigurationFactory<>(
        CalculatorConfiguration.class, validator, Jackson.newObjectMapper(), "calculator"
    );
    if (configFile != null) {
      return configFactory.build(new File(configFile));
    } else {
      return configFactory.build();
    }
  }
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testConfigurationAssets1() throws Exception {
  final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  assertEquals("org/trellisldp/rdfa/resource.mustache", config.getAssets().getTemplate(), "Incorrect asset tpl!");
  assertEquals("http://example.org/image.icon", config.getAssets().getIcon(), "Incorrect asset icon!");
  assertTrue(config.getAssets().getJs().contains("http://example.org/scripts1.js"), "Incorrect asset js!");
  assertTrue(config.getAssets().getCss().contains("http://example.org/styles1.css"), "Incorrect asset css!");
}

代码示例来源:origin: io.dropwizard/dropwizard-configuration

@Override
public ConfigurationFactory<T> create(
    Class<T>     klass,
    Validator    validator,
    ObjectMapper objectMapper,
    String       propertyPrefix) {
  return new YamlConfigurationFactory<>(
    klass,
    validator,
    configureObjectMapper(objectMapper.copy()),
    propertyPrefix);
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testGetJwtAuthenticatorBadKeystore() throws Exception {
  final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  config.getAuth().getJwt().setJwks(null);
  config.getAuth().getJwt().setKeyStore(resourceFilePath("config1.yml"));
  assertTrue(TrellisUtils.getJwtAuthenticator(config.getAuth().getJwt()) instanceof JwtAuthenticator,
      "JWT auth not disabled!");
}

代码示例来源:origin: bazaarvoice/ostrich

private static CalculatorConfiguration loadConfigFile(String configFile)
      throws IOException, ConfigurationException {
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    ConfigurationFactory<CalculatorConfiguration> configFactory = new YamlConfigurationFactory<>(
        CalculatorConfiguration.class, validator, Jackson.newObjectMapper(), "calculator"
    );
    if (configFile != null) {
      return configFactory.build(new File(configFile));
    } else {
      return configFactory.build();
    }
  }
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testConfigurationLocations() throws Exception {
  final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  assertEquals("/tmp/trellisData/binaries", config.getBinaries(), "Incorrect binary location!");
  assertEquals("/tmp/trellisData/mementos", config.getMementos(), "Incorrect memento location!");
  assertEquals("http://localhost:8080/", config.getBaseUrl(), "Incorrect base URL!");
  assertEquals("http://hub.example.com/", config.getHubUrl(), "Incorrect hub URL!");
  final String resources = "http://triplestore.example.com/";
  config.setResources(resources);
  assertEquals(resources, config.getResources(), "Incorrect resource location!");
}

代码示例来源:origin: io.dropwizard/dropwizard-testing

} else if (customPropertyPrefix.isPresent()) {
  bootstrap.setConfigurationFactoryFactory((klass, validator, objectMapper, propertyPrefix) ->
    new YamlConfigurationFactory<>(klass, validator, objectMapper, customPropertyPrefix.get()));

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com