Example usage for java.lang System setProperty

List of usage examples for java.lang System setProperty

Introduction

In this page you can find the example usage for java.lang System setProperty.

Prototype

public static String setProperty(String key, String value) 

Source Link

Document

Sets the system property indicated by the specified key.

Usage

From source file:com.discursive.jccook.httpclient.BasicAuthExample.java

public static void main(String[] args) throws HttpException, IOException {
    // Configure Logging
    System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
    System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
    System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug");

    HttpClient client = new HttpClient();
    HttpState state = client.getState();
    HttpClientParams params = client.getParams();

    // Set credentials on the client
    Credentials credentials = new UsernamePasswordCredentials("testuser", "crazypass");
    state.setCredentials(null, null, credentials);
    params.setAuthenticationPreemptive(true);

    String url = "http://www.discursive.com/jccook/auth/";
    HttpMethod method = new GetMethod(url);

    client.executeMethod(method);// w  w w.  ja v  a2 s  .co m
    String response = method.getResponseBodyAsString();

    System.out.println(response);
    method.releaseConnection();
}

From source file:org.spring.data.gemfire.app.main.SpringGemFireDataServer.java

public static void main(final String[] args) {
    System.setProperty("gemfire.name", SpringGemFireDataServer.class.getSimpleName());
    SpringApplication.run(SpringGemFireDataServer.class, args);
}

From source file:io.apiman.servers.gateway_es.Starter.java

/**
 * Main entry point for the API Gateway micro service.
 * @param args the arguments//from ww w .  j ava2  s  .  co  m
 * @throws Exception when any unhandled exception occurs
 */
public static final void main(String[] args) throws Exception {
    URL resource = Starter.class.getClassLoader().getResource("users.list"); //$NON-NLS-1$
    if (resource != null) {
        System.setProperty(Users.USERS_FILE_PROP, resource.toString());
    }

    loadProperties();
    GatewayMicroService microService = new GatewayMicroService();
    microService.start();
    microService.join();
}

From source file:com.reversemind.glia.test.go3.java

public static void main(String... args) throws Exception {

    System.setProperty("http.proxyHost", "10.105.0.217");
    System.setProperty("http.proxyPort", "3128");

    System.setProperty("https.proxyHost", "10.105.0.217");
    System.setProperty("https.proxyPort", "3128");

    HttpHost proxy = new HttpHost("10.105.0.217", 3128);
    DefaultHttpClient client = new DefaultHttpClient();
    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

    HttpGet request = new HttpGet(
            "https://twitter.com/i/profiles/show/splix/timeline/with_replies?include_available_features=1&include_entities=1&max_id=285605679744569344");
    HttpResponse response = client.execute(request);

    // Get the response
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));

    String sl = "";
    String line = "";
    while ((line = rd.readLine()) != null) {
        LOG.debug(line);/* ww w .ja  v a2 s  .  c o  m*/
        sl += line;
    }

    sl = new String(sl.getBytes(), "UTF-8");
    String sss = sl.replaceAll("\\{1,}", "\\").replaceAll("\\\"", "'").replaceAll("\\"", "'")
            .replaceAll("&gt;", ">").replaceAll("&lt;", "<").replaceAll("&amp;", "&").replaceAll("&apos;", "'")
            .replaceAll("\u003c", "<").replaceAll("\u003e", ">").replaceAll("\n", " ").replaceAll("\\/", "/")
            .replaceAll("\\'", "'");

    String sss2 = sss.replaceAll("\\'", "'");
    LOG.debug(sss);

    save("/opt/_del/go_sl.txt", sl);
    save("/opt/_del/go_sss.txt", sss);
    save("/opt/_del/go_line.txt", line);
    save("/opt/_del/go_sss2.txt", sss2);

    LOG.debug("\n\n\n\n\n");
    LOG.debug(sss);
    LOG.debug("\n\n\n\n\n");
    LOG.debug(URLDecoder.decode(sl, "UTF-8"));
    LOG.debug(URLDecoder.decode("\u0438\u043d\u043e\u0433\u0434\u0430", "UTF-8"));

    LOG.debug(URLDecoder.decode("\n            \u003c/span\u003e\n            \u003cb\u003e\n ", "UTF-8"));

}

From source file:logClient.LogClient.java

public static void main(String[] args) {

    PropertyConfigurator.configure(Constants.LOG4J_PROPERTY_PATH);

    System.setProperty("javax.net.ssl.trustStore", Constants.TRUST_STORE_PATH);
    System.setProperty("javax.net.ssl.trustStorePassword", Constants.TRUST_STORE_PASSWORD);

    LogClient logClient = new LogClient();
    logClient.processConf();/*from  w ww .j  ava  2s  .co  m*/
    logClient.setupBam();
    logClient.getPathList();

    try {
        FileTracker watchService = new FileTracker(FileTracker.regPaths);
        watchService.processEvents();
    } catch (IOException e) {
        log.fatal("Error initializing file watch client -" + e.getMessage(), e);
        log.fatal("Log client is Exiting..");
        System.exit(-1);
    }
}

From source file:edu.snu.leader.discrete.simulator.Main.java

