Java Code Examples for org.apache.commons.configuration.ConfigurationException#printStackTrace()

The following examples show how to use org.apache.commons.configuration.ConfigurationException#printStackTrace() . 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: DomainController.java    From wings with Apache License 2.0 6 votes vote down vote up
private boolean saveUserConfig(String file) {
	PropertyListConfiguration config = new PropertyListConfiguration();
	config.addProperty("user.domain", this.domain.getDomainName());
	for (String domname : this.user_domains.keySet()) {
		DomainInfo dom = this.user_domains.get(domname);
		config.addProperty("user.domains.domain(-1).name", dom.getName());
		config.addProperty("user.domains.domain.dir", dom.getDirectory());
		if(dom.isLegacy())
			config.addProperty("user.domains.domain.legacy", dom.isLegacy());
		else
			config.addProperty("user.domains.domain.url", dom.getUrl());
	}
	try {
		config.save(file);
		return true;
	} catch (ConfigurationException e) {
		e.printStackTrace();
		return false;
	}
}
 
Example 2
Source File: BookKeeperClientFactoryImplTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetMetadataServiceUri() {
    BookKeeperClientFactoryImpl factory = new BookKeeperClientFactoryImpl();
    ServiceConfiguration conf = new ServiceConfiguration();
    conf.setZookeeperServers("localhost:2181");
    try {
        String defaultUri = "zk+null://localhost:2181/ledgers";
        assertEquals(factory.createBkClientConfiguration(conf).getMetadataServiceUri(), defaultUri);
        String expectedUri = "zk+hierarchical://localhost:2181/chroot/ledgers";
        conf.setBookkeeperMetadataServiceUri(expectedUri);
        assertEquals(factory.createBkClientConfiguration(conf).getMetadataServiceUri(), expectedUri);
    } catch (ConfigurationException e) {
        e.printStackTrace();
        fail("Get metadata service uri should be successful", e);
    }
}
 
Example 3
Source File: NerTrainingConfig.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
/**
 * @param file
 * 			Path to config file
 */
public NerTrainingConfig(String file) {
	try {
		configuration = new PropertiesConfiguration(file);
	} catch (ConfigurationException e) {
		logger.error("Configuration file could not be loaded: " + file);
		e.printStackTrace();
	}
}
 
Example 4
Source File: AbstractConfigTest.java    From opensoc-streaming with Apache License 2.0 5 votes vote down vote up
protected void setUp(String configName) throws Exception {
    super.setUp();
    this.setConfigPath("src/test/resources/config/"+getClass().getSimpleName()+".config");
    try {
        this.setConfig(new PropertiesConfiguration(this.getConfigPath()));
       
        Map configOptions= SettingsLoader.getConfigOptions((PropertiesConfiguration)this.config, configName+"=");
        this.setSettings(SettingsLoader.getConfigOptions((PropertiesConfiguration)this.config, configName + "."));
        this.getSettings().put(configName, (String) configOptions.get(configName));
    } catch (ConfigurationException e) {
        fail("Config not found !!"+e);
        e.printStackTrace();
    }               
}
 
Example 5
Source File: CognitionConfiguration.java    From cognition with Apache License 2.0 5 votes vote down vote up
/**
 * Load the CognitionConfiguration from the given AccumuloConfiguration object
 * and any other configurations from the given properties file.
 * @param filePath -- the path to the properties file
 */
