Example usage for java.util Properties Properties

List of usage examples for java.util Properties Properties

Introduction

In this page you can find the example usage for java.util Properties Properties.

Prototype

public Properties() 

Source Link

Document

Creates an empty property list with no default values.

Usage

From source file:MondrianService.java

public static void main(String[] arg) {
    System.out.println("Starting Mondrian Connector for Infoveave");
    Properties prop = new Properties();
    InputStream input = null;//w  w  w  . ja v a2 s .c o  m
    int listenPort = 9998;
    int threads = 100;
    try {
        System.out.println("Staring from :" + getSettingsPath());
        input = new FileInputStream(getSettingsPath() + File.separator + "MondrianService.properties");
        prop.load(input);
        listenPort = Integer.parseInt(prop.getProperty("port"));
        threads = Integer.parseInt(prop.getProperty("maxThreads"));
        if (input != null) {
            input.close();
        }
        System.out.println("Found MondrianService.Properties");
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    }

    port(listenPort);
    threadPool(threads);
    enableCORS("*", "*", "*");

    ObjectMapper mapper = new ObjectMapper();
    MondrianConnector connector = new MondrianConnector();
    get("/ping", (request, response) -> {
        response.type("application/json");
        return "\"Here\"";
    });

    post("/cubes", (request, response) -> {
        response.type("application/json");
        try {
            Query queryObject = mapper.readValue(request.body(), Query.class);
            response.status(200);
            return mapper.writeValueAsString(connector.GetCubes(queryObject));
        } catch (JsonParseException ex) {
            response.status(400);
            return mapper.writeValueAsString(new Error(ex.getMessage()));
        } catch (Exception ex) {
            response.status(400);
            return mapper.writeValueAsString(new Error(ex.getMessage()));
        }
    });

    post("/measures", (request, response) -> {
        response.type("application/json");
        try {
            Query queryObject = mapper.readValue(request.body(), Query.class);
            response.status(200);
            return mapper.writeValueAsString(connector.GetMeasures(queryObject));
        } catch (JsonParseException ex) {
            response.status(400);
            return mapper.writeValueAsString(new Error(ex.getMessage()));
        } catch (Exception ex) {
            response.status(400);
            return mapper.writeValueAsString(new Error(ex.getMessage()));
        }
    });

    post("/dimensions", (request, response) -> {
        response.type("application/json");
        try {
            Query queryObject = mapper.readValue(request.body(), Query.class);
            response.status(200);
            return mapper.writeValueAsString(connector.GetDimensions(queryObject));
        } catch (JsonParseException ex) {
            response.status(400);
            return mapper.writeValueAsString(new Error(ex.getMessage()));
        } catch (Exception ex) {
            response.status(400);
            return mapper.writeValueAsString(new Error(ex.getMessage()));
        }
    });

    post("/cleanCache", (request, response) -> {
        response.type("application/json");
        try {
            Query queryObject = mapper.readValue(request.body(), Query.class);
            response.status(200);
            return mapper.writeValueAsString(connector.CleanCubeCache(queryObject));
        } catch (JsonParseException ex) {
            response.status(400);
            return mapper.writeValueAsString(new Error(ex.getMessage()));
        } catch (Exception ex) {
            response.status(400);
            return mapper.writeValueAsString(new Error(ex.getMessage()));
        }
    });

    post("/executeQuery", (request, response) -> {
        response.type("application/json");
        try {
            Query queryObject = mapper.readValue(request.body(), Query.class);
            response.status(200);
            String content = mapper.writeValueAsString(connector.ExecuteQuery2(queryObject));
            return content;
        } catch (JsonParseException ex) {
            response.status(400);
            return mapper.writeValueAsString(new Error(ex.getMessage()));
        } catch (Exception ex) {
            response.status(400);
            return mapper.writeValueAsString(new Error(ex.getMessage()));
        }
    });
}