public static void main(String[] args) {
    System.setProperty("sim-properties", "cfg/sim/discrete/sim-properties.parameters");

    _simulationProperties = MiscUtils.loadProperties("sim-properties");

    String stringShouldRunGraphical = _simulationProperties.getProperty("run-graphical");
    Validate.notEmpty(stringShouldRunGraphical, "Run graphical option required");
    shouldRunGraphical = Boolean.parseBoolean(stringShouldRunGraphical);

    String stringTotalRuns = _simulationProperties.getProperty("run-count");
    Validate.notEmpty(stringTotalRuns, "Run count required");
    totalRuns = Integer.parseInt(stringTotalRuns);

    if (!shouldRunGraphical) {
        // run just text
        for (int run = 1; run <= totalRuns; run++) {
            System.out.println("Run " + run);
            System.out.println();

            // create and initialize simulator
            Simulator simulator = new Simulator(run);
            _simulationProperties.put("current-run", String.valueOf(run));
            simulator.initialize(_simulationProperties);
            // run it
            simulator.execute();//from   w w w.  ja  v a  2  s  .  c o m
        }
    } else {
        // run graphical
        DebugLocationsStructure db = new DebugLocationsStructure("Conflict Simulation", 800, 600, 60);
        _simulationProperties.put("current-run", String.valueOf(1));
        db.initialize(_simulationProperties, 1);
        db.run();
    }
}

From source file:Pong.java

public static void main(String... args) throws Exception {
    System.setProperty("os.max.pid.bits", "16");

    Options options = new Options();
    options.addOption("i", true, "Input chronicle path");
    options.addOption("n", true, "Number of entries to write");
    options.addOption("w", true, "Number of writer threads");
    options.addOption("r", true, "Number of reader threads");
    options.addOption("x", false, "Delete the output chronicle at startup");

    CommandLine cmd = new DefaultParser().parse(options, args);
    final Path output = Paths.get(cmd.getOptionValue("o", "/tmp/__test/chr"));
    final long maxCount = Long.parseLong(cmd.getOptionValue("n", "10000000"));
    final int writerThreadCount = Integer.parseInt(cmd.getOptionValue("w", "4"));
    final int readerThreadCount = Integer.parseInt(cmd.getOptionValue("r", "4"));
    final boolean deleteOnStartup = cmd.hasOption("x");

    if (deleteOnStartup) {
        FileUtil.removeRecursive(output);
    }//www . ja v a 2  s.co m

    final Chronicle chr = ChronicleQueueBuilder.vanilla(output.toFile()).build();

    final ExecutorService executor = Executors.newFixedThreadPool(4);
    final List<Future<?>> futures = new ArrayList<>();

    final long totalCount = writerThreadCount * maxCount;
    final long t0 = System.nanoTime();

    for (int i = 0; i != readerThreadCount; ++i) {
        final int tid = i;
        futures.add(executor.submit((Runnable) () -> {
            try {
                IntLongMap counts = HashIntLongMaps.newMutableMap();
                ExcerptTailer tailer = chr.createTailer();

                final StringBuilder sb1 = new StringBuilder();
                final StringBuilder sb2 = new StringBuilder();

                long count = 0;
                while (count != totalCount) {
                    if (!tailer.nextIndex())
                        continue;
                    final int id = tailer.readInt();
                    final long val = tailer.readStopBit();
                    final long longValue = tailer.readLong();
                    sb1.setLength(0);
                    sb2.setLength(0);
                    tailer.read8bitText(sb1);
                    tailer.read8bitText(sb2);
                    if (counts.addValue(id, 1) - 1 != val || longValue != 0x0badcafedeadbeefL
                            || !StringInterner.isEqual("FooBar", sb1)
                            || !StringInterner.isEqual("AnotherFooBar", sb2)) {
                        System.out.println("Unexpected value " + id + ", " + val + ", "
                                + Long.toHexString(longValue) + ", " + sb1.toString() + ", " + sb2.toString());
                        return;
                    }
                    ++count;
                    if (count % 1_000_000 == 0) {
                        long t1 = System.nanoTime();
                        System.out.println(tid + " " + (t1 - t0) / 1e6 + " ms");
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }));
    }
    for (Future f : futures) {
        f.get();
    }
    executor.shutdownNow();

    final long t1 = System.nanoTime();
    System.out.println("Done. Rough time=" + (t1 - t0) / 1e6 + " ms");
}

From source file:StartExamples.java

/**
 * Main function, starts the jetty server.
 * /*from   w w w .ja  v  a  2s . co m*/
 * @param args
 * @throws Exception 
 */

public static void main(String[] args) throws Exception {
    System.setProperty("org.mortbay.jetty.Request.maxFormContentSize", "20000000");
    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(8080);
    server.setConnectors(new Connector[] { connector });
    WebAppContext web = new WebAppContext("webroot", "/");
    server.addHandler(web);
    try {
        server.start();
        server.join();
        // server.destroy();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(100);
    }
}

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(", ");
        }/*from  w  ww .j  a va 2s.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(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  ww w  .j  a va  2 s  . c om*/
        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();
}