Example usage for java.lang Throwable getMessage

List of usage examples for java.lang Throwable getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:controllers.Common.java

/**
 * Gets a user printable message for an exception.
 * /*from  w  w  w .  j  a  v  a 2 s  .co  m*/
 * @param throwable Exception to get the message for
 */
@Util
public static String getUserMessage(Throwable throwable) {
    String message = throwable.getMessage();
    if (message == null) {
        message = throwable.getClass().getName();
    }
    return message;
}

From source file:net.officefloor.plugin.socket.server.http.request.HttpRequestTest.java

/**
 * Create the {@link TestSuite} of the tests to be run.
 * //  w  ww.java2s. c o  m
 * @return {@link TestSuite} of tests to be run.
 */
public static Test suite() throws Exception {
    // Create the test suite
    TestSuite suite = new TestSuite(HttpRequestTest.class.getName());

    try {

        // Create an instance of the test to obtain test methods
        HttpRequestTest util = new HttpRequestTest(null, null, null, false, null);

        // Obtain the file containing XML Unmarshaller configuration
        File unmarshallerConfigFile = util.findFile(HttpRequestTest.class, "UnmarshallConfiguration.xml");

        // Obtain the current directory
        XmlUnmarshaller unmarshaller = TreeXmlUnmarshallerFactory.getInstance()
                .createUnmarshaller(new FileInputStream(unmarshallerConfigFile));

        // Create the HTTP servicer builder
        HttpServicerBuilder httpServicerBuilder = new HttpServicerBuilder() {
            @Override
            public HttpServicerTask buildServicer(String managedObjectName, MockHttpServer server)
                    throws Exception {
                // Register team to do the work
                server.constructTeam("WORKER", MockTeamSource.createOnePersonTeam("WORKER"));

                // Register the work to process messages
                ReflectiveWorkBuilder workBuilder = server.constructWork(new RequestWork(), "servicer",
                        "service");
                ReflectiveTaskBuilder taskBuilder = workBuilder.buildTask("service", "WORKER");
                taskBuilder.buildObject(managedObjectName);

                // Return the reference to the service task
                return new HttpServicerTask("servicer", "service");
            }
        };

        // Load the non-secure tests
        final MockHttpServer httpServer = new MockHttpServer() {
        };
        loadTests("http", unmarshallerConfigFile.getParentFile(), unmarshaller, httpServer, false,
                httpServicerBuilder, suite);

        // Load the secure tests
        final MockHttpServer httpsServer = new MockHttpServer() {
        };
        httpsServer.setupSecure();
        loadTests("https", unmarshallerConfigFile.getParentFile(), unmarshaller, httpsServer, true,
                httpServicerBuilder, suite);

        // Add a task to shutdown the servers
        suite.addTest(new TestCase("Shutdown HTTP Server") {
            @Override
            protected void runTest() throws Throwable {
                httpServer.shutdown();
                httpsServer.shutdown();
            }
        });

    } catch (Throwable ex) {
        // Add warning that failed to setup
        suite.addTest(TestSuite.warning("Failed setting up suite of tests: " + ex.getMessage() + " ["
                + ex.getClass().getSimpleName() + "]"));
    }

    // Return the test suite
    return suite;
}

From source file:com.github.dakusui.symfonion.CLI.java

private static void printError(PrintStream ps, Throwable t) {
    ps.println(String.format("symfonion: %s", t.getMessage()));
}

From source file:com.microsoft.applicationinsights.internal.perfcounter.JniPCConnector.java

/**
 * This method must be called before any other method.
 * All other methods are relevant only if this method was successful.
 *
 * Note that the method should not throw and should gracefully return the boolean value.
 * @return True on success.//from  w w  w .  ja va 2 s. c  om
 */
public static boolean initialize() {
    try {
        if (!SystemInformation.INSTANCE.isWindows()) {
            InternalLogger.INSTANCE.error("Jni connector is only used on Windows OS.");
            return false;
        }

        loadNativeLibrary();
    } catch (Throwable e) {
        InternalLogger.INSTANCE.error(
                "Failed to load native dll, Windows performance counters will not be used. "
                        + "Please make sure that Visual C++ Redistributable is properly installed: %s.",
                e.getMessage());

        return false;
    }

    return true;
}

From source file:com.splicemachine.derby.impl.load.HBaseBulkLoadIT.java

