Example usage for java.lang Exception toString

List of usage examples for java.lang Exception toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.github.checkstyle.Main.java

/**
 * Publish on xdoc./* w w  w .java  2  s  .  c o m*/
 * @param cliOptions command line options.
 * @param errors list of publication errors.
 */
private static void runXdocPublication(CliOptions cliOptions, List<String> errors) {
    final XdocPublisher xdocPublisher = new XdocPublisher(cliOptions.getOutputLocation() + XDOC_FILENAME,
            cliOptions.getLocalRepoPath(), cliOptions.getReleaseNumber(), cliOptions.isPublishXdocWithPush(),
            cliOptions.getAuthToken());
    try {
        xdocPublisher.publish();
    }
    // -@cs[IllegalCatch] We should execute all publishers, so cannot fail-fast
    catch (Exception ex) {
        errors.add(ex.toString());
    }
}

From source file:com.github.checkstyle.Main.java

/**
 * Publish on mailing list.// w  ww .  ja  v a  2s  . co m
 * @param cliOptions command line options.
 * @param errors list of publication errors.
 */
private static void runMailingListPublication(CliOptions cliOptions, List<String> errors) {
    final MailingListPublisher mailingListPublisher = new MailingListPublisher(
            cliOptions.getOutputLocation() + MLIST_FILENAME, cliOptions.getMlistUsername(),
            cliOptions.getMlistPassword(), cliOptions.getReleaseNumber());
    try {
        mailingListPublisher.publish();
    }
    // -@cs[IllegalCatch] We should execute all publishers, so cannot fail-fast
    catch (Exception ex) {
        errors.add(ex.toString());
    }
}

From source file:com.github.checkstyle.Main.java

/**
 * Publish on RSS.//from w ww. jav  a2s .  c  om
 * @param cliOptions command line options.
 * @param errors list of publication errors.
 */
private static void runSfRssPublication(CliOptions cliOptions, List<String> errors) {
    final SourceforgeRssPublisher rssPublisher = new SourceforgeRssPublisher(
            cliOptions.getOutputLocation() + RSS_FILENAME, cliOptions.getSfRssBearerToken(),
            cliOptions.getReleaseNumber());
    try {
        rssPublisher.publish();
    }
    // -@cs[IllegalCatch] We should execute all publishers, so cannot fail-fast
    catch (Exception ex) {
        errors.add(ex.toString());
    }
}

From source file:com.pfarrell.crypto.HmacUtil.java

/**
 * calculate an HMAC using the SHA256 algorithm.
 * Given a secret and message, returns a sha256 hash of the message.
 * (no longer uses SHA1)/*from   w  w w .j  a  v a  2s. c o  m*/
 * @param secret string known to both parties
 * @param message to sign
 * @return hexified result
 */
public static String hmac(String secret, byte[] message) {
    Preconditions.checkNotNull(secret);
    Preconditions.checkNotNull(message);
    byte[] gas = null;
    try {
        MessageDigest digest = MessageDigest.getInstance("SHA-256");

        byte[] sbytes = secret.getBytes();
        digest.update(sbytes);
        digest.update(message);
        digest.update(sbytes);
        gas = digest.digest();

    } catch (Exception e) {
        System.out.println("WebUtils.hamac - caught exception: " + e.toString());
    }
    return hexify(gas);
}

From source file:com.github.checkstyle.Main.java

/**
 * Publish on Twitter.//w w  w  . j a  v a2s  .c  om
 * @param cliOptions command line options.
 * @param errors list of publication errors.
 */
private static void runTwitterPublication(CliOptions cliOptions, List<String> errors) {
    final TwitterPublisher twitterPublisher = new TwitterPublisher(
            cliOptions.getOutputLocation() + TWITTER_FILENAME, cliOptions.getTwitterConsumerKey(),
            cliOptions.getTwitterConsumerSecret(), cliOptions.getTwitterAccessToken(),
            cliOptions.getTwitterAccessTokenSecret());
    try {
        twitterPublisher.publish();
    }
    // -@cs[IllegalCatch] We should execute all publishers, so cannot fail-fast
    catch (Exception ex) {
        errors.add(ex.toString());
    }
}

From source file:com.google.cloud.hadoop.util.LogUtilTest.java

/**
 * Verifies that the logged message is as expected.
 *
 * @param category Category of the message (INFO, WARN or ERROR).
 * @param message Message format string.
 * @param args Optional format parameters.
 *///from  w  w w . j a va2s.co  m
private static void verifyLoggedMessage(String category, String message, Exception e) {
    String expectedMessagePrefix = category + " - " + message + "\n";
    expectedMessagePrefix += e.toString() + "\n";
    String actualMessage = sw.getBuffer().substring(logIndex);
    logIndex += actualMessage.length();
    Assert.assertEquals(expectedMessagePrefix, actualMessage.substring(0, expectedMessagePrefix.length()));
}

From source file:controllers.api.v2.Dataset.java

public static Promise<Result> listSegments(@Nullable String platform, @Nonnull String prefix) {
    try {//from  w  w  w .  ja  v  a2 s. co  m
        if (StringUtils.isBlank(platform)) {
            return Promise.promise(() -> ok(Json.toJson(DATA_TYPES_DAO.getAllPlatforms().stream()
                    .map(s -> s.get("name")).collect(Collectors.toList()))));
        }

        List<String> names = DATASET_VIEW_DAO.listSegments(platform, "PROD",
                getPlatformPrefix(platform, prefix));

        // if prefix is a dataset name, then return empty list
        if (names.size() == 1 && names.get(0).equalsIgnoreCase(prefix)) {
            return Promise.promise(() -> ok(Json.toJson(Collections.emptyList())));
        }

        return Promise.promise(() -> ok(Json.toJson(names)));
    } catch (Exception e) {
        Logger.error("Fail to list dataset names/sections", e);
        return Promise.promise(() -> internalServerError("Fetch data Error: " + e.toString()));
    }
}