From source file:com.shuzhilian.icu.license.LicenseGenerator.java

public static void main(String[] args) throws IOException, ParseException {
    if (args.length != 6) {
        System.out.println(/*  ww w.j  a v  a  2 s .c  om*/
                "Args: propties_file license_path license_name license_password private_key_file private_key_password");
        return;
    }
    String prop = args[0];
    String path = args[1];
    String name = args[2];
    String pawd = args[3];
    String pk = args[4];
    String pkpd = args[5];

    LicenseGenerator generator = new LicenseGenerator();
    generator.startUp(new File(pk), pkpd.toCharArray());

    Properties conf = new Properties();
    conf.load(new FileInputStream(new File(prop)));
    generator.generateLicense(path, name, pawd.toCharArray(), conf);
}

From source file:TerminalMonitor.java

static public void main(String args[]) {
    DriverPropertyInfo[] required;
    StringBuffer buffer = new StringBuffer();
    Properties props = new Properties();
    boolean connected = false;
    Driver driver;//w  w  w  . j a v a 2  s  .  c  o  m
    String url;
    int line = 1; // Mark current input line

    if (args.length < 1) {
        System.out.println("Syntax: <java -Djdbc.drivers=DRIVER_NAME " + "TerminalMonitor JDBC_URL>");
        return;
    }
    url = args[0];
    // We have to get a reference to the driver so we can
    // find out what values to prompt the user for in order
    // to make a connection.
    try {
        driver = DriverManager.getDriver(url);
    } catch (SQLException e) {
        e.printStackTrace();
        System.err.println("Unable to find a driver for the specified " + "URL.");
        System.err.println("Make sure you passed the jdbc.drivers " + "property on the command line to specify "
                + "the driver to be used.");
        return;
    }
    try {
        required = driver.getPropertyInfo(url, props);
    } catch (SQLException e) {
        e.printStackTrace();
        System.err.println("Unable to get driver property information.");
        return;
    }
    input = new BufferedReader(new InputStreamReader(System.in));
    // some drivers do not implement this properly
    // if that is the case, prompt for user name and password
    try {
        if (required.length < 1) {
            props.put("user", prompt("user: "));
            props.put("password", prompt("password: "));
        } else {
            // for each required attribute in the driver property info
            // prompt the user for the value
            for (int i = 0; i < required.length; i++) {
                if (!required[i].required) {
                    continue;
                }
                props.put(required[i].name, prompt(required[i].name + ": "));
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
        System.err.println("Unable to read property info.");
        return;
    }
    // Make the connection.
    try {
        connection = DriverManager.getConnection(url, props);
    } catch (SQLException e) {
        e.printStackTrace();
        System.err.println("Unable to connect to the database.");
    }
    connected = true;
    System.out.println("Connected to " + url);
    // Enter into a user input loop
    while (connected) {
        String tmp, cmd;

        // Print a prompt
        if (line == 1) {
            System.out.print("TM > ");
        } else {
            System.out.print(line + " -> ");
        }
        System.out.flush();
        // Get the next line of input
        try {
            tmp = input.readLine();
        } catch (java.io.IOException e) {
            e.printStackTrace();
            return;
        }
        // Get rid of extra space in the command
        cmd = tmp.trim();
        // The user wants to commit pending transactions
        if (cmd.equals("commit")) {
            try {
                connection.commit();
                System.out.println("Commit successful.");
            } catch (SQLException e) {
                System.out.println("Error in commit: " + e.getMessage());
            }
            buffer = new StringBuffer();
            line = 1;
        }
        // The user wants to execute the current buffer
        else if (cmd.equals("go")) {
            if (!buffer.equals("")) {
                try {
                    executeStatement(buffer);
                } catch (SQLException e) {
                    System.out.println(e.getMessage());
                }
            }
            buffer = new StringBuffer();
            line = 1;
            continue;
        }
        // The user wants to quit
        else if (cmd.equals("quit")) {
            connected = false;
            continue;
        }
        // The user wants to clear the current buffer
        else if (cmd.equals("reset")) {
            buffer = new StringBuffer();
            line = 1;
            continue;
        }
        // The user wants to abort a pending transaction
        else if (cmd.equals("rollback")) {
            try {
                connection.rollback();
                System.out.println("Rollback successful.");
            } catch (SQLException e) {
                System.out.println("An error occurred during rollback: " + e.getMessage());
            }
            buffer = new StringBuffer();
            line = 1;
        }
        // The user wants version info
        else if (cmd.startsWith("show")) {
            DatabaseMetaData meta;

            try {
                meta = connection.getMetaData();
                cmd = cmd.substring(5, cmd.length()).trim();
                if (cmd.equals("version")) {
                    showVersion(meta);
                } else {
                    System.out.println("show version"); // Bad arg
                }
            } catch (SQLException e) {
                System.out.println("Failed to load meta data: " + e.getMessage());
            }
            buffer = new StringBuffer();
            line = 1;
        }
        // The input that is not a keyword should appended be to the buffer
        else {
            buffer.append(" " + tmp);
            line++;
            continue;
        }
    }
    try {
        connection.close();
    } catch (SQLException e) {
        System.out.println("Error closing connection: " + e.getMessage());
    }
    System.out.println("Connection closed.");
}

From source file:com.jkoolcloud.client.samples.query.QueryData1.java

public static void main(String[] args) {
    try {/*from   w ww . j av  a  2  s .  co m*/
        Properties props = new Properties();
        props.setProperty(JKCmdOptions.PROP_URI, JKQuery.JKOOL_QUERY_URL);
        JKCmdOptions options = new JKCmdOptions(QueryData1.class, args, props);
        if (options.usage != null) {
            System.out.println(options.usage);
            System.exit(-1);
        }
        options.print();
        JKQuery jkQuery = new JKQuery(options.token);
        HttpResponse response = jkQuery.get(options.query);
        System.out.println(EntityUtils.toString(response.getEntity()));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.semsaas.utils.anyurl.App.java

public static void main(String[] rawArgs) throws Exception {
    Properties props = new Properties();
    String args[] = processOption(rawArgs, props);

    String outputFile = props.getProperty("output");
    OutputStream os = outputFile == null ? System.out : new FileOutputStream(outputFile);

    final org.apache.camel.spring.Main main = new org.apache.camel.spring.Main();
    main.setApplicationContextUri("classpath:application.xml");

    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            try {
                main.stop();/*w w  w  . ja va  2s .c o m*/
            } catch (Exception e) {
            }
        }
    });

    if (args.length > 0) {
        main.start();
        if (main.isStarted()) {
            CamelContext camelContext = main.getCamelContexts().get(0);

            String target = rewriteEndpoint(args[0]);
            boolean producerBased = checkProducerBased(target);

            InputStream is = null;
            if (producerBased) {
                ProducerTemplate producer = camelContext.createProducerTemplate();
                is = producer.requestBody(target, null, InputStream.class);
            } else {
                ConsumerTemplate consumer = camelContext.createConsumerTemplate();
                is = consumer.receiveBody(target, InputStream.class);
            }
            IOUtils.copy(is, os);

            main.stop();
        } else {
            System.err.println("Couldn't trigger jobs, camel wasn't started");
        }
    } else {
        logger.info("No triggers. Running indefintely");
    }
}

From source file:com.alibaba.otter.manager.deployer.OtterManagerLauncher.java

public static void main(String[] args) throws Throwable {
    try {/* www . j  a va 2 s  .c o  m*/
        String conf = System.getProperty("otter.conf", "classpath:otter.properties");
        Properties properties = new Properties();
        if (conf.startsWith(CLASSPATH_URL_PREFIX)) {
            conf = StringUtils.substringAfter(conf, CLASSPATH_URL_PREFIX);
            properties.load(OtterManagerLauncher.class.getClassLoader().getResourceAsStream(conf));
        } else {
            properties.load(new FileInputStream(conf));
        }

        // ??system?
        mergeProps(properties);

        logger.info("## start the manager server.");
        final JettyEmbedServer server = new JettyEmbedServer(
                properties.getProperty("otter.jetty", "jetty.xml"));
        server.start();
        logger.info("## the manager server is running now ......");
        Runtime.getRuntime().addShutdownHook(new Thread() {

            public void run() {
                try {
                    logger.info("## stop the manager server");
                    server.join();
                } catch (Throwable e) {
                    logger.warn("##something goes wrong when stopping manager Server:\n{}",
                            ExceptionUtils.getFullStackTrace(e));
                } finally {
                    logger.info("## manager server is down.");
                }
            }

        });
    } catch (Throwable e) {
        logger.error("## Something goes wrong when starting up the manager Server:\n{}",
                ExceptionUtils.getFullStackTrace(e));
        System.exit(0);
    }
}

From source file:GetDBInfo.java

public static void main(String[] args) {
    Connection c = null; // The JDBC connection to the database server
    try {//  w  w w. j ava  2s .com
        // Look for the properties file DB.props in the same directory as
        // this program. It will contain default values for the various
        // parameters needed to connect to a database
        Properties p = new Properties();
        try {
            p.load(GetDBInfo.class.getResourceAsStream("DB.props"));
        } catch (Exception e) {
        }

        // Get default values from the properties file
        String driver = p.getProperty("driver"); // Driver class name
        String server = p.getProperty("server", ""); // JDBC URL for server
        String user = p.getProperty("user", ""); // db user name
        String password = p.getProperty("password", ""); // db password

        // These variables don't have defaults
        String database = null; // The db name (appended to server URL)
        String table = null; // The optional name of a table in the db

        // Parse the command-line args to override the default values above
        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-d"))
                driver = args[++i]; //-d <driver>
            else if (args[i].equals("-s"))
                server = args[++i];//-s <server>
            else if (args[i].equals("-u"))
                user = args[++i]; //-u <user>
            else if (args[i].equals("-p"))
                password = args[++i];
            else if (database == null)
                database = args[i]; // <dbname>
            else if (table == null)
                table = args[i]; // <table>
            else
                throw new IllegalArgumentException("Unknown argument: " + args[i]);
        }

        // Make sure that at least a server or a database were specified.
        // If not, we have no idea what to connect to, and cannot continue.
        if ((server.length() == 0) && (database.length() == 0))
            throw new IllegalArgumentException("No database specified.");

        // Load the db driver, if any was specified.
        if (driver != null)
            Class.forName(driver);

        // Now attempt to open a connection to the specified database on
        // the specified server, using the specified name and password
        c = DriverManager.getConnection(server + database, user, password);

        // Get the DatabaseMetaData object for the connection. This is the
        // object that will return us all the data we're interested in here
        DatabaseMetaData md = c.getMetaData();

        // Display information about the server, the driver, etc.
        System.out.println("DBMS: " + md.getDatabaseProductName() + " " + md.getDatabaseProductVersion());
        System.out.println("JDBC Driver: " + md.getDriverName() + " " + md.getDriverVersion());
        System.out.println("Database: " + md.getURL());
        System.out.println("User: " + md.getUserName());

        // Now, if the user did not specify a table, then display a list of
        // all tables defined in the named database. Note that tables are
        // returned in a ResultSet, just like query results are.
        if (table == null) {
            System.out.println("Tables:");
            ResultSet r = md.getTables("", "", "%", null);
            while (r.next())
                System.out.println("\t" + r.getString(3));
        }

        // Otherwise, list all columns of the specified table.
        // Again, information about the columns is returned in a ResultSet
        else {
            System.out.println("Columns of " + table + ": ");
            ResultSet r = md.getColumns("", "", table, "%");
            while (r.next())
                System.out.println("\t" + r.getString(4) + " : " + r.getString(6));
        }
    }
    // Print an error message if anything goes wrong.
    catch (Exception e) {
        System.err.println(e);
        if (e instanceof SQLException)
            System.err.println(((SQLException) e).getSQLState());
        System.err.println("Usage: java GetDBInfo [-d <driver] " + "[-s <dbserver>]\n"
                + "\t[-u <username>] [-p <password>] <dbname>");
    }
    // Always remember to close the Connection object when we're done!
    finally {
        try {
            c.close();
        } catch (Exception e) {
        }
    }
}

