Example usage for java.lang RuntimeException RuntimeException

List of usage examples for java.lang RuntimeException RuntimeException

Introduction

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

Prototype

public RuntimeException(Throwable cause) 

Source Link

Document

Constructs a new runtime exception with the specified cause and a detail message of (cause==null ?

Usage

From source file:com.rest.samples.getTipoCambioBanxico.java

public static void main(String[] args) {
    String url = "http://www.banxico.org.mx/tipcamb/llenarTiposCambioAction.do?idioma=sp";
    try {/* w ww  .jav a2s  .  c  o m*/
        HttpClient hc = HttpClientBuilder.create().build();
        HttpGet request = new HttpGet(url);
        request.setHeader("User-Agent", "Mozilla/5.0");
        request.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");

        HttpResponse res = hc.execute(request);
        if (res.getStatusLine().getStatusCode() != 200) {
            throw new RuntimeException("Failed : HTTP eror code: " + res.getStatusLine().getStatusCode());
        }

        BufferedReader rd = new BufferedReader(new InputStreamReader(res.getEntity().getContent()));
        StringBuffer result = new StringBuffer();
        String line = "";
        while ((line = rd.readLine()) != null) {
            result.append(line);
        }
        Document doc = Jsoup.parse(result.toString());
        Element tipoCambioFix = doc.getElementById("FIX_DATO");
        System.out.println(tipoCambioFix.text());

    } catch (IOException ex) {
        Logger.getLogger(SamplesUseHttpclient.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.rest.samples.GetJSON.java

public static void main(String[] args) {
    // TODO code application logic here
    //        String url = "https://api.adorable.io/avatars/list";
    String url = "http://freemusicarchive.org/api/get/albums.json?api_key=60BLHNQCAOUFPIBZ&limit=5";
    try {//from w  ww  .  j a v a  2  s . co m
        HttpClient hc = HttpClientBuilder.create().build();
        HttpGet getMethod = new HttpGet(url);
        getMethod.addHeader("accept", "application/json");
        HttpResponse res = hc.execute(getMethod);
        if (res.getStatusLine().getStatusCode() != 200) {
            throw new RuntimeException("Failed : HTTP eror code: " + res.getStatusLine().getStatusCode());
        }

        InputStream is = res.getEntity().getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        JsonParser parser = new JsonParser();
        JsonElement element = parser.parse(br);
        if (element.isJsonObject()) {
            JsonObject jsonObject = element.getAsJsonObject();
            Set<Map.Entry<String, JsonElement>> jsonEntrySet = jsonObject.entrySet();
            for (Map.Entry<String, JsonElement> entry : jsonEntrySet) {
                if (entry.getValue().isJsonArray() && entry.getValue().getAsJsonArray().size() > 0) {
                    JsonArray jsonArray = entry.getValue().getAsJsonArray();
                    Set<Map.Entry<String, JsonElement>> internalJsonEntrySet = jsonArray.get(0)
                            .getAsJsonObject().entrySet();
                    for (Map.Entry<String, JsonElement> entrie : internalJsonEntrySet) {
                        System.out.println("--->   " + entrie.getKey() + " --> " + entrie.getValue());

                    }

                } else {
                    System.out.println(entry.getKey() + " --> " + entry.getValue());
                }
            }
        }

        String output;
        while ((output = br.readLine()) != null) {
            System.out.println(output);
        }

    } catch (IOException ex) {
        Logger.getLogger(SamplesUseHttpclient.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:nl.raja.niruraji.pa.PlayGround.java

public static void main(String[] args) {

    try {/*ww  w  . j av a 2 s  .c o m*/
        // create HTTP Client         
        HttpClient httpClient = HttpClientBuilder.create().build();
        String url = "http://buienradar.nl/Json/GetTwentyFourHourForecast?geolocationid=2751773";

        // Create new getRequest with below mentioned URL         
        HttpGet getRequest = new HttpGet(url);

        // Add additional header to getRequest which accepts application/xml data         
        //getRequest.addHeader("accept", "application/xml"); 

        // Execute your request and catch response         
        HttpResponse response = httpClient.execute(getRequest);

        // Check for HTTP response code: 200 = success         
        if (response.getStatusLine().getStatusCode() != 200) {
            throw new RuntimeException(
                    "Failed : HTTP error code : " + response.getStatusLine().getStatusCode());

        }

        String result = EntityUtils.toString(response.getEntity());
        JSONObject myObject = new JSONObject(result);

        // Get-Capture Complete application/xml body response

        BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));

        String output;

        System.out.println("============Output:============");

        // Simply iterate through XML response and show on console.

        while ((output = br.readLine()) != null) {

            System.out.println(output);

        }

    } catch (ClientProtocolException e) {

        e.printStackTrace();

    } catch (IOException e) {

        e.printStackTrace();

    }

}

From source file:com.github.e2point718.har2jmx.HAR2JMX.java

public static void main(String[] args) {
    try {/*  ww  w  .j a  v a2 s  .c  o m*/
        parseCommandLine(args);
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.runwaysdk.dataaccess.io.instance.InstanceImporterUnzipper.java

public static void main(String[] args) {
    if (args.length != 1) {
        String msg = "Please include the arguments 1) The path to the application's data directory.";

        throw new RuntimeException(msg);
    }/*  www.  java2  s  .c  om*/

    processZipDir(args[0] + "/universals");
    processZipDir(args[0] + "/geoentities");
    // processZipDir(args[0] + "/classifiers");
}

From source file:com.samczsun.helios.bootloader.Bootloader.java

public static void main(String[] args) {
    try {//  w ww.  j  a  v a 2s.c  om
        if (!Constants.DATA_DIR.exists() && !Constants.DATA_DIR.mkdirs())
            throw new RuntimeException("Could not create data directory");
        if (!Constants.ADDONS_DIR.exists() && !Constants.ADDONS_DIR.mkdirs())
            throw new RuntimeException("Could not create addons directory");
        if (!Constants.SETTINGS_FILE.exists() && !Constants.SETTINGS_FILE.createNewFile())
            throw new RuntimeException("Could not create settings file");
        if (Constants.DATA_DIR.isFile())
            throw new RuntimeException("Data directory is file");
        if (Constants.ADDONS_DIR.isFile())
            throw new RuntimeException("Addons directory is file");
        if (Constants.SETTINGS_FILE.isDirectory())
            throw new RuntimeException("Settings file is directory");

        loadSWTLibrary();

        DisplayPumper displayPumper = new DisplayPumper();

        if (System.getProperty("os.name").toLowerCase().contains("mac")) {
            System.out.println("Attemting to force main thread");
            Executor executor;
            try {
                Class<?> dispatchClass = Class.forName("com.apple.concurrent.Dispatch");
                Object dispatchInstance = dispatchClass.getMethod("getInstance").invoke(null);
                executor = (Executor) dispatchClass.getMethod("getNonBlockingMainQueueExecutor")
                        .invoke(dispatchInstance);
            } catch (Throwable throwable) {
                throw new RuntimeException("Could not reflectively access Dispatch", throwable);
            }
            if (executor != null) {
                executor.execute(displayPumper);
            } else {
                throw new RuntimeException("Could not load executor");
            }
        } else {
            Thread pumpThread = new Thread(displayPumper);
            pumpThread.start();
        }
        while (!displayPumper.isReady())
            ;

        Display display = displayPumper.getDisplay();
        Shell shell = displayPumper.getShell();
        Splash splashScreen = new Splash(display);
        splashScreen.updateState(BootSequence.CHECKING_LIBRARIES);
        checkPackagedLibrary(splashScreen, "enjarify", Constants.ENJARIFY_VERSION,
                BootSequence.CHECKING_ENJARIFY, BootSequence.CLEANING_ENJARIFY, BootSequence.MOVING_ENJARIFY);
        checkPackagedLibrary(splashScreen, "Krakatau", Constants.KRAKATAU_VERSION,
                BootSequence.CHECKING_KRAKATAU, BootSequence.CLEANING_KRAKATAU, BootSequence.MOVING_KRAKATAU);
        Helios.main(args, shell, splashScreen);
        while (!displayPumper.isDone()) {
            Thread.sleep(100);
        }
    } catch (Throwable t) {
        displayError(t);
        System.exit(1);
    }
}

From source file:com.thoughtworks.go.server.DevelopmentServer.java

public static void main(String[] args) throws Exception {
    LogConfigurator logConfigurator = new LogConfigurator(DEFAULT_LOGBACK_CONFIGURATION_FILE);
    logConfigurator.initialize();/* w  w  w.j  a va  2 s .co m*/
    copyDbFiles();
    copyPluginAssets();
    File webApp = new File("webapp");
    if (!webApp.exists()) {
        throw new RuntimeException("No webapp found in " + webApp.getAbsolutePath());
    }

    assertActivationJarPresent();
    SystemEnvironment systemEnvironment = new SystemEnvironment();
    systemEnvironment.setProperty(GENERATE_STATISTICS, "true");

    systemEnvironment.setProperty(SystemEnvironment.PARENT_LOADER_PRIORITY, "true");
    systemEnvironment.setProperty(SystemEnvironment.CRUISE_SERVER_WAR_PROPERTY, webApp.getAbsolutePath());
    systemEnvironment.set(SystemEnvironment.PLUGIN_LOCATION_MONITOR_INTERVAL_IN_SECONDS, 5);

    systemEnvironment.set(SystemEnvironment.DEFAULT_PLUGINS_ZIP, "/plugins.zip");
    systemEnvironment.set(SystemEnvironment.PLUGIN_ACTIVATOR_JAR_PATH, "go-plugin-activator.jar");
    systemEnvironment.set(SystemEnvironment.FAIL_STARTUP_ON_DATA_ERROR, true);
    systemEnvironment.setProperty(GoConstants.I18N_CACHE_LIFE, "0"); //0 means reload when stale
    systemEnvironment.set(SystemEnvironment.GO_SERVER_MODE, "development");
    setupPeriodicGC(systemEnvironment);
    assertPluginsZipExists();
    GoServer server = new GoServer();
    systemEnvironment.setProperty(GoConstants.USE_COMPRESSED_JAVASCRIPT, Boolean.toString(false));
    try {
        server.startServer();

        String hostName = systemEnvironment.getListenHost();
        if (hostName == null) {
            hostName = "localhost";
        }

        System.out.println("GoCD server dashboard started on http://" + hostName + ":"
                + systemEnvironment.getServerPort());
        System.out.println("* credentials: \"admin\" / \"badger\"");
    } catch (Exception e) {
        System.err.println("Failed to start GoCD server. Exception:");
        e.printStackTrace();
    }
}

From source file:com.sm.store.server.ClusterServer.java

public static void main(String[] args) {
    String[] opts = new String[] { "-host", "-configPath", "-dataPath", "-port", "replicaPort", "-start",
            "-freq" };
    String[] defaults = new String[] { "", "", "", "0", "0", "true", "0" };
    String[] paras = getOpts(args, opts, defaults);

    String configPath = paras[1];
    if (configPath.length() == 0) {
        logger.error("missing config path");
        throw new RuntimeException("missing -configPath");
    }//from  ww  w. ja v  a  2  s  .  c o  m
    //set configPath to system properties
    System.setProperty("configPath", configPath);
    NodeConfig nodeConfig = getNodeConfig(configPath + "/node.properties");
    //int clusterNo = Integer.valueOf( paras[0]);
    String dataPath = paras[2];
    if (dataPath.length() == 0) {
        dataPath = "./data";
    }
    int port = Integer.valueOf(paras[3]);
    int replicaPort = Integer.valueOf(paras[4]);
    //get from command line, if not form nodeConfig
    if (port == 0)
        port = nodeConfig.getPort();
    if (port == 0) {
        throw new RuntimeException("port is 0");
    } else {
        if (replicaPort == 0)
            replicaPort = port + 1;
    }
    boolean start = Boolean.valueOf(paras[5]);
    String host = paras[0];
    //get from command line, if not form nodeConfig or from getHost
    if (host.length() == 0)
        host = nodeConfig.getHost();
    if (host.length() == 0)
        host = getLocalHost();
    int freq = Integer.valueOf(paras[6]);
    logger.info("read clusterNode and storeConfig from " + configPath);
    BuildClusterNodes bcn = new BuildClusterNodes(configPath + "/clusters.xml");
    //BuildStoreConfig bsc = new BuildStoreConfig(configPath+"/stores.xml");
    BuildRemoteConfig brc = new BuildRemoteConfig(configPath + "/stores.xml");
    List<ClusterNodes> clusterNodesList = bcn.build();
    short clusterNo = findClusterNo(host + ":" + port, clusterNodesList);
    logger.info("create cluster server config for cluster " + clusterNo + " host " + host + " port " + port
            + " replica port " + replicaPort);
    ClusterServerConfig serverConfig = new ClusterServerConfig(clusterNodesList, brc.build().getConfigList(),
            clusterNo, dataPath, configPath, port, replicaPort, host);
    //over write config from command line if freq > 0
    if (freq > 0)
        serverConfig.setFreq(freq);
    logger.info("create cluster server");
    ClusterStoreServer cs = new ClusterStoreServer(serverConfig, new HessianSerializer());
    // start replica server
    cs.startReplicaServer();
    logger.info("hookup jvm shutdown process");
    cs.hookShutdown();
    if (start) {
        logger.info("server is starting " + cs.getServerConfig().toString());
        cs.start();
    } else
        logger.warn("server is staged and wait to be started");

    List list = new ArrayList();
    //add jmx metric
    List<String> stores = cs.getAllStoreNames();
    for (String store : stores) {
        list.add(cs.getStore(store));
    }
    list.add(cs);
    stores.add("ClusterServer");
    JmxService jms = new JmxService(list, stores);
}

From source file:com.ms.commons.standalone.job.JobRunner.java

public static void main(String[] args) throws JobExecutionException {
    logger.error("__start of job, args is " + StringUtils.join(args, ", "));
    // try and catch everything
    try {//w w w  .j  a  v a  2  s . com
        checkArgs(args);
        JobAction jobAction = JobAction.valueOf(args[0].trim());
        String fullClassName = args[1].trim();
        String[] NewArgs = getNewArgs(args);

        AbstractJob job = getJobInstanceByClassName(fullClassName);
        job.setArgs(NewArgs);

        clearStandaloneStopFile();

        switch (jobAction) {
        case start:
            job.execute(null);
            break;
        case startNohup:
            job.execute(null);
            break;
        case startWithDebug:
            job.execute(null);
            break;
        case stop:
            stopJob();
            break;
        default:
            throw new RuntimeException("jobAction must be start or stop");
        }
    } catch (Throwable t) {
        logger.error(t.getMessage(), t);
        t.printStackTrace();
    }
    logger.error("__end of job, args is " + StringUtils.join(args, ", "));
    System.exit(0);
}

From source file:com.sm.store.server.grizzly.GZClusterServer.java

public static void main(String[] args) {
    String[] opts = new String[] { "-host", "-configPath", "-dataPath", "-port", "replicaPort", "-start",
            "-freq" };
    String[] defaults = new String[] { "", "", "", "0", "0", "true", "10" };
    String[] paras = getOpts(args, opts, defaults);

    String configPath = paras[1];
    if (configPath.length() == 0) {
        logger.error("missing config path");
        throw new RuntimeException("missing -configPath");
    }/*www  . j  a v  a  2s.  c om*/
    System.setProperty("configPath", configPath);
    NodeConfig nodeConfig = getNodeConfig(configPath + "/node.properties");
    //int clusterNo = Integer.valueOf( paras[0]);
    String dataPath = paras[2];
    if (dataPath.length() == 0) {
        dataPath = "./data";
    }
    int port = Integer.valueOf(paras[3]);
    int replicaPort = Integer.valueOf(paras[4]);
    //get from command line, if not form nodeConfig
    if (port == 0)
        port = nodeConfig.getPort();
    if (port == 0) {
        throw new RuntimeException("port is 0");
    } else {
        if (replicaPort == 0)
            replicaPort = port + 1;
    }
    boolean start = Boolean.valueOf(paras[5]);
    String host = paras[0];
    //get from command line, if not form nodeConfig or from getHost
    if (host.length() == 0)
        host = nodeConfig.getHost();
    if (host.length() == 0)
        host = getLocalHost();
    int freq = Integer.valueOf(paras[6]);
    logger.info("read clusterNode and storeConfig from " + configPath);
    BuildClusterNodes bcn = new BuildClusterNodes(configPath + "/clusters.xml");
    //BuildStoreConfig bsc = new BuildStoreConfig(configPath+"/stores.xml");
    BuildRemoteConfig brc = new BuildRemoteConfig(configPath + "/stores.xml");
    List<ClusterNodes> clusterNodesList = bcn.build();
    short clusterNo = findClusterNo(host + ":" + port, clusterNodesList);
    logger.info("create cluster server config for cluster " + clusterNo + " host " + host + " port " + port
            + " replica port " + replicaPort);
    ClusterServerConfig serverConfig = new ClusterServerConfig(clusterNodesList, brc.build().getConfigList(),
            clusterNo, dataPath, configPath, port, replicaPort, host);
    serverConfig.setFreq(freq);
    logger.info("create cluster server");
    GZClusterStoreServer cs = new GZClusterStoreServer(serverConfig, new HessianSerializer());
    // start replica server
    cs.startReplicaServer();
    logger.info("hookup jvm shutdown process");
    cs.hookShutdown();
    if (start) {
        logger.info("server is starting " + cs.getServerConfig().toString());
        cs.start();
    } else
        logger.warn("server is staged and wait to be started");

    List list = new ArrayList();
    //add jmx metric
    List<String> stores = cs.getAllStoreNames();
    for (String store : stores) {
        list.add(cs.getStore(store));
    }
    list.add(cs);
    stores.add("ClusterServer");
    JmxService jms = new JmxService(list, stores);

    try {
        logger.info("Read from console and wait ....");
        int c = System.in.read();
    } catch (IOException e) {
        logger.warn("Error reading " + e.getMessage());
    }
    logger.warn("Exiting from System.in.read()");
}