本文整理汇总了Java中org.apache.commons.configuration.Configuration类的典型用法代码示例。如果您正苦于以下问题:Java Configuration类的具体用法?Java Configuration怎么用?Java Configuration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Configuration类属于org.apache.commons.configuration包,在下文中一共展示了Configuration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onStartup
import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
if (getPort() == 0) {
LOGGER.warn(
"spring boot embed web container listen port is 0, serviceComb will not use container's port to handler RESTful request.");
return;
}
// web container did not did listen now.
// so mock to listen, and then close.
try (ServerSocket ss = new ServerSocket(getPort(), 0, getAddress())) {
if (StringUtils.isEmpty(ServletConfig.getServletUrlPattern())) {
// ensure the servlet will be instantiated
Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
configuration.setProperty(ServletConfig.KEY_SERVLET_URL_PATTERN, ServletConfig.DEFAULT_URL_PATTERN);
}
RestServletInjector.defaultInject(servletContext);
ServletUtils.saveUrlPrefix(servletContext);
} catch (IOException e) {
throw new ServletException(e);
}
}
示例2: testOnStartup
import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
@Test
public void testOnStartup() throws Exception {
Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
String urlPattern = "/rest/*";
configuration.setProperty(ServletConfig.KEY_SERVLET_URL_PATTERN, urlPattern);
ServletContext servletContext = mock(ServletContext.class);
Dynamic dynamic = mock(Dynamic.class);
when(servletContext.addServlet(RestServletInjector.SERVLET_NAME, RestServlet.class)).thenReturn(dynamic);
RestServletInitializer restServletInitializer = new RestServletInitializer();
restServletInitializer.setPort(TEST_PORT);
restServletInitializer.onStartup(servletContext);
verify(dynamic).setAsyncSupported(true);
verify(dynamic).addMapping(urlPattern);
verify(dynamic).setLoadOnStartup(0);
}
示例3: getMicroserviceVersionFactory
import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
@Test
public void getMicroserviceVersionFactory() {
DynamicPropertyFactory.getInstance();
Configuration config = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
config.addProperty(ServiceRegistryConfig.MICROSERVICE_VERSION_FACTORY, "test");
Assert.assertEquals("test", ServiceRegistryConfig.INSTANCE.getMicroserviceVersionFactory());
config.clearProperty(ServiceRegistryConfig.MICROSERVICE_VERSION_FACTORY);
}
示例4: onBootEvent
import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
@Override
public void onBootEvent(BootEvent event) {
if (!EventType.BEFORE_PRODUCER_PROVIDER.equals(event.getEventType())) {
return;
}
String defaultExecutor = DynamicPropertyFactory.getInstance()
.getStringProperty(ExecutorManager.KEY_EXECUTORS_DEFAULT, null)
.get();
if (defaultExecutor != null) {
LOGGER.info("Edge service default executor is {}.", defaultExecutor);
return;
}
// change default to reactive mode
Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
configuration.setProperty(ExecutorManager.KEY_EXECUTORS_DEFAULT, ExecutorManager.EXECUTOR_REACTIVE);
LOGGER.info("Set ReactiveExecutor to be edge service default executor.");
}
示例5: testGetServletUrlPattern
import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
@Test
public void testGetServletUrlPattern() {
DynamicPropertyFactory.getInstance();
Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
configuration.setProperty(ServletConfig.KEY_SERVLET_URL_PATTERN, "/*");
Assert.assertEquals("/*", ServletConfig.getServletUrlPattern());
}
示例6: parseFromProperties
import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
public static MutableCollection<DbMergeInfo> parseFromProperties(Configuration config) {
Set<String> dbs = new HashSet<String>(config.getList("instances"));
MutableList<DbMergeInfo> dbMergeInfos = Lists.mutable.empty();
for (String db : dbs) {
Configuration subset = config.subset(db);
if (subset.containsKey("inputDir")) {
File inputDir = new File(subset.getString("inputDir"));
DbMergeInfo mergeInfo = new DbMergeInfo(db, inputDir);
if (subset.containsKey("driverClassName")) {
mergeInfo.setDriverClassName(subset.getString("driverClassName"));
mergeInfo.setUrl(subset.getString("url"));
mergeInfo.setUsername(subset.getString("username"));
mergeInfo.setPassword(subset.getString("password"));
mergeInfo.setPhysicalSchema(subset.getString("physicalSchema"));
}
dbMergeInfos.add(mergeInfo);
}
}
return dbMergeInfos;
}
示例7: getAsciiDocOptionsAndAttributes
import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
private Options getAsciiDocOptionsAndAttributes(ParserContext context) {
Configuration config = context.getConfig();
final AttributesBuilder attributes = attributes(config.getStringArray(Keys.ASCIIDOCTOR_ATTRIBUTES));
if (config.getBoolean(Keys.ASCIIDOCTOR_ATTRIBUTES_EXPORT, false)) {
final String prefix = config.getString( Keys.ASCIIDOCTOR_ATTRIBUTES_EXPORT_PREFIX, "");
for (final Iterator<String> it = config.getKeys(); it.hasNext();) {
final String key = it.next();
if (!key.startsWith("asciidoctor")) {
attributes.attribute(prefix + key.replace(".", "_"), config.getProperty(key));
}
}
}
final Configuration optionsSubset = config.subset(Keys.ASCIIDOCTOR_OPTION);
final Options options = options().attributes(attributes.get()).get();
for (final Iterator<String> iterator = optionsSubset.getKeys(); iterator.hasNext();) {
final String name = iterator.next();
if (name.equals(Options.TEMPLATE_DIRS)) {
options.setTemplateDirs(optionsSubset.getString(name));
} else {
options.setOption(name, guessTypeByContent(optionsSubset.getString(name)));
}
}
options.setBaseDir(context.getFile().getParentFile().getAbsolutePath());
options.setSafe(UNSAFE);
return options;
}
示例8: loadEngines
import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
/**
* This method is used internally to load markup engines. Markup engines are found using descriptor files on
* classpath, so adding an engine is as easy as adding a jar on classpath with the descriptor file included.
*/
private void loadEngines(final Configuration config, final ContentStore db, final File destination, final File templatesPath) {
try {
ClassLoader cl = TemplateEngines.class.getClassLoader();
Enumeration<URL> resources = cl.getResources("META-INF/org.jbake.parser.TemplateEngines.properties");
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
Properties props = new Properties();
props.load(url.openStream());
for (Map.Entry<Object, Object> entry : props.entrySet()) {
String className = (String) entry.getKey();
String[] extensions = ((String) entry.getValue()).split(",");
registerEngine(config, db, destination, templatesPath, className, extensions);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例9: setUp
import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
configuration.clearProperty(ServletConfig.KEY_SERVLET_URL_PATTERN);
configuration.setProperty(ServletConfig.KEY_CSE_REST_ADDRESS, LISTEN_ADDRESS);
PowerMockito.mockStatic(NetUtils.class);
PowerMockito.when(NetUtils.parseIpPortFromURI(anyString())).thenReturn(new IpPort(LISTEN_ADDRESS, TEST_PORT));
PowerMockito.when(NetUtils.canTcpListen(anyObject(), anyInt())).thenReturn(false);
}
示例10: setProperty
import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
public static void setProperty(String key, Object value) {
// ensure have instance
DynamicPropertyFactory.getInstance();
Configuration config = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
config.addProperty(key, value);
}
示例11: createConfigFromConfigCenter
import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
public static DynamicWatchedConfiguration createConfigFromConfigCenter(Configuration localConfiguration) {
if (localConfiguration.getProperty(configCenterUrlKey) == null) {
LOGGER.info("config center URL is missing, skip to load configuration from config center");
return null;
}
ConfigCenterConfigurationSource configCenterConfigurationSource =
SPIServiceUtils.getTargetService(ConfigCenterConfigurationSource.class);
if (null == configCenterConfigurationSource) {
LOGGER.info(
"config center SPI service can not find, skip to load configuration from config center");
return null;
}
configCenterConfigurationSource.init(localConfiguration);
return new DynamicWatchedConfiguration(configCenterConfigurationSource);
}
示例12: testAll
import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
@Test
public void testAll() {
ConfigurationSpringInitializer configurationSpringInitializer = new ConfigurationSpringInitializer();
Assert.assertEquals(Ordered.LOWEST_PRECEDENCE / 2, configurationSpringInitializer.getOrder());
Assert.assertEquals(true,
Deencapsulation.getField(configurationSpringInitializer, "ignoreUnresolvablePlaceholders"));
Object o = ConfigUtil.getProperty("zq");
@SuppressWarnings("unchecked")
List<Map<String, Object>> listO = (List<Map<String, Object>>) o;
Assert.assertEquals(3, listO.size());
Assert.assertEquals(null, ConfigUtil.getProperty("notExist"));
MicroserviceConfigLoader loader = ConfigUtil.getMicroserviceConfigLoader();
Assert.assertNotNull(loader);
Configuration instance = ConfigurationManager.getConfigInstance();
ConfigUtil.installDynamicConfig();
// must not reinstall
Assert.assertEquals(instance, ConfigurationManager.getConfigInstance());
}
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:23,代码来源:TestConfigurationSpringInitializer.java
示例13: getPropertiesWithPrefix
import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
/**
* 获取key包含prefix前缀的所有配置项
*/
public static Map<String, String> getPropertiesWithPrefix(String prefix) {
Object config = DynamicPropertyFactory.getBackingConfigurationSource();
if (!Configuration.class.isInstance(config)) {
return new HashMap<>();
}
return getPropertiesWithPrefix((Configuration) config, prefix);
}
示例14: testGetPropertiesWithPrefix
import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
@Test
public void testGetPropertiesWithPrefix() {
Configuration configuration = ConfigUtil.createLocalConfig();
String prefix = "service_description.properties";
Map<String, String> expectedMap = new HashMap<>();
expectedMap.put("key1", "value1");
expectedMap.put("key2", "value2");
Assert.assertEquals(expectedMap, ConfigurePropertyUtils.getPropertiesWithPrefix(configuration, prefix));
List<BasePath> paths = ConfigurePropertyUtils.getMicroservicePaths(configuration);
Assert.assertEquals(2, paths.size());
Assert.assertEquals(paths.get(0).getPath(), "/test1/testpath");
Assert.assertEquals(paths.get(0).getProperty().get("checksession"), false);
System.setProperty(Const.URL_PREFIX, "/webroot");
paths = ConfigurePropertyUtils.getMicroservicePaths(configuration);
Assert.assertEquals(2, paths.size());
Assert.assertEquals(paths.get(0).getPath(), "/webroot/test1/testpath");
Assert.assertEquals(paths.get(0).getProperty().get("checksession"), false);
}
示例15: loadFirst
import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
/**
* Load configuration from a list of files until the first successful load
* @param conf the configuration object
* @param files the list of filenames to try
* @return the configuration object
*/
static MetricsConfig loadFirst(String prefix, String... fileNames) {
for (String fname : fileNames) {
try {
Configuration cf = new PropertiesConfiguration(fname)
.interpolatedConfiguration();
LOG.info("loaded properties from "+ fname);
LOG.debug(toString(cf));
MetricsConfig mc = new MetricsConfig(cf, prefix);
LOG.debug(mc);
return mc;
} catch (ConfigurationException e) {
if (e.getMessage().startsWith("Cannot locate configuration")) {
continue;
}
throw new MetricsConfigException(e);
}
}
LOG.warn("Cannot locate configuration: tried "+
Joiner.on(",").join(fileNames));
// default to an empty configuration
return new MetricsConfig(new PropertiesConfiguration(), prefix);
}