public CognitionConfiguration(AccumuloConfiguration accumuloConfig, String filePath) {
  try {
    this.config = new PropertiesConfiguration(filePath);
  } catch (ConfigurationException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
  this.accumuloConfig = accumuloConfig;
}
 
Example 6
Source File: ConfigComponent.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
public void reload() {
  boolean mainConfigLoaded = false;
  for (ConfigView configView : configViews) {
    Configuration configurationForView;

    try {
      configurationForView = configurationProvider.getConfigurationForView(configView);
      if (configurationForView instanceof DataConfiguration) {
        DataConfiguration dc = (DataConfiguration) configurationForView;
        configurationForView = dc.getConfiguration();
      }
      if (configurationForView instanceof FileConfiguration) {
        FileConfiguration fc = (FileConfiguration) configurationForView;
        if (configView instanceof InMainConfig) {
          if (!mainConfigLoaded) {
            fc.reload();
            mainConfigLoaded = true;
          }
        } else {
          fc.reload();
        }
        configView.loadConfiguration(fc);
      }
    } catch (ConfigurationException e1) {
      //TODO ??
      e1.printStackTrace();
    }
  }
}
 
Example 7
Source File: ShiroAuthenticationServiceTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
private void setupPrincipalName(String expectedName) {
  PowerMockito.mockStatic(org.apache.shiro.SecurityUtils.class);
  when(org.apache.shiro.SecurityUtils.getSubject()).thenReturn(subject);
  when(subject.isAuthenticated()).thenReturn(true);
  when(subject.getPrincipal()).thenReturn(new PrincipalImpl(expectedName));

  Notebook notebook = Mockito.mock(Notebook.class);
  try {
    when(notebook.getConf())
        .thenReturn(new ZeppelinConfiguration(this.getClass().getResource("/zeppelin-site.xml")));
  } catch (ConfigurationException e) {
    e.printStackTrace();
  }
}
 
Example 8
Source File: RunningMan.java    From JavaRock with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
        //1. 读xml到对象
        String dataFile = "CourseManagementSystem.xml";
        XmlService xmlService = null;
        try {
            xmlService = new XmlService(dataFile);
        } catch (ConfigurationException e) {
            e.printStackTrace();
            System.out.println("XML文件有问题,请重试");
            return;
        }
        Map<Integer, Teacher> teachers = xmlService.getTeachers("Teachers.Teacher.");
        Map<Integer, Student> students = xmlService.getStudents("Students.Student.");
        Map<Integer, Course> courses = xmlService.getCourses("Courses.Course.");
//
//        //2. 对象关联 - 业务逻辑
        List<TeacherCourse> teacherCourses = xmlService.getTechCourse("TechCourses.TechCourse.", teachers, courses);
        List<Score> scores = xmlService.getScores("Scores.Score.", courses, students);
//        //3. 对象写入DB
        String driver = "com.mysql.jdbc.Driver";
        String url = "jdbc:mysql://127.0.0.1:3306/course_management_system?useUnicode=true&characterEncoding=UTF-8";
        String username = "root";
        String password = "password";
        DataService dataService = new DataService(driver, url, username, password);
        dataService.insertTeachers(teachers);
        dataService.insertStudents(students);
        dataService.insertCourses(courses);
        dataService.insertTechCourses(teacherCourses);
        dataService.insertScores(scores);

        for (Integer item : courses.keySet()) {
            System.out.println(dataService.queryMaxScore(item).toString());
        }
    }
 
Example 9
Source File: RunningMan.java    From JavaRock with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
        //1. 初始化
        String xmlPath = "CourseManagementSystem.xml";
        XmlParserService xmlParserService = null;
        try {
            xmlParserService = new XmlParserService(xmlPath);
        } catch (ConfigurationException e) {
            e.printStackTrace();
            return;
        }
        //2. 读xml到对象集合
        Map<Integer, Teacher> teachers = xmlParserService.getTeachers("Teachers.Teacher");
        Map<Integer, Student> students = xmlParserService.getStudents("Students.Student");
        Map<Integer, Course> courses = xmlParserService.getCourses("Courses.Course");
//
//        //3. 对象的业务处理
        List<TechCourse> techCourses = xmlParserService.getTechCourses("TechCourses.TechCourse", teachers, courses);
        List<Score> scores = xmlParserService.getScore("Scores.Score", students, courses);
//        //4. 将对象写入数据库中
        String url = "jdbc:mysql://127.0.0.1:3306/course_management_system?useUnicode=true&characterEncoding=UTF-8";
        String username = "root";
        String password = "password";
        DBService dbService = new DBService(url, username, password);
        dbService.insertTeachers(teachers);
        dbService.insertStudents(students);
        dbService.insertCourses(courses);
        dbService.insertTechCourses(techCourses);
        dbService.insertScore(scores);
        //最大值
        for (int i : courses.keySet()) {
            dbService.queryMaxScore(i);
        }
//        //5. 结束工作
        dbService.close();
    }
 
Example 10
Source File: PlatformConfiguration.java    From dpCms with Apache License 2.0 5 votes vote down vote up
private PlatformConfiguration(){
	try {
		config = new PropertiesConfiguration("platform.properties");
		config.setReloadingStrategy(new FileChangedReloadingStrategy());			
	} catch (ConfigurationException e) {
		e.printStackTrace();
	}  
}
 
