Example usage for java.lang Throwable getClass

List of usage examples for java.lang Throwable getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:it.cnr.icar.eric.client.admin.AdminShellUtilityTest.java

public static void main(String[] args) {
    try {//  ww  w  .ja v a  2  s  . c om
        junit.textui.TestRunner.run(suite());
    } catch (Throwable t) {
        System.out.println("Throwable: " + t.getClass().getName() + " Message: " + t.getMessage());
        t.printStackTrace();
    }
}

From source file:it.cnr.icar.eric.client.xml.registry.SecureSessionPerformanceTest.java

public static void main(String[] args) {
    System.out.println("Get into the program...\n");
    try {/*from  w  w  w  .jav a  2 s  .co m*/
        TestRunner.run(suite());
    } catch (Throwable t) {
        System.out.println("Throwable: " + t.getClass().getName() + " Message: " + t.getMessage());
        t.printStackTrace();
    }
}

From source file:caarray.client.test.full.LoadTest.java

/**
 * @param args/*w w  w .java2 s .  co m*/
 */
public static void main(String[] args) {
    List<ApiFacade> apiFacades = new ArrayList<ApiFacade>();
    List<List<ConfigurableTestSuite>> testSuiteCollection = new ArrayList<List<ConfigurableTestSuite>>();
    int numThreads = TestProperties.getNumThreads();
    if (numThreads <= 1) {
        System.out.println(
                "Thread count for load test set to 1 - setting to default count of " + DEFAULT_THREADS);
        numThreads = DEFAULT_THREADS;
    }
    try {
        for (int i = apiFacades.size(); i < numThreads; i++) {
            apiFacades.add(new FullApiFacade());
        }
        for (int i = testSuiteCollection.size(); i < numThreads; i++) {
            List<ConfigurableTestSuite> shortTests = TestMain.getShortTestSuites(apiFacades.get(i));
            List<ConfigurableTestSuite> longTests = TestMain.getLongTestSuites(apiFacades.get(i));
            List<ConfigurableTestSuite> testSuites = new ArrayList<ConfigurableTestSuite>();
            testSuites.addAll(shortTests);
            testSuites.addAll(longTests);
            testSuiteCollection.add(testSuites);
        }
        TestResultReport[] threadReports = new TestResultReport[numThreads];
        for (int i = 0; i < numThreads; i++) {
            threadReports[i] = new TestResultReport();
        }
        Thread[] loadTestThreads = new Thread[numThreads];
        for (int i = 0; i < numThreads; i++) {
            LoadTestThread thread = new LoadTestThread(apiFacades.get(i), testSuiteCollection.get(i),
                    threadReports[i], i);
            loadTestThreads[i] = new Thread(thread);
        }
        System.out.println("Executing load tests for " + numThreads + " threads ...");
        long start = System.currentTimeMillis();
        for (int i = 0; i < numThreads; i++) {
            loadTestThreads[i].start();
        }
        for (int i = 0; i < numThreads; i++) {
            loadTestThreads[i].join();
        }
        long time = System.currentTimeMillis() - start;
        System.out.println("Load tests completed in " + (double) time / (double) 1000 + " seconds.");

        TestResultReport finalReport = new TestResultReport();
        for (TestResultReport report : threadReports) {
            finalReport.merge(report);
        }
        System.out.println("Analyzing load test results ...");
        finalReport.writeLoadTestReports();
    } catch (Throwable t) {
        System.out.println("An exception occured execuitng the load tests: " + t.getClass());
        System.out.println("Test suite aborted.");
        t.printStackTrace();
        log.error("Exception encountered:", t);
    }

}

From source file:it.cnr.icar.eric.client.xml.registry.infomodel.RegistryPackageTest.java

public static void main(String[] args) {
    try {/*from  w  ww . j a v  a  2s. co  m*/
        TestRunner.run(suite());
    } catch (Throwable t) {
        System.out.println("Throwable: " + t.getClass().getName() + " Message: " + t.getMessage());
        t.printStackTrace();
    }
}

From source file:it.cnr.icar.eric.client.xml.registry.InfomodelFactoryTest.java