From source file:sample.jetty.SampleJettyApplication.java

public static void main(String[] args) throws Exception {
    InputStream inputstream = null;
    try {/* w ww . j  a  va  2 s.com*/
        Properties pro = new Properties();
        //?????
        URL url = org.springframework.util.ResourceUtils.getURL("classpath:MySql_general.properties");
        inputstream = url.openStream();
        pro.load(inputstream);
        //new EmbedMySqlServer(pro).startup();

        String dbPath = (new File("")).getAbsolutePath() + "/db/";
        dbPath = dbPath.replaceAll("\\\\", "/");
        //???
        EmbedMySqlServer mysqldbServer = new EmbedMySqlServer(pro, dbPath /*"C:\\gfworklog\\db\\"*/);

        SampleJettyApplication.MAIN_THREAD_LOCAL.put("embedMysqlServer", mysqldbServer);

        mysqldbServer.startup();

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            inputstream.close();
        } catch (Exception ex) {
        }
    }
    System.out.println(Thread.currentThread().getName() + " ========================= " + 1
            + " =========================");
    ConfigurableApplicationContext cac = SpringApplication.run(SampleJettyApplication.class, args);

}

From source file:com.magnet.mmx.util.DatabaseExport.java

public static void main(String[] args) throws Exception {
    InputStream inputStream = DeviceDAOImplTest.class.getResourceAsStream("/test.properties");

    Properties testProperties = new Properties();
    testProperties.load(inputStream);/*from  w ww.  j  a va  2s. co  m*/

    String host = testProperties.getProperty("db.host");
    String port = testProperties.getProperty("db.port");
    String user = testProperties.getProperty("db.user");
    String password = testProperties.getProperty("db.password");
    String driver = testProperties.getProperty("db.driver");
    String schema = testProperties.getProperty("db.schema");

    String url = "jdbc:mysql://" + host + ":" + port + "/" + schema;

    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(driver);
    ds.setUsername(user);
    ds.setPassword(password);
    ds.setUrl(url);
    TreeMap<String, String> map = new TreeMap<String, String>();
    map.put("mmxTag", "SELECT * FROM mmxTag ");
    doWork(ds.getConnection(), map);
}

From source file:com.netflix.suro.client.example.SuroClient4Test.java

public static void main(String[] args) throws JsonProcessingException, InterruptedException {
    // ip num_of_messages message_size sleep num_of_iterations
    String ip = args[0];/*from  w ww. j  a  va 2s.c om*/
    int numMessages = Integer.parseInt(args[1]);
    int messageSize = Integer.parseInt(args[2]);
    int sleep = Integer.parseInt(args[3]);
    int numIterations = Integer.parseInt(args[4]);

    Properties props = new Properties();
    props.setProperty(ClientConfig.LB_TYPE, "static");
    props.setProperty(ClientConfig.LB_SERVER, ip);

    SuroClient client = new SuroClient(props);
    byte[] payload = createMessagePayload(messageSize);
    for (int n = 0; n < numIterations; ++n) {
        for (int i = 0; i < numMessages; ++i) {
            client.send(new Message(i % 2 == 0 ? "request_trace" : "nf_errors_log", payload));
        }
        Thread.sleep(sleep);
    }
    client.shutdown();
}