Example 11
Source File: XMLScenarioFactory.java    From qaf with MIT License 5 votes vote down vote up
@Override
protected Collection<Object[]> parseFile(String xmlFile) {
	ArrayList<Object[]> statements = new ArrayList<Object[]>();
	try {
		HierarchicalConfiguration processor = new XMLConfiguration(xmlFile);
		List<?> definations = processor.getRoot().getChildren();
		for (Object definationObj : definations) {
			ConfigurationNode defination = (ConfigurationNode) definationObj;
			String type = defination.getName();
			String[] entry = new String[3];

			if (type.equalsIgnoreCase("SCENARIO") || type.equalsIgnoreCase("STEP-DEF")) {
				entry[0] = type;

				Map<?, ?> metaData = getMetaData(defination);
				entry[1] = (String) metaData.get("name");
				metaData.remove("name");
				entry[2] = gson.toJson(metaData);
				statements.add(entry);
				System.out.println("META-DATA:" + entry[2]);
				addSteps(defination, statements);
				statements.add(new String[] { "END", "", "" });
			}
		}
	} catch (ConfigurationException e) {
		e.printStackTrace();
	}

	return statements;
}
 
Example 12
Source File: MyConfigurationXMLUtils.java    From spring-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 获取树状结构数据
 */
public void getHierarchicalExample() {

    try {
        XMLConfiguration config = new XMLConfiguration("properties-website-job.xml");
        log.info(config.getFileName());
        //   log.info(config.getStringByEncoding("jdbc.oracle.work.235.url", "GBK"));

        //包含 websites.site.name 的集合
        Object prop = config.getProperty("websites.site.name");

        if (prop instanceof Collection) {
            //  System.out.println("Number of tables: " + ((Collection<?>) prop).size());
            Collection<String> c = (Collection<String>) prop;
            int i = 0;

            for (String s : c) {

                System.out.println("sitename :" + s);

                List<HierarchicalConfiguration> fields = config.configurationsAt("websites.site(" + String.valueOf(i) + ").fields.field");
                for (HierarchicalConfiguration sub : fields) {
                    // sub contains all data about a single field
                    //此处可以包装成 bean
                    String name = sub.getString("name");
                    String type = sub.getString("type");
                    System.out.println("name :" + name + " , type :" + type);
                }

                i++;
                System.out.println(" === ");
            }
        }
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }


}
 
Example 13
Source File: MyConfigurationPropertiesUtils.java    From spring-boot with Apache License 2.0 5 votes vote down vote up
public MyConfigurationPropertiesUtils(String propertyFileName) {

        try {
            propertiesConfiguration = new PropertiesConfiguration(propertyFileName);
        } catch (ConfigurationException e) {
            e.printStackTrace();
        }
    }
 
Example 14
Source File: ConfigHelper.java    From lorne_core with Apache License 2.0 5 votes vote down vote up
public void setProperty(String key, Object val) {
    propertiesConfiguration.setProperty(key, val);
    try {
        propertiesConfiguration.save();
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }
}
 
Example 15
Source File: Configuration.java    From nightwatch with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void init(String configFilePath) {
    try {
        defultConfigFilePath = configFilePath;
        config = new PropertiesConfiguration(defultConfigFilePath);
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }
}
 
Example 16
Source File: ConfigHelper.java    From Lottor with MIT License 5 votes vote down vote up
public void setProperty(String key, Object val) {
    propertiesConfiguration.setProperty(key, val);
    try {
        propertiesConfiguration.save();
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }
}
 
Example 17
Source File: ColUtil.java    From yshopmall with Apache License 2.0 5 votes vote down vote up
/**
 * 获取配置信息
 */