public static void main(String[] args) {
    try {/*from   w  w w . j ava  2s. co  m*/
        junit.textui.TestRunner.run(suite());
    } catch (Throwable t) {
        System.out.println("\nThrowable: " + t.getClass().getName() + " Message: " + t.getMessage());
        t.printStackTrace();
    }
}

From source file:com.appeligo.responsetest.ServerResponseChecker.java

/**
 * @param args/*from  ww w.j  a v a  2s. co  m*/
 */
public static void main(String[] args) {

    PatternLayout pattern = new PatternLayout("%d{ISO8601} %-5p [%-c{1} - %t] - %m%n");
    ConsoleAppender consoleAppender = new ConsoleAppender(pattern);
    LevelRangeFilter infoFilter = new LevelRangeFilter();
    infoFilter.setLevelMin(Level.INFO);
    consoleAppender.addFilter(infoFilter);
    BasicConfigurator.configure(consoleAppender);

    String configFile = "/etc/flip.tv/responsetest.xml";

    if (args.length > 0) {
        if (args.length == 2 && args[0].equals("-config")) {
            configFile = args[1];
        } else {
            log.error("Usage: java " + ServerResponseChecker.class.getName() + " [-config <xmlfile>]");
            System.exit(1);
        }
    }

    try {
        XMLConfiguration config = new XMLConfiguration(configFile);

        logFile = config.getString("logFile", logFile);
        servlet = config.getString("servlet", servlet);
        timeoutSeconds = config.getLong("timeoutSeconds", timeoutSeconds);
        responseTimeThresholdSeconds = config.getLong("responseTimeThresholdSeconds",
                responseTimeThresholdSeconds);
        reporter = config.getString("reporter", reporter);
        smtpServer = config.getString("smtpServer", smtpServer);
        smtpUsername = config.getString("smtpUsername", smtpUsername);
        smtpPassword = config.getString("smtpPassword", smtpPassword);
        smtpDebug = config.getBoolean("smtpDebug", smtpDebug);
        mailTo = config.getString("mailTo", mailTo);
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }

    marker = logFile + ".mailed";

    try {
        BasicConfigurator.configure(new RollingFileAppender(pattern, logFile, true));
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    // Add email appender
    SMTPAppender mailme = new SMTPAppender();
    LevelRangeFilter warnFilter = new LevelRangeFilter();
    warnFilter.setLevelMin(Level.WARN);
    mailme.addFilter(warnFilter);
    mailme.setSMTPDebug(smtpDebug);
    mailme.setSMTPHost(smtpServer);
    mailme.setTo(mailTo);
    mailme.setFrom(reporter + " <" + smtpUsername + ">");
    mailme.setBufferSize(1);
    mailme.setSubject(servlet + " Not Responding!");
    mailme.setSMTPUsername(smtpUsername);
    mailme.setSMTPPassword(smtpPassword);
    mailme.setLayout(new SimpleLayout());
    mailme.activateOptions();
    mailme.setLayout(pattern);
    BasicConfigurator.configure(mailme);

    long before;
    ConnectionThread connectionThread = new ConnectionThread();
    connectionThread.start();
    synchronized (connectionThread) {
        connectionThread.setOkToGo(true);
        connectionThread.notifyAll();
        before = System.currentTimeMillis();
        long delay = timeoutSeconds * 1000;
        while (!done && delay > 0) {
            try {
                connectionThread.wait(delay);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            delay -= (System.currentTimeMillis() - before);
        }
    }
    long after = System.currentTimeMillis();
    responseMillis = after - before;
    String reportStatus = "Could not report";
    try {
        StringBuilder sb = new StringBuilder();
        sb.append(servlet + "/responsetest/report.action");
        sb.append("?reporter=" + URLEncoder.encode(reporter));
        sb.append("&status=" + URLEncoder.encode(status));
        sb.append("&bytesRead=" + bytesRead);
        sb.append("&timedOut=" + (!done));
        if (throwable == null) {
            sb.append("&exception=none");
        } else {
            sb.append("&exception="
                    + URLEncoder.encode(throwable.getClass().getName() + "-" + throwable.getMessage()));
        }
        sb.append("&responseMillis=" + responseMillis);
        URL reportURL = new URL(sb.toString());
        connection = (HttpURLConnection) reportURL.openConnection();
        connection.connect();
        reportStatus = connection.getResponseCode() + " - " + connection.getResponseMessage();
    } catch (Throwable t) {
        reportStatus = t.getClass().getName() + "-" + t.getMessage();
    }
    StringBuilder sb = new StringBuilder();
    sb.append(servlet + ": ");
    sb.append(status + ", " + bytesRead + " bytes, ");
    if (done) {
        sb.append("DONE, ");
    } else {
        sb.append("TIMED OUT, ");
    }
    sb.append(responseMillis + " millisecond response, ");
    sb.append(" report status=" + reportStatus);
    File markerFile = new File(marker);
    if (done && status.startsWith("200") && (throwable == null)) {
        if ((responseMillis / 1000) < responseTimeThresholdSeconds) {
            if (markerFile.exists()) {
                markerFile.delete();
            }
            log.debug(sb.toString());
        } else {
            if (markerFile.exists()) {
                log.info(sb.toString());
            } else {
                try {
                    new FileOutputStream(marker).close();
                    log.warn(sb.toString());
                } catch (IOException e) {
                    log.info(sb.toString());
                    log.info("Can't send email alert because could not write marker file: " + marker + ". "
                            + e.getMessage());
                }
            }
        }
    } else {
        if (throwable != null) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            throwable.printStackTrace(pw);
            sb.append(sw.toString());
        }
        if (markerFile.exists()) {
            log.info(sb.toString());
        } else {
            try {
                new FileOutputStream(marker).close();
                log.fatal(sb.toString()); // chosen appender layout ignoresThrowable()
            } catch (IOException e) {
                log.info(sb.toString());
                log.info("Can't send email alert because could not write marker file: " + marker + ". "
                        + e.getMessage());
            }
        }
    }
}

From source file:fedora.server.utilities.rebuild.Rebuild.java

public static void main(String[] args) {
    // tell commons-logging to use log4j
    System.setProperty("org.apache.commons.logging.LogFactory", "org.apache.commons.logging.impl.Log4jFactory");
    System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger");
    // log4j//from w  w  w . j  av  a 2 s.c  o m
    // File log4jConfig = new File(new File(homeDir), "config/log4j.xml");
    // DOMConfigurator.configure(log4jConfig.getPath());
    String profile = null;
    if (args.length > 0) {
        profile = args[0];
    }
    if (args.length > 1) {
        fail("Too many arguments", true, true);
    }
    try {
        File serverDir = new File(new File(Constants.FEDORA_HOME), "server");
        ServerConfiguration serverConfig = getServerConfig(serverDir, profile);
        System.err.println();
        System.err.println("                       Fedora Rebuild Utility");
        System.err.println("                     ..........................");
        System.err.println();
        System.err.println("WARNING: Live rebuilds are not currently supported.");
        System.err.println("         Make sure your server is stopped before continuing.");
        System.err.println();
        System.err.println("Server directory is " + serverDir.toString());
        if (profile != null) {
            System.err.print("Server profile is " + profile);
        }
        System.err.println();
        System.err.println("---------------------------------------------------------------------");
        System.err.println();
        Rebuilder rebuilder = getRebuilder();
        Map<String, String> options = getUserInput(rebuilder, serverDir, serverConfig);
        new Rebuild(rebuilder, options, serverConfig);
    } catch (Throwable th) {
        String msg = th.getMessage();
        if (msg == null) {
            msg = th.getClass().getName();
        }
        fail(msg, false, false);
        th.printStackTrace();
    }
}

From source file:com.clustercontrol.agent.Agent.java

/**
 * ?/*w  w w .  j  a  v a  2 s. co m*/
 * 
 * @param args ??
 */
public static void main(String[] args) throws Exception {

    // ?
    if (args.length != 1) {
        System.out.println("Usage : java Agent [Agent.properties File Path]");
        System.exit(1);
    }

    try {
        // System
        m_log.info("starting Hinemos Agent...");
        m_log.info("java.vm.version = " + System.getProperty("java.vm.version"));
        m_log.info("java.vm.vendor = " + System.getProperty("java.vm.vendor"));
        m_log.info("java.home = " + System.getProperty("java.home"));
        m_log.info("os.name = " + System.getProperty("os.name"));
        m_log.info("os.arch = " + System.getProperty("os.arch"));
        m_log.info("os.version = " + System.getProperty("os.version"));
        m_log.info("user.name = " + System.getProperty("user.name"));
        m_log.info("user.dir = " + System.getProperty("user.dir"));
        m_log.info("user.country = " + System.getProperty("user.country"));
        m_log.info("user.language = " + System.getProperty("user.language"));
        m_log.info("file.encoding = " + System.getProperty("file.encoding"));

        // System(SET)
        String limitKey = "jdk.xml.entityExpansionLimit"; // TODO JRE???????????????????
        System.setProperty(limitKey, "0");
        m_log.info(limitKey + " = " + System.getProperty(limitKey));

        // TODO ???agentHome
        // ??????????
        File file = new File(args[0]);
        agentHome = file.getParentFile().getParent() + "/";
        m_log.info("agentHome=" + agentHome);

        // 
        long startDate = HinemosTime.currentTimeMillis();
        m_log.info("start date = " + new Date(startDate) + "(" + startDate + ")");
        agentInfo.setStartupTime(startDate);

        // Agent??
        m_log.info("Agent.properties = " + args[0]);

        // ?
        File scriptDir = new File(agentHome + "script/");
        if (scriptDir.exists()) {
            File[] listFiles = scriptDir.listFiles();
            if (listFiles != null) {
                for (File f : listFiles) {
                    boolean ret = f.delete();
                    if (ret) {
                        m_log.debug("delete script : " + f.getName());
                    } else {
                        m_log.warn("delete script error : " + f.getName());
                    }
                }
            } else {
                m_log.warn("listFiles is null");
            }
        } else {
            //????????
            boolean ret = scriptDir.mkdir();
            if (!ret) {
                m_log.warn("mkdir error " + scriptDir.getPath());
            }
        }

        // queue?
        m_sendQueue = new SendQueue();

        // Agent?
        Agent agent = new Agent(args[0]);

        //-----------------
        //-- 
        //-----------------
        m_log.debug("exec() : create topic ");

        m_receiveTopic = new ReceiveTopic(m_sendQueue);
        m_receiveTopic.setName("ReceiveTopicThread");
        m_log.info("receiveTopic start 1");
        m_receiveTopic.start();
        m_log.info("receiveTopic start 2");

        // ?
        agent.exec();

        m_log.info("Hinemos Agent started");

        // ?
        agent.waitAwakeAgent();
    } catch (Throwable e) {
        m_log.error("Agent.java: Runtime Exception Occurred. " + e.getClass().getName() + ", " + e.getMessage(),
                e);
    }
}

From source file:net.pms.PMS.java

public static void main(String args[]) throws IOException, ConfigurationException {
    boolean displayProfileChooser = false;

    // FIXME (breaking change): use a standard argument
    // format (and a standard argument processor) e.g.
    // --console, --scrollbars &c.
    if (args.length > 0) {
        for (int a = 0; a < args.length; a++) {
            if (args[a].equals(CONSOLE)) {
                System.setProperty(CONSOLE, Boolean.toString(true));
            } else if (args[a].equals(NATIVELOOK)) {
                System.setProperty(NATIVELOOK, Boolean.toString(true));
            } else if (args[a].equals(SCROLLBARS)) {
                System.setProperty(SCROLLBARS, Boolean.toString(true));
            } else if (args[a].equals(NOCONSOLE)) {
                System.setProperty(NOCONSOLE, Boolean.toString(true));
            } else if (args[a].equals(PROFILES)) {
                displayProfileChooser = true;
            }/*from   www .  j  a v  a2  s  .c om*/
        }
    }

    try {
        Toolkit.getDefaultToolkit();

        if (isHeadless()) {
            if (System.getProperty(NOCONSOLE) == null) {
                System.setProperty(CONSOLE, Boolean.toString(true));
            }
        }
    } catch (Throwable t) {
        System.err.println("Toolkit error: " + t.getClass().getName() + ": " + t.getMessage());

        if (System.getProperty(NOCONSOLE) == null) {
            System.setProperty(CONSOLE, Boolean.toString(true));
        }
    }

    if (!isHeadless() && displayProfileChooser) {
        ProfileChooser.display();
    }

    try {
        setConfiguration(new PmsConfiguration());
        assert getConfiguration() != null;

        // Load the (optional) logback config file.
        // This has to be called after 'new PmsConfiguration'
        // as the logging starts immediately and some filters
        // need the PmsConfiguration.
        // XXX not sure this is (still) true: the only filter
        // we use is ch.qos.logback.classic.filter.ThresholdFilter
        LoggingConfigFileLoader.load();

        // create the PMS instance returned by get()
        createInstance(); // calls new() then init()
    } catch (Throwable t) {
        String errorMessage = String.format("Configuration error: %s: %s", t.getClass().getName(),
                t.getMessage());

        System.err.println(errorMessage);
        t.printStackTrace();

        if (!isHeadless() && instance != null) {
            JOptionPane.showMessageDialog(
                    ((JFrame) (SwingUtilities.getWindowAncestor((Component) instance.getFrame()))),
                    errorMessage, Messages.getString("PMS.42"), JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:com.zimbra.cs.zclient.ZMailboxUtil.java

public static void main(String args[]) throws IOException, ServiceException {
    CliUtil.toolSetup();//from   w  w w  .  j  a  v a2 s  .  c  om
    SoapTransport.setDefaultUserAgent("zmmailbox", BuildInfo.VERSION);

    ZMailboxUtil pu = new ZMailboxUtil();
    CommandLineParser parser = new GnuParser();
    Options options = new Options();
    options.addOption("a", "admin", true, "admin account name to auth as");
    options.addOption("z", "zadmin", false,
            "use zimbra admin name/password from localconfig for admin/password");
    options.addOption("h", "help", false, "display usage");
    options.addOption("f", "file", true, "use file as input stream");
    options.addOption("u", "url", true, "http[s]://host[:port] of server to connect to");
    options.addOption("r", "protocol", true, "protocol to use for request/response [soap11, soap12, json]");
    options.addOption("m", "mailbox", true, "mailbox to open");
    options.addOption(null, "auth", true, "account name to auth as; defaults to -m unless -A is used");
    options.addOption("A", "admin-priv", false, "execute requests with admin privileges");
    options.addOption("p", "password", true, "auth password");
    options.addOption("P", "passfile", true, "filename with password in it");
    options.addOption("t", "timeout", true, "timeout (in seconds)");
    options.addOption("v", "verbose", false, "verbose mode");
    options.addOption("d", "debug", false, "debug mode");
    options.addOption(SoapCLI.OPT_AUTHTOKEN);
    options.addOption(SoapCLI.OPT_AUTHTOKENFILE);

    CommandLine cl = null;
    boolean err = false;

    try {
        cl = parser.parse(options, args, true);
    } catch (ParseException pe) {
        stderr.println("error: " + pe.getMessage());
        err = true;
    }

    if (err || cl.hasOption('h')) {
        pu.usage();
    }

    try {
        boolean isAdmin = false;
        pu.setVerbose(cl.hasOption('v'));
        if (cl.hasOption('a')) {
            pu.setAdminAccountName(cl.getOptionValue('a'));
            pu.setUrl(DEFAULT_ADMIN_URL, true);
            isAdmin = true;
        }
        if (cl.hasOption('z')) {
            pu.setAdminAccountName(LC.zimbra_ldap_user.value());
            pu.setPassword(LC.zimbra_ldap_password.value());
            pu.setUrl(DEFAULT_ADMIN_URL, true);
            isAdmin = true;
        }

        if (cl.hasOption(SoapCLI.O_AUTHTOKEN) && cl.hasOption(SoapCLI.O_AUTHTOKENFILE))
            pu.usage();
        if (cl.hasOption(SoapCLI.O_AUTHTOKEN)) {
            pu.setAdminAuthToken(ZAuthToken.fromJSONString(cl.getOptionValue(SoapCLI.O_AUTHTOKEN)));
            pu.setUrl(DEFAULT_ADMIN_URL, true);
            isAdmin = true;
        }
        if (cl.hasOption(SoapCLI.O_AUTHTOKENFILE)) {
            String authToken = StringUtil.readSingleLineFromFile(cl.getOptionValue(SoapCLI.O_AUTHTOKENFILE));
            pu.setAdminAuthToken(ZAuthToken.fromJSONString(authToken));
            pu.setUrl(DEFAULT_ADMIN_URL, true);
            isAdmin = true;
        }

        String authAccount, targetAccount;
        if (cl.hasOption('m')) {
            if (!cl.hasOption('p') && !cl.hasOption('P') && !cl.hasOption('y') && !cl.hasOption('Y')
                    && !cl.hasOption('z')) {
                throw ZClientException.CLIENT_ERROR("-m requires one of the -p/-P/-y/-Y/-z options", null);
            }
            targetAccount = cl.getOptionValue('m');
        } else {
            targetAccount = null;
        }
        if ((cl.hasOption("A") || cl.hasOption("auth")) && !cl.hasOption('m')) {
            throw ZClientException.CLIENT_ERROR("-A/--auth requires -m", null);
        }
        if (cl.hasOption("A")) {
            if (!isAdmin) {
                throw ZClientException.CLIENT_ERROR("-A requires admin auth", null);
            }
            if (cl.hasOption("auth")) {
                throw ZClientException.CLIENT_ERROR("-A cannot be combined with --auth", null);
            }
            authAccount = null;
        } else if (cl.hasOption("auth")) {
            authAccount = cl.getOptionValue("auth");
        } else {
            // default case
            authAccount = targetAccount;
        }
        if (!StringUtil.isNullOrEmpty(authAccount))
            pu.setAuthAccountName(authAccount);
        if (!StringUtil.isNullOrEmpty(targetAccount))
            pu.setTargetAccountName(targetAccount);

        if (cl.hasOption('u'))
            pu.setUrl(cl.getOptionValue('u'), isAdmin);
        if (cl.hasOption('p'))
            pu.setPassword(cl.getOptionValue('p'));
        if (cl.hasOption('P')) {
            pu.setPassword(StringUtil.readSingleLineFromFile(cl.getOptionValue('P')));
        }
        if (cl.hasOption('d'))
            pu.setDebug(true);

        if (cl.hasOption('t'))
            pu.setTimeout(cl.getOptionValue('t'));

        args = cl.getArgs();

        pu.setInteractive(args.length < 1);

        pu.initMailbox();
        if (args.length < 1) {
            InputStream is = null;
            if (cl.hasOption('f')) {
                is = new FileInputStream(cl.getOptionValue('f'));
            } else {
                if (LC.command_line_editing_enabled.booleanValue()) {
                    try {
                        CliUtil.enableCommandLineEditing(LC.zimbra_home.value() + "/.zmmailbox_history");
                    } catch (IOException e) {
                        System.err.println("Command line editing will be disabled: " + e);
                        if (pu.mGlobalVerbose) {
                            e.printStackTrace(System.err);
                        }
                    }
                }
                is = System.in; // This has to happen last because JLine modifies System.in.
            }
            pu.interactive(new BufferedReader(new InputStreamReader(is, "UTF-8")));
        } else {
            pu.execute(args);
        }
    } catch (ServiceException e) {
        Throwable cause = e.getCause();
        stderr.println("ERROR: " + e.getCode() + " (" + e.getMessage() + ")" + (cause == null ? ""
                : " (cause: " + cause.getClass().getName() + " " + cause.getMessage() + ")"));
        if (pu.mGlobalVerbose)
            e.printStackTrace(stderr);
        System.exit(2);
    }
}