From source file:com.bigtobster.pgnextractalt.commands.CommandContext.java

/**
 * Logs a severe error in logs/*from   w  w  w.j a  va 2  s  .  co m*/
 *
 * @param logger    The erring class's Logger
 * @param message   The message to be logged
 * @param exception The exception causing the error
 */
@SuppressWarnings("SameParameterValue")
private static void logSevereError(@SuppressWarnings("SameParameterValue") final Logger logger,
        final String message, final Exception exception) {
    logger.log(Level.SEVERE, message);
    logger.log(Level.SEVERE, exception.getMessage());
    logger.log(Level.SEVERE, exception.toString(), exception.fillInStackTrace());
}

From source file:org.apache.jmeter.protocol.http.sampler.HttpClientDefaultParameters.java

private static void load(String file, GenericHttpParams params) {
    log.info("Trying httpclient parameters from " + file);
    File f = new File(file);
    if (!(f.exists() && f.canRead())) {
        f = new File(NewDriver.getJMeterDir() + File.separator + "bin" + File.separator + file); // $NON-NLS-1$
        log.info(file + " httpclient parameters does not exist, trying " + f.getAbsolutePath());
        if (!(f.exists() && f.canRead())) {
            log.error("Cannot read parameters file for HttpClient: " + file);
            return;
        }//from   ww  w .ja  v a2s . co  m
    }
    log.info("Reading httpclient parameters from " + f.getAbsolutePath());
    InputStream is = null;
    Properties props = new Properties();
    try {
        is = new FileInputStream(f);
        props.load(is);
        for (Map.Entry<Object, Object> me : props.entrySet()) {
            String key = (String) me.getKey();
            String value = (String) me.getValue();
            int typeSep = key.indexOf('$'); // $NON-NLS-1$
            try {
                if (typeSep > 0) {
                    String type = key.substring(typeSep + 1);// get past separator
                    String name = key.substring(0, typeSep);
                    log.info("Defining " + name + " as " + value + " (" + type + ")");
                    if (type.equals("Integer")) {
                        params.setParameter(name, Integer.valueOf(value));
                    } else if (type.equals("Long")) {
                        params.setParameter(name, Long.valueOf(value));
                    } else if (type.equals("Boolean")) {
                        params.setParameter(name, Boolean.valueOf(value));
                    } else if (type.equals("HttpVersion")) { // Commons HttpClient only
                        params.setVersion(name, value);
                    } else {
                        log.warn("Unexpected type: " + type + " for name " + name);
                    }
                } else {
                    log.info("Defining " + key + " as " + value);
                    params.setParameter(key, value);
                }
            } catch (Exception e) {
                log.error("Error in property: " + key + "=" + value + " " + e.toString());
            }
        }
    } catch (IOException e) {
        log.error("Problem loading properties " + e.toString());
    } finally {
        JOrphanUtils.closeQuietly(is);
    }
}

From source file:gov.nist.appvet.tool.synchtest.util.ReportUtil.java

/** This method should be used for sending files back to AppVet. */
public static boolean sendInNewHttpRequest(String appId, String reportFilePath, ToolStatus reportStatus) {
    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, 30000);
    HttpConnectionParams.setSoTimeout(httpParameters, 1200000);
    HttpClient httpClient = new DefaultHttpClient(httpParameters);
    httpClient = SSLWrapper.wrapClient(httpClient);
    try {/*  w w w  .  jav  a2 s  .com*/
        /*
         * To send reports back to AppVet, the following parameters must be
         * sent: - command: SUBMIT_REPORT - username: AppVet username -
         * password: AppVet password - appid: The app ID - toolid: The ID of
         * this tool - toolrisk: The risk assessment (LOW, MODERATE, HIGH,
         * ERROR) - report: The report file.
         */
        MultipartEntity entity = new MultipartEntity();
        entity.addPart("command", new StringBody("SUBMIT_REPORT", Charset.forName("UTF-8")));
        entity.addPart("username", new StringBody(Properties.appvetUsername, Charset.forName("UTF-8")));
        entity.addPart("password", new StringBody(Properties.appvetPassword, Charset.forName("UTF-8")));
        entity.addPart("appid", new StringBody(appId, Charset.forName("UTF-8")));
        entity.addPart("toolid", new StringBody(Properties.toolId, Charset.forName("UTF-8")));
        entity.addPart("toolrisk", new StringBody(reportStatus.name(), Charset.forName("UTF-8")));
        File report = new File(reportFilePath);
        FileBody fileBody = new FileBody(report);
        entity.addPart("file", fileBody);
        HttpPost httpPost = new HttpPost(Properties.appvetUrl);
        httpPost.setEntity(entity);
        // Send the report to AppVet
        log.debug("Sending report file to AppVet");
        final HttpResponse response = httpClient.execute(httpPost);
        log.debug("Received from AppVet: " + response.getStatusLine());
        // Clean up
        httpPost = null;
        return true;
    } catch (Exception e) {
        log.error(e.toString());
        return false;
    }
}