public static PropertiesConfiguration getConfig() {
    try {
        return new PropertiesConfiguration("generator.properties" );
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 18
Source File: MetaSettings.java    From systemsgenetics with GNU General Public License v3.0 4 votes vote down vote up
public void parse(String settings, String texttoreplace, String replacetextwith) {
		try {
			config = new XMLConfiguration(settings);

			nrPermutations = config.getInt("defaults.permutations", 0);

			useAbsoluteZscore = config.getBoolean("defaults.absolutezscore", false);
			finalEQTLBufferMaxLength = config.getInt("defaults.finalnreqtls", 100000);
			fdrthreshold = config.getDouble("defaults.fdrthreshold", 0.05);
			cisdistance = config.getInt("defaults.cisprobedistance", 250000);
			transdistance = config.getInt("defaults.transprobedistance", 5000000);
			includeProbesWithoutProperMapping = config.getBoolean("defaults.includeprobeswithoutmapping", true);
			includeSNPsWithoutProperMapping = config.getBoolean("defaults.includesnpswithoutmapping", true);
			makezscoreplot = config.getBoolean("defaults.makezscoreplot", true);
			makezscoretable = config.getBoolean("defaults.makezscoretable", false);
			probetranslationfile = config.getString("defaults.probetranslationfile");
			String outputStr = config.getString("defaults.output");

			System.out.println("outputstr: " + outputStr);

			if (texttoreplace != null && replacetextwith != null && outputStr.contains(texttoreplace)) {
				outputStr = outputStr.replaceAll(texttoreplace, replacetextwith);
				System.out.println("outputstr: " + outputStr);
			}
			output = outputStr;
			System.out.println("outputstr: " + outputStr);
//			System.exit(-1);


			probeDatasetPresenceThreshold = config.getInt("defaults.minimalnumberofdatasetsthatcontainprobe", 0);
			snpDatasetPresenceThreshold = config.getInt("defaults.minimalnumberofdatasetsthatcontainsnp", 0);
			probeAndSNPPresenceFilterSampleThreshold = config.getInt("defaults.snpprobeselectsamplesizethreshold", -1);

			runonlypermutation = config.getInt("defaults.runonlypermutation", -1);
			nrThresds = config.getInt("defaults.threads", 0);
			cis = config.getBoolean("defaults.cis", false);
			trans = config.getBoolean("defaults.trans", false);

			probeselection = config.getString("defaults.probeselection");

			if (probeselection != null && probeselection.trim().length() == 0) {
				probeselection = null;
			}
			snpselection = config.getString("defaults.snpselection");

			if (snpselection != null && snpselection.trim().length() == 0) {
				snpselection = null;
			}

			if (texttoreplace != null && replacetextwith != null && snpselection.contains(texttoreplace)) {
				snpselection = snpselection.replaceAll(texttoreplace, replacetextwith);
			}

			snpprobeselection = config.getString("defaults.snpprobeselection");

			if (snpprobeselection != null && snpprobeselection.trim().length() == 0) {
				snpprobeselection = null;
			} else {
				System.out.println("SNP PROBE SELECTION: " + snpprobeselection);
			}


			int i = 0;

			String dataset = "";
			datasetnames = new ArrayList<String>();
			datasetlocations = new ArrayList<String>();
			datasetannotations = new ArrayList<String>();
			datasetPrefix = new ArrayList<String>();

			while (dataset != null) {
				dataset = config.getString("datasets.dataset(" + i + ").name");  // see if a dataset is defined
				if (dataset != null) {

					datasetnames.add(dataset);
					String prefix = config.getString("datasets.dataset(" + i + ").prefix");  // see if a dataset is defined

					if (prefix == null) {
						prefix = "Dataset";
					}
					datasetPrefix.add(prefix);
					String datasetlocation = config.getString("datasets.dataset(" + i + ").location");  // see if a dataset is defined
					if (texttoreplace != null && replacetextwith != null && datasetlocation.contains(texttoreplace)) {
						datasetlocation = datasetlocation.replace(texttoreplace, replacetextwith);
					}
					String datasetannotation = config.getString("datasets.dataset(" + i + ").expressionplatform");  // see if a dataset is defined

					datasetlocations.add(datasetlocation);
					datasetannotations.add(datasetannotation);
				}
				i++;
			}


			// parse datasets
		} catch (ConfigurationException e) {
			e.printStackTrace();
		}
	}
 
Example 19
Source File: Domain.java    From wings with Apache License 2.0 4 votes vote down vote up
private void initializeDomain() {
	try {
	  if(!new File(this.domainConfigFile).exists())
	    return;
	  
		PropertyListConfiguration config = new PropertyListConfiguration(this.domainConfigFile);

		this.useSharedTripleStore = config.getBoolean("useSharedTripleStore", true);
		this.planEngine = config.getString("executions.engine.plan", "Local");
		this.stepEngine = config.getString("executions.engine.step", "Local");

		this.templateLibrary = new DomainLibrary(config.getString("workflows.library.url"),
				config.getString("workflows.library.map"));
		this.newTemplateDirectory = new UrlMapPrefix(config.getString("workflows.prefix.url"),
				config.getString("workflows.prefix.map"));

		this.executionLibrary = new DomainLibrary(config.getString("executions.library.url"),
				config.getString("executions.library.map"));
		this.newExecutionDirectory = new UrlMapPrefix(config.getString("executions.prefix.url"),
				config.getString("executions.prefix.map"));
		
		this.dataOntology = new DomainOntology(config.getString("data.ontology.url"),
				config.getString("data.ontology.map"));
		this.dataLibrary = new DomainLibrary(config.getString("data.library.url"),
				config.getString("data.library.map"));
		this.dataLibrary.setStorageDirectory(config.getString("data.library.storage"));

		this.componentLibraryNamespace = config.getString("components.namespace");
		this.abstractComponentLibrary = new DomainLibrary(
				config.getString("components.abstract.url"),
				config.getString("components.abstract.map"));

		String concreteLibraryName = config.getString("components.concrete");
		List<HierarchicalConfiguration> clibs = config.configurationsAt("components.libraries.library");
		for (HierarchicalConfiguration clib : clibs) {
			String url = clib.getString("url");
			String map = clib.getString("map");
			String name = clib.getString("name");
			String codedir = clib.getString("storage");
			DomainLibrary concreteLib = new DomainLibrary(url, map, name, codedir);
			this.concreteComponentLibraries.add(concreteLib);
			if(name.equals(concreteLibraryName))
				this.concreteComponentLibrary = concreteLib;
		}
		
		List<HierarchicalConfiguration> perms = config.configurationsAt("permissions.permission");
      for (HierarchicalConfiguration perm : perms) {
        String userid = perm.getString("userid");
        boolean canRead = perm.getBoolean("canRead", false);
        boolean canWrite = perm.getBoolean("canWrite", false);
        boolean canExecute = perm.getBoolean("canExecute", false);
        Permission permission = new Permission(userid, canRead, canWrite, canExecute);
        this.permissions.add(permission);
      }
	} catch (ConfigurationException e) {
		e.printStackTrace();
	}
}
 
Example 20
Source File: Domain.java    From wings with Apache License 2.0 4 votes vote down vote up
public boolean saveDomain() {
	PropertyListConfiguration config = new PropertyListConfiguration();
	config.addProperty("name", this.domainName);
	config.addProperty("useSharedTripleStore", this.useSharedTripleStore);
	
	config.addProperty("executions.engine.plan", this.planEngine);
	config.addProperty("executions.engine.step", this.stepEngine);

	this.setUrlMapProp(config, "workflows.library", this.templateLibrary);
	this.setUrlMapProp(config, "workflows.prefix", this.newTemplateDirectory);
	
	this.setUrlMapProp(config, "executions.library", this.executionLibrary);
	this.setUrlMapProp(config, "executions.prefix", this.newExecutionDirectory);
	
	this.setUrlMapProp(config, "data.ontology", this.dataOntology);
	this.setUrlMapProp(config, "data.library", this.dataLibrary);
	config.addProperty("data.library.storage", this.dataLibrary.getStorageDirectory());

	config.addProperty("components.namespace", this.componentLibraryNamespace);
	this.setUrlMapProp(config, "components.abstract", this.abstractComponentLibrary);
	config.addProperty("components.concrete", this.concreteComponentLibrary.getName());

	for (DomainLibrary clib : this.concreteComponentLibraries) {
		config.addProperty("components.libraries.library(-1).url", clib.getUrl());
		config.addProperty("components.libraries.library.map", clib.getMapping());
		config.addProperty("components.libraries.library.name", clib.getName());
		config.addProperty("components.libraries.library.storage", clib.getStorageDirectory());
	}

	for (Permission permission : this.permissions) {
	  config.addProperty("permissions.permission(-1).userid", permission.getUserid());
	  config.addProperty("permissions.permission.canRead", permission.canRead());
	  config.addProperty("permissions.permission.canWrite", permission.canWrite());
	  config.addProperty("permissions.permission.canExecute", permission.canExecute());
	}
	
	if (this.domainDirectory != null) {
		File domdir = new File(this.domainDirectory);
		if (!domdir.exists() && !domdir.mkdirs())
			System.err.println("Could not create domain directory: " + this.domainDirectory);
	}
	try {
		config.save(this.domainConfigFile);
		return true;
	} catch (ConfigurationException e) {
		e.printStackTrace();
	}
	return false;
}