List of usage examples for java.util Properties getProperty
public String getProperty(String key)
From source file:com.google.api.ads.adwords.jaxws.extensions.AwReporting.java
/** * Main method.//from w w w . j a v a 2 s . c o m * * @param args the command line arguments. */ public static void main(String args[]) { // Proxy JaxWsProxySelector ps = new JaxWsProxySelector(ProxySelector.getDefault()); ProxySelector.setDefault(ps); Options options = createCommandLineOptions(); boolean errors = false; String propertiesPath = null; try { CommandLineParser parser = new BasicParser(); CommandLine cmdLine = parser.parse(options, args); // Print full help and quit if (cmdLine.hasOption("help")) { printHelpMessage(options); printSamplePropertiesFile(); System.exit(0); } setLogLevel(cmdLine); if (cmdLine.hasOption("file")) { propertiesPath = cmdLine.getOptionValue("file"); } else { LOGGER.error("Missing required option: 'file'"); System.exit(0); } LOGGER.info("Using properties file: " + propertiesPath); Set<Long> accountIdsSet = Sets.newHashSet(); if (cmdLine.hasOption("accountIdsFile")) { String accountsFileName = cmdLine.getOptionValue("accountIdsFile"); addAccountsFromFile(accountIdsSet, accountsFileName); } Properties properties = initApplicationContextAndProperties(propertiesPath); ReportModeService.setReportMode(properties.getProperty("reportMode")); //TODO Any other approach? LOGGER.debug("Creating ReportProcessor bean..."); ReportProcessor processor = createReportProcessor(); LOGGER.debug("... success."); if (cmdLine.hasOption("generatePdf")) { LOGGER.debug("GeneratePDF option detected."); // Get HTML template and output directoy String[] pdfFiles = cmdLine.getOptionValues("generatePdf"); File htmlTemplateFile = new File(pdfFiles[0]); File outputDirectory = new File(pdfFiles[1]); LOGGER.debug("Html template file to be used: " + htmlTemplateFile); LOGGER.debug("Output directory for PDF: " + outputDirectory); // Generate PDFs generatePdf(processor, cmdLine.getOptionValue("startDate"), cmdLine.getOptionValue("endDate"), properties, htmlTemplateFile, outputDirectory); } else if (cmdLine.hasOption("startDate") && cmdLine.hasOption("endDate")) { // Generate Reports String dateStart = cmdLine.getOptionValue("startDate"); String dateEnd = cmdLine.getOptionValue("endDate"); LOGGER.info("Starting report download for dateStart: " + dateStart + " and dateEnd: " + dateEnd); processor.generateReportsForMCC(ReportDefinitionDateRangeType.CUSTOM_DATE, dateStart, dateEnd, accountIdsSet, properties); } else if (cmdLine.hasOption("dateRange")) { ReportDefinitionDateRangeType dateRangeType = ReportDefinitionDateRangeType .fromValue(cmdLine.getOptionValue("dateRange")); LOGGER.info("Starting report download for dateRange: " + dateRangeType.name()); processor.generateReportsForMCC(dateRangeType, null, null, accountIdsSet, properties); } else { errors = true; LOGGER.error("Configuration incomplete. Missing options for command line."); } } catch (IOException e) { errors = true; LOGGER.error("File not found: " + e.getMessage()); } catch (ParseException e) { errors = true; System.err.println("Error parsing the values for the command line options: " + e.getMessage()); } catch (Exception e) { errors = true; LOGGER.error("Unexpected error accessing the API: " + e.getMessage()); e.printStackTrace(); } if (errors) { System.exit(1); } else { System.exit(0); } }
From source file:info.usbo.skypetwitter.Run.java
public static void main(String[] args) { System.out.println("Working Directory = " + System.getProperty("user.dir")); Properties props; props = (Properties) System.getProperties().clone(); //loadProperties(props, "D:\\Data\\Java\\classpath\\twitter.props"); work_dir = System.getProperty("user.dir"); loadProperties(props, work_dir + "\\twitter.props"); twitter_user_id = props.getProperty("twitter.user"); twitter_timeout = Integer.parseInt(props.getProperty("twitter.timeout")); System.out.println("Twitter user: " + twitter_user_id); System.out.println("Twitter timeout: " + twitter_timeout); if ("".equals(twitter_user_id)) { return;//from w w w . j a v a 2 s .c o m } if (load_file() == 0) { System.out.println("File not found"); return; } while (true) { bChanged = 0; /* create_id(); Chat ch = Chat.getInstance(chat_group_id); ch.send("!"); */ SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm"); System.out.println("Looking at " + sdf.format(Calendar.getInstance().getTime())); Chat ch = Chat.getInstance(chat_group_id); Twitter twitter = new TwitterFactory().getInstance(); try { List<Status> statuses; statuses = twitter.getUserTimeline(twitter_user_id); //System.out.println("Showing @" + twitter_user_id + "'s user timeline."); String sText; for (Status status : statuses) { //System.out.println(status.getId()); Date d = status.getCreatedAt(); // ? Calendar cal = Calendar.getInstance(); cal.setTime(d); cal.add(Calendar.HOUR_OF_DAY, 7); d = cal.getTime(); sText = "@" + status.getUser().getScreenName() + " " + sdf.format(d) + " ( https://twitter.com/" + twitter_user_id + "/status/" + status.getId() + " ): \r\n" + status.getText() + "\r\n***"; for (URLEntity e : status.getURLEntities()) { sText = sText.replaceAll(e.getURL(), e.getExpandedURL()); } for (MediaEntity e : status.getMediaEntities()) { sText = sText.replaceAll(e.getURL(), e.getMediaURL()); } if (twitter_ids.indexOf(status.getId()) == -1) { System.out.println(sText); ch.send(sText); twitter_ids.add(status.getId()); bChanged = 1; } } } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); //System.exit(-1); } catch (SkypeException ex) { ex.printStackTrace(); System.out.println("Failed to send message: " + ex.getMessage()); } // VK try { vk(); for (VK v : vk) { if (vk_ids.indexOf(v.getId()) == -1) { Date d = v.getDate(); // ? Calendar cal = Calendar.getInstance(); cal.setTime(d); cal.add(Calendar.HOUR_OF_DAY, 7); d = cal.getTime(); String sText = "@Depersonilized (VK) " + sdf.format(d) + " ( http://vk.com/Depersonilized?w=wall-0_" + v.getId() + " ): \r\n" + v.getText(); if (!"".equals(v.getAttachment())) { sText += "\r\n" + v.getAttachment(); } sText += "\r\n***"; System.out.println(sText); ch.send(sText); vk_ids.add(v.getId()); bChanged = 1; } } } catch (ParseException e) { e.printStackTrace(); System.out.println("Failed to get vk: " + e.getMessage()); //System.exit(-1); } catch (SkypeException ex) { ex.printStackTrace(); System.out.println("Failed to send message: " + ex.getMessage()); } if (bChanged == 1) { save_file(); } try { Thread.sleep(1000 * 60 * twitter_timeout); } catch (InterruptedException ex) { ex.printStackTrace(); System.out.println("Failed to sleep: " + ex.getMessage()); } } }
From source file:com.digitalgeneralists.assurance.Application.java
public static void main(String[] args) { Logger logger = Logger.getLogger(Application.class); logger.info("App is starting."); Properties applicationProperties = new Properties(); String applicationInfoFileName = "/version.txt"; InputStream inputStream = Application.class.getResourceAsStream(applicationInfoFileName); applicationInfoFileName = null;/*from w w w. j a v a 2 s . c o m*/ try { if (inputStream != null) { applicationProperties.load(inputStream); Application.applicationShortName = applicationProperties.getProperty("name"); Application.applicationName = applicationProperties.getProperty("applicationName"); Application.applicationVersion = applicationProperties.getProperty("version"); Application.applicationBuildNumber = applicationProperties.getProperty("buildNumber"); applicationProperties = null; } } catch (IOException e) { logger.warn("Could not load application version information.", e); } finally { try { inputStream.close(); } catch (IOException e) { logger.error("Couldn't close the application version input stream."); } inputStream = null; } javax.swing.SwingUtilities.invokeLater(new Runnable() { private Logger logger = Logger.getLogger(Application.class); public void run() { logger.info("Starting the Swing run thread."); try { Application.installDb(); } catch (IOException e) { logger.fatal("Unable to install the application database.", e); System.exit(1); } catch (SQLException e) { logger.fatal("Unable to install the application database.", e); System.exit(1); } IApplicationUI window = null; ClassPathXmlApplicationContext springContext = null; try { springContext = new ClassPathXmlApplicationContext("/META-INF/spring/app-context.xml"); StringBuffer message = new StringBuffer(256); logger.info(message.append("Spring Context: ").append(springContext)); message.setLength(0); window = (IApplicationUI) springContext.getBean("ApplicationUI"); } finally { if (springContext != null) { springContext.close(); } springContext = null; } if (window != null) { logger.info("Launching the window."); window.display(); } else { logger.fatal("The main application window object is null."); } logger = null; } }); }
From source file:de.zazaz.iot.bosch.indego.util.IndegoMqttAdapter.java
public static void main(String[] args) { System.setProperty("log4j.configurationFile", "log4j2-indegoMqttAdapter-normal.xml"); Options options = new Options(); StringBuilder commandList = new StringBuilder(); for (DeviceCommand cmd : DeviceCommand.values()) { if (commandList.length() > 0) { commandList.append(", "); }/* w w w. ja v a2s. com*/ commandList.append(cmd.toString()); } options.addOption(Option // .builder("c") // .longOpt("config") // .desc("The configuration file to use") // .required() // .hasArg() // .build()); options.addOption(Option // .builder("d") // .longOpt("debug") // .desc("Logs more details") // .build()); options.addOption(Option // .builder("?") // .longOpt("help") // .desc("Prints this help") // .build()); CommandLineParser parser = new DefaultParser(); CommandLine cmds = null; try { cmds = parser.parse(options, args); } catch (ParseException ex) { System.err.println(ex.getMessage()); System.err.println(); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(IndegoMqttAdapter.class.getName(), options); System.exit(1); return; } if (cmds.hasOption("?")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(CmdLineTool.class.getName(), options); return; } if (cmds.hasOption("d")) { System.setProperty("log4j.configurationFile", "log4j2-indegoMqttAdapter-debug.xml"); } String configFileName = cmds.getOptionValue('c'); File configFile = new File(configFileName); if (!configFile.exists()) { System.err.println(String.format("The specified config file (%s) does not exist", configFileName)); System.err.println(); System.exit(2); return; } Properties properties = new Properties(); try (InputStream in = new FileInputStream(configFile)) { properties.load(in); } catch (IOException ex) { System.err.println(ex.getMessage()); System.err.println(String.format("Was not able to load the properties file (%s)", configFileName)); System.err.println(); } MqttIndegoAdapterConfiguration config = new MqttIndegoAdapterConfiguration(); config.setIndegoBaseUrl(properties.getProperty("indego.mqtt.device.base-url")); config.setIndegoUsername(properties.getProperty("indego.mqtt.device.username")); config.setIndegoPassword(properties.getProperty("indego.mqtt.device.password")); config.setMqttBroker(properties.getProperty("indego.mqtt.broker.connection")); config.setMqttClientId(properties.getProperty("indego.mqtt.broker.client-id")); config.setMqttUsername(properties.getProperty("indego.mqtt.broker.username")); config.setMqttPassword(properties.getProperty("indego.mqtt.broker.password")); config.setMqttTopicRoot(properties.getProperty("indego.mqtt.broker.topic-root")); config.setPollingIntervalMs(Integer.parseInt(properties.getProperty("indego.mqtt.polling-interval-ms"))); MqttIndegoAdapter adapter = new MqttIndegoAdapter(config); adapter.startup(); }
From source file:de.zazaz.iot.bosch.indego.util.IndegoIftttAdapter.java
public static void main(String[] args) { System.setProperty("log4j.configurationFile", "log4j2-indegoIftttAdapter-normal.xml"); Options options = new Options(); StringBuilder commandList = new StringBuilder(); for (DeviceCommand cmd : DeviceCommand.values()) { if (commandList.length() > 0) { commandList.append(", "); }//from w w w. j a va2 s.c o m commandList.append(cmd.toString()); } options.addOption(Option // .builder("c") // .longOpt("config") // .desc("The configuration file to use") // .required() // .hasArg() // .build()); options.addOption(Option // .builder("d") // .longOpt("debug") // .desc("Logs more details") // .build()); options.addOption(Option // .builder("?") // .longOpt("help") // .desc("Prints this help") // .build()); CommandLineParser parser = new DefaultParser(); CommandLine cmds = null; try { cmds = parser.parse(options, args); } catch (ParseException ex) { System.err.println(ex.getMessage()); System.err.println(); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(IndegoIftttAdapter.class.getName(), options); System.exit(1); return; } if (cmds.hasOption("?")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(CmdLineTool.class.getName(), options); return; } if (cmds.hasOption("d")) { System.setProperty("log4j.configurationFile", "log4j2-indegoIftttAdapter-debug.xml"); } String configFileName = cmds.getOptionValue('c'); File configFile = new File(configFileName); if (!configFile.exists()) { System.err.println(String.format("The specified config file (%s) does not exist", configFileName)); System.err.println(); System.exit(2); return; } Properties properties = new Properties(); try (InputStream in = new FileInputStream(configFile)) { properties.load(in); } catch (IOException ex) { System.err.println(ex.getMessage()); System.err.println(String.format("Was not able to load the properties file (%s)", configFileName)); System.err.println(); } IftttIndegoAdapterConfiguration config = new IftttIndegoAdapterConfiguration(); config.setIftttMakerKey(properties.getProperty("indego.ifttt.maker.key")); config.setIftttIgnoreServerCertificate( Integer.parseInt(properties.getProperty("indego.ifttt.maker.ignore-server-certificate")) != 0); config.setIftttReceiverPort(Integer.parseInt(properties.getProperty("indego.ifttt.maker.receiver-port"))); config.setIftttReceiverSecret(properties.getProperty("indego.ifttt.maker.receiver-secret")); config.setIftttOfflineEventName(properties.getProperty("indego.ifttt.maker.eventname-offline")); config.setIftttOnlineEventName(properties.getProperty("indego.ifttt.maker.eventname-online")); config.setIftttErrorEventName(properties.getProperty("indego.ifttt.maker.eventname-error")); config.setIftttErrorClearedEventName(properties.getProperty("indego.ifttt.maker.eventname-error-cleared")); config.setIftttStateChangeEventName(properties.getProperty("indego.ifttt.maker.eventname-state-change")); config.setIndegoBaseUrl(properties.getProperty("indego.ifttt.device.base-url")); config.setIndegoUsername(properties.getProperty("indego.ifttt.device.username")); config.setIndegoPassword(properties.getProperty("indego.ifttt.device.password")); config.setPollingIntervalMs(Integer.parseInt(properties.getProperty("indego.ifttt.polling-interval-ms"))); IftttIndegoAdapter adapter = new IftttIndegoAdapter(config); adapter.startup(); }
From source file:eu.databata.engine.util.PropagatorRecreateDatabaseTool.java
public static void main(String[] args) { ClassLoader classLoader = PropagatorRecreateDatabaseTool.class.getClassLoader(); InputStream resourceAsStream = classLoader.getResourceAsStream("databata.properties"); Properties propagatorProperties = new Properties(); try {// www . j ava2s .c om propagatorProperties.load(resourceAsStream); } catch (FileNotFoundException e) { LOG.error("Sepecified file 'databata.properties' not found"); } catch (IOException e) { LOG.error("Sepecified file 'databata.properties' cannot be loaded"); } SingleConnectionDataSource dataSource = new SingleConnectionDataSource(); dataSource.setDriverClassName(propagatorProperties.getProperty("db.propagation.driver")); dataSource.setUrl(propagatorProperties.getProperty("db.propagation.dba.connection-url")); dataSource.setUsername(propagatorProperties.getProperty("db.propagation.dba.user")); dataSource.setPassword(propagatorProperties.getProperty("db.propagation.dba.password")); dataSource.setSuppressClose(true); String databaseName = "undefined"; try { databaseName = dataSource.getConnection().getMetaData().getDatabaseProductName(); } catch (SQLException e) { LOG.error("Cannot get connection by specified url", e); } String databaseCode = PropagationUtils.getDatabaseCode(databaseName); LOG.info("Database with code '" + databaseCode + "' is identified."); String submitFileName = "META-INF/databata/" + databaseCode + "_recreate_database.sql"; String fileContent = ""; try { fileContent = getFileContent(classLoader, submitFileName); } catch (IOException e) { LOG.info("File with name '" + submitFileName + "' cannot be read from classpath. Trying to load default submit file."); } if (fileContent == null || "".equals(fileContent)) { String defaultSubmitFileName = "META-INF/databata/" + databaseCode + "_recreate_database.default.sql"; try { fileContent = getFileContent(classLoader, defaultSubmitFileName); } catch (IOException e) { LOG.info("File with name '" + defaultSubmitFileName + "' cannot be read from classpath. Trying to load default submit file."); } } if (fileContent == null) { LOG.info("File content is empty. Stopping process."); return; } fileContent = replacePlaceholders(fileContent, propagatorProperties); SqlFile sqlFile = null; try { sqlFile = new SqlFile(fileContent, null, submitFileName, new SqlExecutionCallback() { @Override public void handleExecuteSuccess(String sql, int arg1, double arg2) { LOG.info("Sql is sucessfully executed \n ======== \n" + sql + "\n ======== \n"); } @Override public void handleException(SQLException arg0, String sql) throws SQLException { LOG.info("Sql returned error \n ======== \n" + sql + "\n ======== \n"); } }, null); } catch (IOException e) { LOG.error("Error when initializing SqlTool", e); } try { sqlFile.setConnection(dataSource.getConnection()); } catch (SQLException e) { LOG.error("Error is occured when setting connection", e); } try { sqlFile.execute(); } catch (SqlToolError e) { LOG.error("Error when creating user", e); } catch (SQLException e) { LOG.error("Error when creating user", e); } }
From source file:de.huberlin.german.korpling.laudatioteitool.App.java
public static void main(String[] args) { Options opts = new Options() .addOption(new Option("merge", true, messages.getString("MERGE CONTENT FROM INPUT DIRECTORY INTO ONE TEI HEADER"))) .addOption(new Option("split", true, messages.getString("SPLIT ONE TEI HEADER INTO SEVERAL HEADER FILES"))) .addOption(new Option("validate", true, messages.getString("VALIDATE DIRECTORY OR FILE"))) .addOption(new Option("config", true, messages.getString("CONFIG FILE LOCATION"))) .addOption(new Option("schemecorpus", true, messages.getString("CORPUS SCHEME LOCATION"))) .addOption(new Option("schemedoc", true, messages.getString("DOCUMENT SCHEME LOCATION"))) .addOption(new Option("schemeprep", true, messages.getString("PREPARATION SCHEME LOCATION"))) .addOption(new Option("help", false, messages.getString("SHOW THIS HELP"))); HelpFormatter fmt = new HelpFormatter(); String usage = "java -jar teitool.jar [options] [output directory/file]"; String header = messages.getString("HELP HEADER"); String footer = messages.getString("HELP FOOTER"); try {/* w w w . j a v a2 s. com*/ CommandLineParser cliParser = new PosixParser(); CommandLine cmd = cliParser.parse(opts, args); Properties props = new Properties(); if (cmd.hasOption("config")) { props = readConfig(cmd.getOptionValue("config")); } // end if "config" given fillPropertiesFromCommandLine(props, cmd); if (cmd.hasOption("help")) { fmt.printHelp(usage, header, opts, footer); } else if (cmd.hasOption("validate")) { validate(cmd.getOptionValue("validate"), props.getProperty("schemecorpus"), props.getProperty("schemedoc"), props.getProperty("schemeprep")); } else if (cmd.hasOption("merge")) { if (cmd.getArgs().length != 1) { System.out.println(messages.getString("YOU NEED TO GIVE AT AN OUTPUT FILE AS ARGUMENT")); System.exit(-1); } MergeTEI merge = new MergeTEI(new File(cmd.getOptionValue("merge")), new File(cmd.getArgs()[0]), props.getProperty("schemecorpus"), props.getProperty("schemedoc"), props.getProperty("schemeprep")); merge.merge(); System.exit(0); } else if (cmd.hasOption("split")) { if (cmd.getArgs().length != 1) { System.out.println(messages.getString("YOU NEED TO GIVE AT AN OUTPUT DIRECTORY AS ARGUMENT")); System.exit(-1); } SplitTEI split = new SplitTEI(new File(cmd.getOptionValue("split")), new File(cmd.getArgs()[0]), props.getProperty("schemecorpus"), props.getProperty("schemedoc"), props.getProperty("schemeprep")); split.split(); System.exit(0); } else { fmt.printHelp(usage, header, opts, footer); } } catch (ParseException ex) { System.err.println(ex.getMessage()); fmt.printHelp(usage, header, opts, footer); } catch (LaudatioException ex) { System.err.println(ex.getMessage()); } catch (UnsupportedOperationException ex) { System.err.println(ex.getMessage()); } System.exit(1); }
From source file:com.joseflavio.unhadegato.Concentrador.java
/** * @param args [0] = Diretrio de configuraes. *//* w ww . j a v a 2s .co m*/ public static void main(String[] args) { log.info(Util.getMensagem("unhadegato.iniciando")); try { /***********************/ if (args.length > 0) { if (!args[0].isEmpty()) { configuracao = new File(args[0]); if (!configuracao.isDirectory()) { String msg = Util.getMensagem("unhadegato.diretorio.incorreto"); System.out.println(msg); log.error(msg); System.exit(1); } } } if (configuracao == null) { configuracao = new File(System.getProperty("user.home") + File.separator + "unhadegato"); configuracao.mkdirs(); } log.info(Util.getMensagem("unhadegato.diretorio.endereco", configuracao.getAbsolutePath())); /***********************/ File confGeralArq = new File(configuracao, "unhadegato.conf"); if (!confGeralArq.exists()) { try (InputStream is = Concentrador.class.getResourceAsStream("/unhadegato.conf"); OutputStream os = new FileOutputStream(confGeralArq);) { IOUtils.copy(is, os); } } Properties confGeral = new Properties(); try (FileInputStream fis = new FileInputStream(confGeralArq)) { confGeral.load(fis); } String prop_porta = confGeral.getProperty("porta"); String prop_porta_segura = confGeral.getProperty("porta.segura"); String prop_seg_pri = confGeral.getProperty("seguranca.privada"); String prop_seg_pri_senha = confGeral.getProperty("seguranca.privada.senha"); String prop_seg_pri_tipo = confGeral.getProperty("seguranca.privada.tipo"); String prop_seg_pub = confGeral.getProperty("seguranca.publica"); String prop_seg_pub_senha = confGeral.getProperty("seguranca.publica.senha"); String prop_seg_pub_tipo = confGeral.getProperty("seguranca.publica.tipo"); if (StringUtil.tamanho(prop_porta) == 0) prop_porta = "8885"; if (StringUtil.tamanho(prop_porta_segura) == 0) prop_porta_segura = "8886"; if (StringUtil.tamanho(prop_seg_pri) == 0) prop_seg_pri = "servidor.jks"; if (StringUtil.tamanho(prop_seg_pri_senha) == 0) prop_seg_pri_senha = "123456"; if (StringUtil.tamanho(prop_seg_pri_tipo) == 0) prop_seg_pri_tipo = "JKS"; if (StringUtil.tamanho(prop_seg_pub) == 0) prop_seg_pub = "cliente.jks"; if (StringUtil.tamanho(prop_seg_pub_senha) == 0) prop_seg_pub_senha = "123456"; if (StringUtil.tamanho(prop_seg_pub_tipo) == 0) prop_seg_pub_tipo = "JKS"; /***********************/ File seg_pri = new File(prop_seg_pri); if (!seg_pri.isAbsolute()) seg_pri = new File(configuracao.getAbsolutePath() + File.separator + prop_seg_pri); if (seg_pri.exists()) { System.setProperty("javax.net.ssl.keyStore", seg_pri.getAbsolutePath()); System.setProperty("javax.net.ssl.keyStorePassword", prop_seg_pri_senha); System.setProperty("javax.net.ssl.keyStoreType", prop_seg_pri_tipo); } File seg_pub = new File(prop_seg_pub); if (!seg_pub.isAbsolute()) seg_pub = new File(configuracao.getAbsolutePath() + File.separator + prop_seg_pub); if (seg_pub.exists()) { System.setProperty("javax.net.ssl.trustStore", seg_pub.getAbsolutePath()); System.setProperty("javax.net.ssl.trustStorePassword", prop_seg_pub_senha); System.setProperty("javax.net.ssl.trustStoreType", prop_seg_pub_tipo); } /***********************/ new Thread() { File arquivo = new File(configuracao, "copaibas.conf"); long ultimaData = -1; @Override public void run() { while (true) { long data = arquivo.lastModified(); if (data > ultimaData) { executarCopaibas(arquivo); ultimaData = data; } try { Thread.sleep(5 * 1000); } catch (InterruptedException e) { return; } } } }.start(); /***********************/ log.info(Util.getMensagem("unhadegato.conexao.esperando")); log.info(Util.getMensagem("copaiba.porta.normal.abrindo", prop_porta)); Portal portal1 = new Portal(new SocketServidor(Integer.parseInt(prop_porta), false, true)); log.info(Util.getMensagem("copaiba.porta.segura.abrindo", prop_porta_segura)); Portal portal2 = new Portal(new SocketServidor(Integer.parseInt(prop_porta_segura), true, true)); portal1.start(); portal2.start(); portal1.join(); /***********************/ } catch (Exception e) { log.error(e.getMessage(), e); } finally { for (CopaibaGerenciador gerenciador : gerenciadores.values()) gerenciador.encerrar(); gerenciadores.clear(); gerenciadores = null; } }
From source file:eu.databata.engine.util.PropagatorRecreateUserTool.java
public static void main(String[] args) { if (args.length == 0) { printMessage();//from w ww. j a v a2s. c om return; } String scriptName = getScriptName(args[0]); if (scriptName == null) { printMessage(); return; } ClassLoader classLoader = PropagatorRecreateUserTool.class.getClassLoader(); InputStream resourceAsStream = classLoader.getResourceAsStream("databata.properties"); Properties propagatorProperties = new Properties(); try { propagatorProperties.load(resourceAsStream); } catch (FileNotFoundException e) { LOG.error("Sepecified file 'databata.properties' not found"); } catch (IOException e) { LOG.error("Sepecified file 'databata.properties' cannot be loaded"); } SingleConnectionDataSource dataSource = new SingleConnectionDataSource(); dataSource.setDriverClassName(propagatorProperties.getProperty("db.propagation.driver")); if ("-idb".equals(args[0])) { dataSource.setUrl(propagatorProperties.getProperty("db.propagation.dba.connection-url")); dataSource.setUsername(propagatorProperties.getProperty("db.propagation.dba.user")); dataSource.setPassword(propagatorProperties.getProperty("db.propagation.dba.password")); } else { dataSource.setUrl(propagatorProperties.getProperty("db.propagation.sa.connection-url")); dataSource.setUsername(propagatorProperties.getProperty("db.propagation.sa.user")); dataSource.setPassword(propagatorProperties.getProperty("db.propagation.sa.password")); } dataSource.setSuppressClose(true); String databaseName = "undefined"; try { databaseName = dataSource.getConnection().getMetaData().getDatabaseProductName(); } catch (SQLException e) { LOG.error("Cannot get connection by specified url", e); return; } String databaseCode = PropagationUtils.getDatabaseCode(databaseName); LOG.info("Database with code '" + databaseCode + "' is identified. for database '" + databaseName + "'"); String submitFileName = "META-INF/databata/" + databaseCode + "_" + scriptName + ".sql"; String fileContent = ""; try { fileContent = getFileContent(classLoader, submitFileName); } catch (IOException e) { LOG.info("File with name '" + submitFileName + "' cannot be read from classpath. Trying to load default submit file."); } if (fileContent == null || "".equals(fileContent)) { String defaultSubmitFileName = "META-INF/databata/" + databaseCode + "_" + scriptName + ".default.sql"; try { fileContent = getFileContent(classLoader, defaultSubmitFileName); } catch (IOException e) { LOG.info("File with name '" + defaultSubmitFileName + "' cannot be read from classpath. Trying to load default submit file."); } } if (fileContent == null) { LOG.info("File content is empty. Stopping process."); return; } fileContent = replacePlaceholders(fileContent, propagatorProperties); SqlFile sqlFile = null; try { sqlFile = new SqlFile(fileContent, null, submitFileName, new SqlExecutionCallback() { @Override public void handleExecuteSuccess(String sql, int arg1, double arg2) { LOG.info("Sql is sucessfully executed \n ======== \n" + sql + "\n ======== \n"); } @Override public void handleException(SQLException arg0, String sql) throws SQLException { LOG.info("Sql returned error \n ======== \n" + sql + "\n ======== \n"); } }, null); } catch (IOException e) { LOG.error("Error when initializing SqlTool", e); } try { sqlFile.setConnection(dataSource.getConnection()); } catch (SQLException e) { LOG.error("Error is occured when setting connection", e); } try { sqlFile.execute(); } catch (SqlToolError e) { LOG.error("Error when creating user", e); } catch (SQLException e) { LOG.error("Error when creating user", e); } }
From source file:dashboard.ImportCDN.java
public static void main(String[] args) { int n = 0;/* w ww .j a v a2s .c o m*/ String propertiesFileName = ""; // First argument - number of events to import if (args.length > 0) { try { n = Integer.parseInt(args[0]); } catch (NumberFormatException e) { System.err.println("First argument must be an integer"); System.exit(1); } } else { System.err.println("Please specify number of events to import."); System.exit(1); } // Second argument - properties file name if (args.length > 1) propertiesFileName = args[1]; else propertiesFileName = "gigaDashboard.properties"; // Read Properties file Properties prop = new Properties(); try { //load a properties file prop.load(new FileInputStream(propertiesFileName)); // Another option - load default properties from the Jar //prop.load(ImportCDN.class.getResourceAsStream("/gigaDashboard.properties")); //get the property values TOKEN = prop.getProperty("MIXPANEL_GIGA_PROJECT_TOKEN"); API_KEY = prop.getProperty("MIXPANEL_GIGA_API_KEY"); bucketName = prop.getProperty("S3_BUCKET_NAME"); AWS_USER = prop.getProperty("AWS_USER"); AWS_PASS = prop.getProperty("AWS_PASS"); DELETE_PROCESSED_LOGS = prop.getProperty("DELETE_PROCESSED_LOGS"); //System.out.println("MIXPANEL PROJECT TOKEN = " + TOKEN); //System.out.println("MIXPANEL API KEY = " + API_KEY); System.out.println("DELETE_PROCESSED_LOGS = " + DELETE_PROCESSED_LOGS); System.out.println("S3_BUCKET_NAME = " + prop.getProperty("S3_BUCKET_NAME")); //System.out.println("AWS_USER = " + prop.getProperty("AWS_USER")); //System.out.println("AWS_PASS = " + prop.getProperty("AWS_PASS")); System.out.println("==================="); } catch (IOException ex) { //ex.printStackTrace(); System.err.println("Can't find Propertie file - " + propertiesFileName); System.err.println("Second argument must be properties file name"); System.exit(1); } try { System.out.println("\n>>> Starting to import " + n + " events... \n"); readAmazonLogs(n); } catch (Exception e) { e.printStackTrace(); } }