@BeforeClass
public static void loaddata() throws Exception {
    try {//from  www .  j  av  a 2  s  .  c  o  m
        TestUtils.executeSqlFile(spliceClassWatcher, "tcph/TPCHIT.sql", SCHEMA_NAME);
        spliceClassWatcher.prepareStatement(format(
                "call SYSCS_UTIL.BULK_IMPORT_HFILE('%s','%s',null,'%s','|','\"',null,null,null,0,null,true,null, '%s', false)",
                SCHEMA_NAME, LINEITEM, getResource("lineitem.tbl"), getResource("data"))).execute();
        spliceClassWatcher.prepareStatement(format(
                "call SYSCS_UTIL.BULK_IMPORT_HFILE('%s','%s',null,'%s','|','\"',null,null,null,0,null,true,null, '%s', false)",
                SCHEMA_NAME, ORDERS, getResource("orders.tbl"), getResource("data"))).execute();
        spliceClassWatcher.prepareStatement(format(
                "call SYSCS_UTIL.BULK_IMPORT_HFILE('%s','%s',null,'%s','|','\"',null,null,null,0,null,true,null, '%s', false)",
                SCHEMA_NAME, CUSTOMERS, getResource("customer.tbl"), getResource("data"))).execute();
        spliceClassWatcher.prepareStatement(format(
                "call SYSCS_UTIL.BULK_IMPORT_HFILE('%s','%s',null,'%s','|','\"',null,null,null,0,null,true,null, '%s', false)",
                SCHEMA_NAME, PARTSUPP, getResource("partsupp.tbl"), getResource("data"))).execute();
        spliceClassWatcher.prepareStatement(format(
                "call SYSCS_UTIL.BULK_IMPORT_HFILE('%s','%s',null,'%s','|','\"',null,null,null,0,null,true,null, '%s', false)",
                SCHEMA_NAME, SUPPLIER, getResource("supplier.tbl"), getResource("data"))).execute();
        spliceClassWatcher.prepareStatement(format(
                "call SYSCS_UTIL.BULK_IMPORT_HFILE('%s','%s',null,'%s','|','\"',null,null,null,0,null,true,null, '%s', false)",
                SCHEMA_NAME, PART, getResource("part.tbl"), getResource("data"))).execute();
        spliceClassWatcher.prepareStatement(format(
                "call SYSCS_UTIL.BULK_IMPORT_HFILE('%s','%s',null,'%s','|','\"',null,null,null,0,null,true,null, '%s', false)",
                SCHEMA_NAME, NATION, getResource("nation.tbl"), getResource("data"))).execute();
        spliceClassWatcher.prepareStatement(format(
                "call SYSCS_UTIL.BULK_IMPORT_HFILE('%s','%s',null,'%s','|','\"',null,null,null,0,null,true,null, '%s', false)",
                SCHEMA_NAME, REGION, getResource("region.tbl"), getResource("data"))).execute();

        spliceClassWatcher
                .prepareStatement(format("call SYSCS_UTIL.COLLECT_SCHEMA_STATISTICS('%s', false)", SCHEMA_NAME))
                .execute();
        spliceClassWatcher.prepareStatement(format("create table A(c varchar(200))"));
        // validate
        assertEquals(9958L, (long) spliceClassWatcher.query("select count(*) from " + LINEITEM));
        assertEquals(2500L, (long) spliceClassWatcher.query("select count(*) from " + ORDERS));
        assertEquals(250L, (long) spliceClassWatcher.query("select count(*) from " + CUSTOMERS));
        assertEquals(1332L, (long) spliceClassWatcher.query("select count(*) from " + PARTSUPP));
        assertEquals(16L, (long) spliceClassWatcher.query("select count(*) from " + SUPPLIER));
        assertEquals(333L, (long) spliceClassWatcher.query("select count(*) from " + PART));
        assertEquals(25L, (long) spliceClassWatcher.query("select count(*) from " + NATION));
        assertEquals(5L, (long) spliceClassWatcher.query("select count(*) from " + REGION));
    } catch (Exception e) {
        java.lang.Throwable ex = Throwables.getRootCause(e);
        if (ex.getMessage().contains("bulk load not supported"))
            notSupported = true;
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.ProcessRdfForm.java

/**
 * Parse the n3Strings to a List of RDF Model objects.
 * //from   ww  w. j a  v  a  2  s .  c o m
 * @param n3Strings
 * @param parseType if OPTIONAL, then don't throw exceptions on errors
 * If REQUIRED, then throw exceptions on errors.
 * @throws Exception 
 */
protected static List<Model> parseN3ToRDF(List<String> n3Strings, N3ParseType parseType) throws Exception {
    List<String> errorMessages = new ArrayList<String>();

    List<Model> rdfModels = new ArrayList<Model>();
    for (String n3 : n3Strings) {
        try {
            Model model = ModelFactory.createDefaultModel();
            StringReader reader = new StringReader(n3);
            model.read(reader, "", "N3");
            rdfModels.add(model);
        } catch (Throwable t) {
            errorMessages.add(t.getMessage() + "\nN3: \n" + n3 + "\n");
        }
    }

    String errors = "";
    for (String errorMsg : errorMessages) {
        errors += errorMsg + '\n';
    }

    if (!errorMessages.isEmpty()) {
        if (REQUIRED.equals(parseType)) {
            throw new Exception("Errors processing required N3. The EditConfiguration should "
                    + "be setup so that if a submission passes validation, there will not be errors "
                    + "in the required N3.\n" + errors);
        } else if (OPTIONAL.equals(parseType)) {
            log.debug("Some Optional N3 did not parse, if a optional N3 does not parse it "
                    + "will be ignored.  This allows optional parts of a form submission to "
                    + "remain unfilled out and then the optional N3 does not get values subsituted in from"
                    + "the form submission values.  It may also be the case that there are unintentional "
                    + "syntax errors the optional N3.");
            log.debug(errors);
        }
    }

    return rdfModels;
}

From source file:org.commonjava.cartographer.rest.util.ResponseUtils.java

public static CharSequence formatEntity(final String id, final Throwable error, final String message) {
    final StringWriter sw = new StringWriter();
    sw.append("Id: ").append(id);
    if (message != null) {
        sw.append("\nMessage: ").append(message);
    }/* ww  w .j a v a  2  s .c  o m*/

    sw.append(error.getMessage());

    final Throwable cause = error.getCause();
    if (cause != null) {
        sw.append("\nError:\n\n");
        cause.printStackTrace(new PrintWriter(sw));
    }

    sw.write('\n');

    return sw.toString();
}

From source file:org.opencastproject.util.IoSupport.java

/**
 * Closes the processes input, output and error streams.
 *
 * @param process// w ww.j  a  va 2 s .c o  m
 *         the process
 * @return <code>true</code> if the streams were closed
 */
public static boolean closeQuietly(final Process process) {
    if (process != null) {
        try {
            if (process.getErrorStream() != null)
                process.getErrorStream().close();
            if (process.getInputStream() != null)
                process.getInputStream().close();
            if (process.getOutputStream() != null)
                process.getOutputStream().close();
            return true;
        } catch (Throwable t) {
            logger.trace("Error closing process streams: " + t.getMessage());
        }
    }
    return false;
}

From source file:com.cloudera.util.InternalHttpServer.java

/**
 * Single attempt to create an http server for the node.
 * /*from w w  w  .j ava  2 s  .c  om*/
 * @param bindAddress
 * @param nodePort
 * @return instance of a started http server or null if failed.
 * @throws BindException
 */
public static InternalHttpServer startHttpServer(ContextCreator cc, String bindAddress, int nodePort)
        throws BindException {
    InternalHttpServer http = null;
    try {
        http = new InternalHttpServer();
        http.setBindAddress(bindAddress);
        http.setPort(nodePort);
        http.setContextCreator(cc);
        http.start();
        return http;
    } catch (BindException be) {
        http.stop();
        http = null;
        throw be;
    } catch (Throwable t) {
        logger.error("Unexpected exception/error thrown! " + t.getMessage(), t);
        // if any exception happens bail out and cleanup.
        http.stop();
        return null;
    }
}

From source file:io.fabric8.collector.git.GitBuildConfigProcessor.java

public static void cloneRepo(File projectFolder, String cloneUrl, CredentialsProvider credentialsProvider,
        final File sshPrivateKey, final File sshPublicKey, String remote) {
    // clone the repo!
    boolean cloneAll = false;
    LOG.info("Cloning git repo " + cloneUrl + " into directory " + projectFolder.getAbsolutePath());
    CloneCommand command = Git.cloneRepository();
    GitHelpers.configureCommand(command, credentialsProvider, sshPrivateKey, sshPublicKey);
    command = command.setCredentialsProvider(credentialsProvider).setCloneAllBranches(cloneAll).setURI(cloneUrl)
            .setDirectory(projectFolder).setRemote(remote);

    try {// ww  w. ja  va2 s .c  o  m
        command.call();
    } catch (Throwable e) {
        LOG.error("Failed to command remote repo " + cloneUrl + " due: " + e.getMessage(), e);
        throw new RuntimeException("Failed to command remote repo " + cloneUrl + " due: " + e.getMessage());
    }
}