List of usage examples for org.apache.commons.configuration CompositeConfiguration addConfiguration
public void addConfiguration(Configuration config)
From source file:gobblin.metastore.util.DatabaseJobHistoryStoreSchemaManager.java
public static void main(String[] args) throws IOException { if (args.length < 1 || args.length > 2) { printUsage();/*from w ww . j ava 2 s.com*/ } Closer closer = Closer.create(); try { CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(new SystemConfiguration()); if (args.length == 2) { config.addConfiguration(new PropertiesConfiguration(args[1])); } Properties properties = getProperties(config); DatabaseJobHistoryStoreSchemaManager schemaManager = closer .register(DatabaseJobHistoryStoreSchemaManager.builder(properties).build()); if (String.CASE_INSENSITIVE_ORDER.compare("migrate", args[0]) == 0) { schemaManager.migrate(); } else if (String.CASE_INSENSITIVE_ORDER.compare("info", args[0]) == 0) { schemaManager.info(); } else { printUsage(); } } catch (Throwable t) { throw closer.rethrow(t); } finally { closer.close(); } }
From source file:com.dattack.dbcopy.cli.DbCopyCli.java
/** * The <code>main</code> method. * * @param args//from ww w . j av a 2 s .co m * the program arguments */ public static void main(final String[] args) { final Options options = createOptions(); try { final CommandLineParser parser = new DefaultParser(); final CommandLine cmd = parser.parse(options, args); final String[] filenames = cmd.getOptionValues(FILE_OPTION); final String[] jobNames = cmd.getOptionValues(JOB_NAME_OPTION); final String[] propertiesFiles = cmd.getOptionValues(PROPERTIES_OPTION); HashSet<String> jobNameSet = null; if (jobNames != null) { jobNameSet = new HashSet<>(Arrays.asList(jobNames)); } CompositeConfiguration configuration = new CompositeConfiguration(); if (propertiesFiles != null) { for (final String fileName : propertiesFiles) { configuration.addConfiguration(new PropertiesConfiguration(fileName)); } } final DbCopyEngine ping = new DbCopyEngine(); ping.execute(filenames, jobNameSet, configuration); } catch (@SuppressWarnings("unused") final ParseException e) { showUsage(options); } catch (final ConfigurationException | DattackParserException e) { System.err.println(e.getMessage()); } }
From source file:ch.cyclops.gatekeeper.Main.java
public static void main(String[] args) throws Exception { CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(new SystemConfiguration()); if (args.length > 0) config.addConfiguration(new PropertiesConfiguration(args[args.length - 1])); //setting up the logging framework now Logger.getRootLogger().getLoggerRepository().resetConfiguration(); ConsoleAppender console = new ConsoleAppender(); //create appender //configure the appender String PATTERN = "%d [%p|%C{1}|%M|%L] %m%n"; console.setLayout(new PatternLayout(PATTERN)); String logConsoleLevel = config.getProperty("log.level.console").toString(); switch (logConsoleLevel) { case ("INFO"): console.setThreshold(Level.INFO); break;/*from ww w. ja va2s . c o m*/ case ("DEBUG"): console.setThreshold(Level.DEBUG); break; case ("WARN"): console.setThreshold(Level.WARN); break; case ("ERROR"): console.setThreshold(Level.ERROR); break; case ("FATAL"): console.setThreshold(Level.FATAL); break; case ("OFF"): console.setThreshold(Level.OFF); break; default: console.setThreshold(Level.ALL); } console.activateOptions(); //add appender to any Logger (here is root) Logger.getRootLogger().addAppender(console); String logFileLevel = config.getProperty("log.level.file").toString(); String logFile = config.getProperty("log.file").toString(); if (logFile != null && logFile.length() > 0) { FileAppender fa = new FileAppender(); fa.setName("FileLogger"); fa.setFile(logFile); fa.setLayout(new PatternLayout("%d %-5p [%c{1}] %m%n")); switch (logFileLevel) { case ("INFO"): fa.setThreshold(Level.INFO); break; case ("DEBUG"): fa.setThreshold(Level.DEBUG); break; case ("WARN"): fa.setThreshold(Level.WARN); break; case ("ERROR"): fa.setThreshold(Level.ERROR); break; case ("FATAL"): fa.setThreshold(Level.FATAL); break; case ("OFF"): fa.setThreshold(Level.OFF); break; default: fa.setThreshold(Level.ALL); } fa.setAppend(true); fa.activateOptions(); //add appender to any Logger (here is root) Logger.getRootLogger().addAppender(fa); } //now logger configuration is done, we can start using it. Logger mainLogger = Logger.getLogger("gatekeeper-driver.Main"); mainLogger.debug("Driver loaded properly"); if (args.length > 0) { GKDriver gkDriver = new GKDriver(args[args.length - 1], 1, "Eq7K8h9gpg"); System.out.println("testing if admin: " + gkDriver.isAdmin(1, 0)); ArrayList<String> uList = gkDriver.getUserList(0); //the argument is the starting count of number of allowed //internal attempts. if (uList != null) { mainLogger.info("Received user list from Gatekeeper! Count: " + uList.size()); for (int i = 0; i < uList.size(); i++) mainLogger.info(uList.get(i)); } boolean authResponse = gkDriver.simpleAuthentication(1, "Eq7K8h9gpg"); if (authResponse) mainLogger.info("Authentication attempt was successful."); else mainLogger.warn("Authentication attempt failed!"); String sName = "myservice-" + System.currentTimeMillis(); HashMap<String, String> newService = gkDriver.registerService(sName, "this is my new cool service", 0); String sKey = ""; if (newService != null) { mainLogger.info("Service registration was successful! Got:" + newService.get("uri") + ", Key=" + newService.get("key")); sKey = newService.get("key"); } else { mainLogger.warn("Service registration failed!"); } int newUserId = gkDriver.registerUser("user-" + System.currentTimeMillis(), "pass1234", false, sName, 0); if (newUserId != -1) mainLogger.info("User registration was successful. Received new id: " + newUserId); else mainLogger.warn("User registration failed!"); String token = gkDriver.generateToken(newUserId, "pass1234"); boolean isValidToken = gkDriver.validateToken(token, newUserId); if (isValidToken) mainLogger.info("The token: " + token + " is successfully validated for user-id: " + newUserId); else mainLogger.warn("Token validation was unsuccessful! Token: " + token + ", user-id: " + newUserId); ArrayList<String> sList = gkDriver.getServiceList(0); //the argument is the starting count of number of allowed //internal attempts. if (sList != null) { mainLogger.info("Received service list from Gatekeeper! Count: " + sList.size()); for (int i = 0; i < sList.size(); i++) mainLogger.info(sList.get(i)); } isValidToken = gkDriver.validateToken(token, sKey); if (isValidToken) mainLogger.info("The token: " + token + " is successfully validated for user-id: " + newUserId + " against s-key:" + sKey); else mainLogger.warn("Token validation was unsuccessful! Token: " + token + ", user-id: " + newUserId + ", s-key: " + sKey); boolean deleteResult = gkDriver.deleteUser(newUserId, 0); if (deleteResult) mainLogger.info("User with id: " + newUserId + " was deleted successfully."); else mainLogger.warn("User with id: " + newUserId + " could not be deleted successfully!"); } }
From source file:mpaf.Main.java
public static void main(String[] args) { // Apache commons configuration CompositeConfiguration config = new CompositeConfiguration(); try {/*w w w .j av a2 s. c o m*/ XMLConfiguration user = new XMLConfiguration("mpaf.properties.user.xml"); XMLConfiguration defaults = new XMLConfiguration("mpaf.properties.default.xml"); // careful configuration is read from top to bottom if you want a // config to overwrite the user config, add it as first element // also make it optional to load, check if the file exists and THEN // load it! if (user != null) config.addConfiguration(user); config.addConfiguration(defaults); } catch (ConfigurationException e1) { e1.printStackTrace(); } SqlHandler sqlH = null; sqlH = new SqlHandler(); sqlH.setDbtype(config.getString("db.type", "sqlite")); sqlH.setDbhost(config.getString("db.host", "127.0.0.1")); sqlH.setDbport(config.getString("db.port", "3306")); sqlH.setDbname(config.getString("db.name", "mpaf.db")); sqlH.setDbuser(config.getString("db.user")); sqlH.setDbpass(config.getString("db.password")); IceModel iceM = new IceModel(config); IceController iceC; try { iceC = new IceController(iceM, sqlH.getConnection()); } catch (ClassNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); return; } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); return; } Server server = new Server(); ConsoleParser parser = new ConsoleParser(iceC, iceM, server); new Thread(parser).start(); // will be called once a shutdown event is thrown(like ctrl+c or sigkill // etc.) ShutdownThread shutdown = new ShutdownThread(iceC); Runtime.getRuntime().addShutdownHook(new Thread(shutdown)); if (config.getBoolean("jetty.enabled")) { SocketConnector connector = new SocketConnector(); connector.setPort(config.getInt("jetty.ports.http", 10001)); server.setConnectors(new Connector[] { connector }); ServletContextHandler servletC = new ServletContextHandler(ServletContextHandler.SESSIONS); servletC.setContextPath("/"); servletC.setAttribute("sqlhandler", sqlH); servletC.setAttribute("iceController", iceC); servletC.setAttribute("iceModel", iceM); // To add a servlet: ServletHolder holder = new ServletHolder(new DefaultCacheServlet()); holder.setInitParameter("cacheControl", "max-age=3600,public"); holder.setInitParameter("resourceBase", "web"); servletC.addServlet(holder, "/"); servletC.addServlet(new ServletHolder(new ServerList()), "/serverlist"); servletC.addServlet(new ServletHolder(new ChannelList()), "/channellist"); servletC.addServlet(new ServletHolder(new HandlerList()), "/handlerlist"); servletC.addServlet(new ServletHolder(new ServerManage()), "/servermanage"); servletC.addServlet(new ServletHolder(new Login()), "/login"); servletC.addServlet(new ServletHolder(new Logout()), "/logout"); servletC.addServlet(new ServletHolder(new UserCreate()), "/usercreate"); servletC.addServlet(new ServletHolder(new UserInfo()), "/userinfo"); servletC.addServlet(new ServletHolder(new UserList()), "/userlist"); server.setHandler(servletC); try { server.start(); server.join(); } catch (Exception e) { e.printStackTrace(); } } }
From source file:de.berber.kindle.annotator.Main.java
/** * Main function of PDFAnnotator. For command line parameters see the {@see * Options} class.//from www .ja va 2s . c o m * * @param args * List of command line parameters. */ public static void main(String[] args) { final CompositeConfiguration cc = new CompositeConfiguration(); try { // configure logging final PatternLayout layout = new PatternLayout("%d{ISO8601} %-5p [%t] %c: %m%n"); final ConsoleAppender consoleAppender = new ConsoleAppender(layout); Logger.getRootLogger().addAppender(consoleAppender); Logger.getRootLogger().setLevel(Level.WARN); // read commandline final Options options = new Options(); final CmdLineParser parser = new CmdLineParser(options); parser.setUsageWidth(80); try { // parse the arguments. parser.parseArgument(args); if (options.help) { parser.printUsage(System.err); return; } } catch (CmdLineException e) { // if there's a problem in the command line, // you'll get this exception. this will report // an error message. System.err.println(e.getMessage()); System.err.println("Usage:"); // print the list of available options parser.printUsage(System.err); System.err.println(); // print option sample. This is useful some time System.err.println(" Example: java -jar <jar> " + parser.printExample(ExampleMode.ALL)); return; } // read default configuration file final URL defaultURL = PDFAnnotator.class.getClassLoader() .getResource("de/berber/kindle/annotator/PDFAnnotator.default"); // read config file specified at the command line if (options.config != null) { final File configFile = new File(options.config); if (!configFile.exists() || !configFile.canRead()) { LOG.error("Specified configuration file does not exist."); } else { cc.addConfiguration(new PropertiesConfiguration(configFile)); } } cc.addConfiguration(new PropertiesConfiguration(defaultURL)); final WorkingList model = new WorkingList(); final WorkQueue queue = new WorkQueue(cc, model); AbstractMain view = null; if (options.noGUI) { view = new BatchMain(options, model); } else { view = new MainWindow(options, model); } view.run(); if (options.noGUI) { queue.stop(); } } catch (Exception ex) { LOG.error("Error while executing Kindle Annotator. Please report a bug."); ex.printStackTrace(); } }
From source file:io.apiman.common.config.ConfigFactory.java
public static final CompositeConfiguration createConfig() { CompositeConfiguration compositeConfiguration = new CompositeConfiguration(); compositeConfiguration.addConfiguration(new SystemPropertiesConfiguration()); compositeConfiguration//from w ww . ja v a 2s. com .addConfiguration(ConfigFileConfiguration.create("apiman.properties", "apiman.config.url")); //$NON-NLS-1$ //$NON-NLS-2$ return compositeConfiguration; }
From source file:com.hpe.caf.worker.testing.SystemSettingsProvider.java
private static CompositeConfiguration createConfiguration() { CompositeConfiguration configuration = new CompositeConfiguration(); configuration.addConfiguration(new SystemConfiguration()); configuration.addConfiguration(new EnvironmentConfiguration()); return configuration; }
From source file:com.dattack.jtoolbox.commons.configuration.ConfigurationUtil.java
/** * Create a <code>Configuration</code> based on the environment variables and system properties. * * @return a <code>Configuration</code> based on the environment variables and system properties *//* www . ja v a 2 s . co m*/ public static CompositeConfiguration createEnvSystemConfiguration() { final CompositeConfiguration configuration = new CompositeConfiguration(); configuration.addConfiguration(new SystemConfiguration()); configuration.addConfiguration(new EnvironmentConfiguration()); return configuration; }
From source file:com.dattack.dbtools.drules.DrulesClient.java
private static CompositeConfiguration loadProperties(final String[] propertyFiles) throws ConfigurationException { final CompositeConfiguration configuration = new CompositeConfiguration(); configuration.addConfiguration(GlobalConfiguration.getConfiguration()); if (propertyFiles != null) { for (final String filename : propertyFiles) { if (StringUtils.isNotBlank(filename)) { configuration.addConfiguration( new PropertiesConfiguration(ConfigurationUtil.interpolate(filename, configuration))); }/* ww w .ja va2 s . c o m*/ } } return configuration; }
From source file:com.dattack.naming.standalone.StandaloneContextFactory.java
private static CompositeConfiguration getConfiguration(final Map<?, ?> environment) { final BaseConfiguration baseConf = new BaseConfiguration(); for (final Entry<?, ?> entry : environment.entrySet()) { baseConf.setProperty(ObjectUtils.toString(entry.getKey()), entry.getValue()); }/* w w w . j a va 2 s. c o m*/ final CompositeConfiguration configuration = new CompositeConfiguration(); configuration.addConfiguration(new SystemConfiguration()); configuration.addConfiguration(new EnvironmentConfiguration()); configuration.addConfiguration(baseConf); return configuration; }