List of usage examples for java.util Properties getProperty
public String getProperty(String key)
From source file:com.mobius.software.mqtt.performance.controller.ControllerRunner.java
public static void main(String[] args) { try {//from w w w . j a va2 s . co m /*URI baseURI = URI.create(args[0].replace("-baseURI=", "")); configFile = args[1].replace("-configFile=", "");*/ String userDir = System.getProperty("user.dir"); System.out.println("user.dir: " + userDir); setConfigFilePath(userDir + "/config.properties"); Properties prop = new Properties(); prop.load(new FileInputStream(configFile)); System.out.println("properties loaded..."); String hostname = prop.getProperty("hostname"); Integer port = Integer.parseInt(prop.getProperty("port")); URI baseURI = new URI(null, null, hostname, port, null, null, null); configureConsoleLogger(); System.out.println("starting http server..."); JerseyServer server = new JerseyServer(baseURI); System.out.println("http server started"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("press any key to stop: "); br.readLine(); server.terminate(); } catch (Throwable e) { logger.error("AN ERROR OCCURED: " + e.getMessage()); e.printStackTrace(); } finally { System.exit(0); } }
From source file:TypeMapDemo.java
public static void main(String[] args) throws IOException, ClassNotFoundException, SQLException { Properties p = new Properties(); p.load(new FileInputStream("db.properties")); Class c = Class.forName(p.getProperty("db.driver")); System.out.println("Loaded driverClass " + c.getName()); Connection con = DriverManager.getConnection(p.getProperty("db.url"), "student", "student"); System.out.println("Got Connection " + con); Statement s = con.createStatement(); int ret;/*from w w w. j av a2s. com*/ try { s.executeUpdate("drop table MR"); s.executeUpdate("drop type MUSICRECORDING"); } catch (SQLException andDoNothingWithIt) { // Should use "if defined" but not sure it works for UDTs... } ret = s.executeUpdate("create type MUSICRECORDING as object (" + " id integer," + " title varchar(20), " + " artist varchar(20) " + ")"); System.out.println("Created TYPE! Ret=" + ret); ret = s.executeUpdate("create table MR of MUSICRECORDING"); System.out.println("Created TABLE! Ret=" + ret); int nRows = s.executeUpdate("insert into MR values(123, 'Greatest Hits', 'Ian')"); System.out.println("inserted " + nRows + " rows"); // Put the data class into the connection's Type Map // If the data class were not an inner class, // this would likely be done with Class.forName(...); Map map = con.getTypeMap(); map.put("MUSICRECORDING", MusicRecording.class); con.setTypeMap(map); ResultSet rs = s.executeQuery("select * from MR where id = 123"); //"select musicrecording(id,artist,title) from mr"); rs.next(); for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { Object o = rs.getObject(i); System.out.print(o + "(Type " + o.getClass().getName() + ")\t"); } System.out.println(); }
From source file:dhtaccess.tools.Put.java
public static void main(String[] args) { byte[] secret = null; int ttl = 3600; // parse properties Properties prop = System.getProperties(); String gateway = prop.getProperty("dhtaccess.gateway"); if (gateway == null || gateway.length() <= 0) { gateway = DEFAULT_GATEWAY;/*from w w w. ja v a 2s . c o m*/ } // parse options Options options = new Options(); options.addOption("h", "help", false, "print help"); options.addOption("g", "gateway", true, "gateway URI, list at http://opendht.org/servers.txt"); options.addOption("s", "secret", true, "can be used to remove the value later"); options.addOption("t", "ttl", true, "how long (in seconds) to store the value"); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.out.println("There is an invalid option."); e.printStackTrace(); System.exit(1); } String optVal; if (cmd.hasOption('h')) { usage(COMMAND); System.exit(1); } optVal = cmd.getOptionValue('g'); if (optVal != null) { gateway = optVal; } optVal = cmd.getOptionValue('s'); if (optVal != null) { try { secret = optVal.getBytes(ENCODE); } catch (UnsupportedEncodingException e) { // NOTREACHED } } optVal = cmd.getOptionValue('t'); if (optVal != null) { ttl = Integer.parseInt(optVal); } args = cmd.getArgs(); // parse arguments if (args.length < 2) { usage(COMMAND); System.exit(1); } for (int index = 0; index + 1 < args.length; index += 2) { byte[] key = null, value = null; try { key = args[index].getBytes(ENCODE); value = args[index + 1].getBytes(ENCODE); } catch (UnsupportedEncodingException e1) { // NOTREACHED } // prepare for RPC DHTAccessor accessor = null; try { accessor = new DHTAccessor(gateway); } catch (MalformedURLException e) { e.printStackTrace(); System.exit(1); } // RPC int res = accessor.put(key, value, ttl, secret); String resultString; switch (res) { case 0: resultString = "Success"; break; case 1: resultString = "Capacity"; break; case 2: resultString = "Again"; break; default: resultString = "???"; } System.out.println(resultString + ": " + args[index] + ", " + args[index + 1]); } }
From source file:fi.laverca.examples.EtsiSign.java
/** * The main method/*from ww w . jav a2 s . com*/ * @param args */ public static void main(String[] args) { // Load properties Properties properties = ExampleConf.getProperties(); // Setup SSL log.info("Setting up ssl"); JvmSsl.setSSL(properties.getProperty(ExampleConf.TRUSTSTORE_FILE), properties.getProperty(ExampleConf.TRUSTSTORE_PASSWORD), properties.getProperty(ExampleConf.KEYSTORE_FILE), properties.getProperty(ExampleConf.KEYSTORE_PASSWORD), properties.getProperty(ExampleConf.KEYSTORE_TYPE)); String apId = properties.getProperty(ExampleConf.AP_ID); String apPwd = properties.getProperty(ExampleConf.AP_PASSWORD); // Setup service URLs String msspSignatureUrl = properties.getProperty(ExampleConf.SIGNATURE_URL); String msspStatusUrl = properties.getProperty(ExampleConf.STATUS_URL); String msspReceiptUrl = properties.getProperty(ExampleConf.RECEIPT_URL); // Create client MssClient etsiClient = new MssClient(apId, apPwd, msspSignatureUrl, msspStatusUrl, msspReceiptUrl); String apTransId = "A" + System.currentTimeMillis(); String msisdn = "+35847001001"; // Create DataToBeSigned DTBS dtbs = new DTBS("sign this", DTBS.ENCODING_UTF8); MSS_SignatureReq sigReq = etsiClient.createSignatureRequest(apTransId, // AP Transaction ID msisdn, // MSISDN dtbs, // Data to be signed null, // Data to be displayed SignatureProfiles.FICOM_SIGNATURE, // Signature profile MSS_Formats.PKCS7, // MSS Format MessagingModeType.SYNCH); // Messaging Mode MSS_SignatureResp sigResp = null; try { sigResp = etsiClient.send(sigReq); } catch (AxisFault af) { log.error("Got SOAP fault", af); return; } catch (IOException ioe) { log.error("Got IOException ", ioe); return; } log.info("Got response"); log.info(" StatusCode : " + sigResp.getStatus().getStatusCode().getValue()); log.info(" StatusMessage: " + sigResp.getStatus().getStatusMessage()); }
From source file:dhtaccess.tools.Get.java
public static void main(String[] args) { boolean details = false; // parse properties Properties prop = System.getProperties(); String gateway = prop.getProperty("dhtaccess.gateway"); if (gateway == null || gateway.length() <= 0) { gateway = DEFAULT_GATEWAY;//from ww w .j a va 2s. c o m } // parse options Options options = new Options(); options.addOption("h", "help", false, "print help"); options.addOption("g", "gateway", true, "gateway URI, list at http://opendht.org/servers.txt"); options.addOption("d", "details", false, "print secret hash and TTL"); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.out.println("There is an invalid option."); e.printStackTrace(); System.exit(1); } String optVal; if (cmd.hasOption('h')) { usage(COMMAND); System.exit(1); } optVal = cmd.getOptionValue('g'); if (optVal != null) { gateway = optVal; } if (cmd.hasOption('d')) { details = true; } args = cmd.getArgs(); // parse arguments if (args.length < 1) { usage(COMMAND); System.exit(1); } // prepare for RPC DHTAccessor accessor = null; try { accessor = new DHTAccessor(gateway); } catch (MalformedURLException e) { e.printStackTrace(); System.exit(1); } for (int index = 0; index < args.length; index++) { byte[] key = null; try { key = args[index].getBytes(ENCODE); } catch (UnsupportedEncodingException e1) { // NOTREACHED } // RPC if (args.length > 1) { System.out.println(args[index] + ":"); } if (details) { Set<DetailedGetResult> results = accessor.getDetails(key); for (DetailedGetResult r : results) { String valString = null; try { valString = new String((byte[]) r.getValue(), ENCODE); } catch (UnsupportedEncodingException e) { // NOTREACHED } BigInteger hashedSecure = new BigInteger(1, (byte[]) r.getHashedSecret()); System.out.println(valString + " " + r.getTTL() + " " + r.getHashType() + " 0x" + ("0000000" + hashedSecure.toString(16)).substring(0, 8)); } } else { Set<byte[]> results = accessor.get(key); for (byte[] valBytes : results) { try { System.out.println(new String((byte[]) valBytes, ENCODE)); } catch (UnsupportedEncodingException e) { // NOTREACHED } } } } // for (int index = 0... }
From source file:Main.java
public static void main(String[] args) throws Exception { Properties prop = new Properties(); prop.put("Chapter Count", "200"); prop.put("Tutorial Count", "150"); prop.put("tutorial", "java2s.com"); prop.put("Runnable", "true"); // get two properties and print them System.out.println(prop.getProperty("Runnable")); System.out.println(prop.getProperty("Tutorial Count")); }
From source file:PersistentEcho.java
public static void main(String[] args) { String argString = ""; boolean notProperty = true; // Are there arguments? // If so retrieve them. if (args.length > 0) { for (String arg : args) { argString += arg + " "; }/*from www .ja va 2 s .c om*/ argString = argString.trim(); } // No arguments, is there // an environment variable? // If so, //retrieve it. else if ((argString = System.getenv("PERSISTENTECHO")) != null) { } // No environment variable // either. Retrieve property value. else { notProperty = false; // Set argString to null. // If it's still null after // we exit the try block, // we've failed to retrieve // the property value. argString = null; FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream("PersistentEcho.txt"); Properties inProperties = new Properties(); inProperties.load(fileInputStream); argString = inProperties.getProperty("argString"); } catch (IOException e) { System.err.println("Can't read property file."); System.exit(1); } finally { if (fileInputStream != null) { try { fileInputStream.close(); } catch (IOException e) { } ; } } } if (argString == null) { System.err.println("Couldn't find argString property"); System.exit(1); } // Somehow, we got the // value. Echo it already! System.out.println(argString); // If we didn't retrieve the // value from the property, // save it //in the property. if (notProperty) { Properties outProperties = new Properties(); outProperties.setProperty("argString", argString); FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream("PersistentEcho.txt"); outProperties.store(fileOutputStream, "PersistentEcho properties"); } catch (IOException e) { } finally { if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException e) { } ; } } } }
From source file:net.tirasa.olingooauth2.Main.java
public static void main(final String[] args) throws Exception { final Properties oauth2Properties = new Properties(); oauth2Properties.load(Main.class.getResourceAsStream("/oauth2.properties")); final AzureADOAuth2HttpClientFactory oauth2HCF = new AzureADOAuth2HttpClientFactory( oauth2Properties.getProperty("oauth2.authority"), oauth2Properties.getProperty("oauth2.clientId"), oauth2Properties.getProperty("oauth2.redirectURI"), oauth2Properties.getProperty("oauth2.resourceURI"), new UsernamePasswordCredentials(oauth2Properties.getProperty("oauth2.username"), oauth2Properties.getProperty("oauth2.password"))); final ODataClient client = ODataClientFactory.getEdmEnabledV4("https://outlook.office365.com/ews/odata"); client.getConfiguration().setHttpClientFactory(oauth2HCF); final ODataEntitySetRequest<ODataEntitySet> messages = client.getRetrieveRequestFactory() .getEntitySetRequest(//from w ww .j a v a 2 s .c om URI.create("https://outlook.office365.com/ews/odata/Me/Folders('Inbox')/Messages")); for (ODataEntity message : messages.execute().getBody().getEntities()) { System.out.println("Message: " + message.getId()); } }
From source file:org.atomserver.utils.jetty.StandAloneAtomServer.java
public static void main(String[] args) throws Exception { // the System Property "atomserver.home" defines the home directory for the standalone app String atomserverHome = System.getProperty("atomserver.home"); if (StringUtils.isEmpty(atomserverHome)) { log.error("The variable \"atomserver.home\" must be defined"); System.exit(-1);//from w w w. j a v a 2 s .c o m } File atomserverHomeDir = new File(atomserverHome); if (!atomserverHomeDir.exists() && !atomserverHomeDir.isDirectory()) { log.error("The variable \"atomserver.home\" (" + atomserverHome + ") must point to a directory that exists"); } // instantiate the Jetty Server Server server = new Server(); // create a new connector on the declared port, and set it onto the server log.debug("atomserver.port = " + System.getProperty("atomserver.port")); Connector connector = new SelectChannelConnector(); connector.setPort(Integer.getInteger("atomserver.port", DEFAULT_PORT)); server.setConnectors(new Connector[] { connector }); // create a ClassLoader that points at the conf directories log.debug("atomserver.conf.dir = " + System.getProperty("atomserver.conf.dir")); log.debug("atomserver.ops.conf.dir = " + System.getProperty("atomserver.ops.conf.dir")); ClassLoader classLoader = new ConfigurationAwareClassLoader(StandAloneAtomServer.class.getClassLoader()); // load the version from the version.properties file Properties versionProps = new Properties(); versionProps.load(classLoader.getResourceAsStream(DEFAULT_VERSIONS_FILE)); String version = versionProps.getProperty("atomserver.version"); // create a new webapp, rooted at webapps/atomserver-${version}, with the configured // context name String servletContextName = System.getProperty("atomserver.servlet.context"); log.debug("atomserver.servlet.context = " + servletContextName); WebAppContext webapp = new WebAppContext(atomserverHome + "/webapps/atomserver-" + version, "/" + servletContextName); // set the webapp's ClassLoader to be the one that loaded THIS class. the REASON that // this needs to be set is so that when we extract the web application context below we can // cast it to WebApplicationContext here webapp.setClassLoader(StandAloneAtomServer.class.getClassLoader()); // set the Jetty server's webapp and start it server.setHandler(webapp); server.start(); // if the seed system property was set, use the DBSeeder to populate the server String seedDB = System.getProperty("seed.database.with.pets"); log.debug("seed.database.with.pets = " + seedDB); if (!StringUtils.isEmpty(seedDB)) { if (Boolean.valueOf(seedDB)) { Thread.sleep(2000); WebApplicationContext webappContext = WebApplicationContextUtils .getWebApplicationContext(webapp.getServletContext()); DBSeeder.getInstance(webappContext).seedPets(); } } server.join(); }
From source file:com.taobao.tddl.common.util.CountPunisher.java
public static void main(String[] args) { {//from w w w. jav a 2s. co m SmoothValve smoothValve = new SmoothValve(20); String config = "CountPunisherProperties=limit=20\\r\\ntimeWindow=3000"; Properties p = ConfigServerHelper.parseProperties(config, "[tddlConfigListener]"); String punisherConfig = p.getProperty("CountPunisherProperties"); CountPunisher countPunisher = CountPunisher.parse(smoothValve, punisherConfig); System.out.println(countPunisher); } { SmoothValve smoothValve = new SmoothValve(20); String config = "CountPunisherProperties=limit=20@@@timeWindow=3000"; Properties p = ConfigServerHelper.parseProperties(config, "[tddlConfigListener]"); String punisherConfig = p.getProperty("CountPunisherProperties"); CountPunisher countPunisher = CountPunisher.parse(smoothValve, punisherConfig); System.out.println(countPunisher); } { SmoothValve smoothValve = new SmoothValve(20); String config = "CountPunisherProperties=limit=20;;;timeWindow=3000"; Properties p = ConfigServerHelper.parseProperties(config, "[tddlConfigListener]"); String punisherConfig = p.getProperty("CountPunisherProperties"); CountPunisher countPunisher = CountPunisher.parse(smoothValve, punisherConfig); System.out.println(countPunisher); } }