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:de.cimt.talendcomp.connectionpool.BasicConnectionPool.java

public static void error(String message, Throwable t) {
    if (t != null && (message == null || message.trim().isEmpty())) {
        message = t.getMessage();
    }/* w w  w .j  av  a2 s. c  o  m*/
    if (logger != null) {
        if (t != null) {
            logger.error(message, t);
        } else {
            logger.error(message);
        }
    } else {
        System.err.println(Thread.currentThread().getName() + ": ERROR: " + message);
        if (t != null) {
            t.printStackTrace(System.err);
        }
    }
}

From source file:gov.nih.nci.caintegrator.application.download.caarray.CaArrayFileDownloadManager.java

protected static void reportError(String message, Throwable e) {
    if (null == message)
        message = "";
    logger.error(message, e);/*from w ww. j  ava  2  s  . com*/
    String e_message = "";
    if (null != e)
        e_message = e.getMessage();
    System.err.println(message + ": " + e_message);
}

From source file:com.adito.agent.client.ProxyUtil.java

/**
 * Attempt to proxy settings from Firefox.
 * /*ww w .  j  av a2  s .c  o m*/
 * @return firefox proxy settings
 * @throws IOException if firefox settings could not be obtained for some
 *         reason
 */
public static BrowserProxySettings lookupFirefoxProxySettings() throws IOException {

    try {

        Vector proxies = new Vector();
        Vector bypassAddr = new Vector();

        File home = new File(Utils.getHomeDirectory());
        File firefoxAppData;

        if (System.getProperty("os.name") != null && System.getProperty("os.name").startsWith("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            firefoxAppData = new File(home, "Application Data\\Mozilla\\Firefox\\profiles.ini"); //$NON-NLS-1$
        } else {
            firefoxAppData = new File(home, ".mozilla/firefox/profiles.ini"); //$NON-NLS-1$
        }

        // Look for Path elements in the profiles.ini
        BufferedReader reader = null;
        Hashtable profiles = new Hashtable();
        String line;
        try {
            reader = new BufferedReader(new InputStreamReader(new FileInputStream(firefoxAppData)));
            String currentProfileName = ""; //$NON-NLS-1$

            while ((line = reader.readLine()) != null) {
                line = line.trim();
                if (line.startsWith("[") && line.endsWith("]")) { //$NON-NLS-1$ //$NON-NLS-2$
                    currentProfileName = line.substring(1, line.length() - 1);
                    continue;
                }

                if (line.startsWith("Path=")) { //$NON-NLS-1$
                    profiles.put(currentProfileName, new File(firefoxAppData.getParent(), line.substring(5)));
                }
            }
        } finally {
            if (reader != null) {
                reader.close();
            }
        }

        // Iterate through all the profiles and load the proxy infos from
        // the prefs.js file

        File prefsJS;
        String profileName;
        for (Enumeration e = profiles.keys(); e.hasMoreElements();) {
            profileName = (String) e.nextElement();
            prefsJS = new File((File) profiles.get(profileName), "prefs.js"); //$NON-NLS-1$
            Properties props = new Properties();
            reader = null;
            try {
                if (!prefsJS.exists()) {
                    // needed to defend against un-initialised profiles.
                    // #ifdef DEBUG
                    log.info("The file " + prefsJS.getAbsolutePath() + " does not exist."); //$NON-NLS-1$
                    // #endif
                    // now remove it from the map.
                    profiles.remove(profileName);
                    continue;
                }
                reader = new BufferedReader(new InputStreamReader(new FileInputStream(prefsJS)));
                while ((line = reader.readLine()) != null) {
                    line = line.trim();
                    if (line.startsWith("user_pref(\"")) { //$NON-NLS-1$
                        int idx = line.indexOf("\"", 11); //$NON-NLS-1$
                        if (idx == -1)
                            continue;
                        String pref = line.substring(11, idx);

                        // Save this position
                        int pos = idx + 1;

                        // Look for another quote
                        idx = line.indexOf("\"", idx + 1); //$NON-NLS-1$

                        String value;
                        if (idx == -1) {
                            // No more quotes
                            idx = line.indexOf(" ", pos); //$NON-NLS-1$

                            if (idx == -1)
                                continue;

                            int idx2 = line.indexOf(")", pos); //$NON-NLS-1$

                            if (idx2 == -1)
                                continue;

                            value = line.substring(idx + 1, idx2);

                        } else {

                            // String value
                            int idx2 = line.indexOf("\"", idx + 1); //$NON-NLS-1$

                            if (idx2 == -1)
                                continue;

                            value = line.substring(idx + 1, idx2);
                        }

                        props.put(pref, value);

                    }
                }
            } finally {
                if (reader != null) {
                    reader.close();
                }
            }
            ProxyInfo p;
            /**
             * Extract some proxies from the properites, if the proxy is
             * enabled
             */
            if ("1".equals(props.get("network.proxy.type"))) { //$NON-NLS-1$ //$NON-NLS-2$
                boolean isProfileActive = checkProfileActive(prefsJS);
                if (props.containsKey("network.proxy.ftp")) { //$NON-NLS-1$
                    p = createProxyInfo(
                            "ftp=" + props.get("network.proxy.ftp") + ":" + props.get("network.proxy.ftp_port"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                            "Firefox Profile [" + profileName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    p.setActiveProfile(isProfileActive);
                    proxies.addElement(p);
                }

                if (props.containsKey("network.proxy.http")) { //$NON-NLS-1$
                    p = createProxyInfo(
                            "http=" + props.get("network.proxy.http") + ":" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                                    + props.get("network.proxy.http_port"), //$NON-NLS-1$
                            "Firefox Profile [" + profileName + "]"); //$NON-NLS-1$ //$NON-NLS-2$
                    p.setActiveProfile(isProfileActive);
                    proxies.addElement(p);
                }

                if (props.containsKey("network.proxy.ssl")) { //$NON-NLS-1$
                    p = createProxyInfo(
                            "ssl=" + props.get("network.proxy.ssl") + ":" + props.get("network.proxy.ssl_port"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                            "Firefox Profile [" + profileName + "]"); //$NON-NLS-1$ //$NON-NLS-2$
                    p.setActiveProfile(isProfileActive);
                    proxies.addElement(p);
                }

                if (props.containsKey("network.proxy.socks")) { //$NON-NLS-1$
                    p = createProxyInfo("socks=" + props.get("network.proxy.socks") + ":" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                            + props.get("network.proxy.socks_port"), "Firefox Profile [" + profileName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    p.setActiveProfile(isProfileActive);
                    proxies.addElement(p);
                }

                if (props.containsKey("network.proxy.no_proxies_on")) { //$NON-NLS-1$

                    StringTokenizer tokens = new StringTokenizer(
                            props.getProperty("network.proxy.no_proxies_on"), ","); //$NON-NLS-1$ //$NON-NLS-2$

                    while (tokens.hasMoreTokens()) {
                        bypassAddr.addElement(((String) tokens.nextToken()).trim());
                    }

                }
            }
        }

        // need to ensure that the returned values are sorted correctly...
        BrowserProxySettings bps = new BrowserProxySettings();
        bps.setBrowser("Mozilla Firefox"); //$NON-NLS-1$
        bps.setProxiesActiveFirst(proxies);
        bps.setBypassAddr(new String[bypassAddr.size()]);
        bypassAddr.copyInto(bps.getBypassAddr());
        return bps;

    } catch (Throwable t) {
        throw new IOException("Failed to get proxy information from Firefox profiles: " + t.getMessage()); //$NON-NLS-1$
    }
}

From source file:com.qualogy.qafe.business.integration.java.JavaServiceProcessor.java

private static String resolveErrorMessage(Throwable cause) {
    String errorMessage = null;// www.  java2  s.  co  m
    if (cause instanceof NullPointerException) {
        StackTraceElement[] stackTraceElements = ((NullPointerException) cause).getStackTrace();
        StackTraceElement stackTraceElement = stackTraceElements[0];
        errorMessage = cause.toString() + ": " + stackTraceElement.toString();
    } else {
        errorMessage = cause.getMessage();
    }
    if (errorMessage != null) {
        errorMessage = errorMessage.trim();
    }
    return errorMessage;
}

From source file:io.debezium.data.VerifyRecord.java

protected static String prettyJson(JsonNode json) {
    try {//from  w  w w .  jav  a2 s . c  o  m
        return new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(json);
    } catch (Throwable t) {
        Testing.printError(t);
        fail(t.getMessage());
        assert false : "Will not get here";
        return null;
    }
}

From source file:com.evolveum.midpoint.report.impl.ReportUtils.java

public static String prettyPrintForReport(Object value) {
    if (value == null) {
        return "";
    }/*from   w w w. ja  va  2s . c  o  m*/

    if (value instanceof MetadataType) {
        return "";
    }

    //special handling for byte[], some problems with jasper when printing 
    if (byte[].class.equals(value.getClass())) {
        return prettyPrintForReport((byte[]) value);
    }

    // 1. Try to find prettyPrintForReport in this class first
    if (value instanceof Containerable) { //e.g. RoleType needs to be converted to PCV in order to format properly
        value = (((Containerable) value).asPrismContainerValue());
    }

    for (Method method : ReportUtils.class.getMethods()) {
        if (method.getName().equals("prettyPrintForReport")) {
            Class<?>[] parameterTypes = method.getParameterTypes();
            if (parameterTypes.length == 1 && parameterTypes[0].equals(value.getClass())) {
                try {
                    return (String) method.invoke(null, value);
                } catch (Throwable e) {
                    return "###INTERNAL#ERROR### " + e.getClass().getName() + ": " + e.getMessage()
                            + "; prettyPrintForReport method for value " + value;
                }
            }
        }
    }

    // 2. Default to PrettyPrinter.prettyPrint
    String str = PrettyPrinter.prettyPrint(value);
    if (str.length() > 1000) {
        return str.substring(0, 1000);
    }
    return str;

}

From source file:edu.stanford.epad.epadws.handlers.HandlerUtil.java

public static int warningJSONResponse(int responseCode, String message, Throwable t, EPADLogger log) {
    String finalMessage = message + (t == null ? "" : ((t.getMessage() == null) ? "" : ": " + t.getMessage()));
    log.warning(finalMessage, t);/*from w w  w  .j  a  va  2  s  .c o  m*/
    return responseCode;
}

From source file:edu.stanford.epad.epadws.handlers.HandlerUtil.java

public static int warningResponse(int responseCode, String message, Throwable t, EPADLogger log) {
    String finalMessage = message + (t == null ? "" : ((t.getMessage() == null) ? "" : ": " + t.getMessage()));
    log.warning(finalMessage, t);//from w w w  . j  a v a  2s . c  o m
    return responseCode;
}

From source file:com.pedox.plugin.HttpClient.HttpClient.java

private static void handleResult(boolean success, int statusCode, Header[] headers, String responseString,
        CallbackContext callbackContext, Throwable throwable) {
    JSONObject result = new JSONObject();
    try {// w w  w.  j  a v  a2 s  . c  o  m
        /** Set header **/
        JSONObject headerParam = new JSONObject();
        if (headers != null) {
            for (Header param : headers) {
                headerParam.put(param.getName(), param.getValue());
            }
        }
        if (throwable != null) {
            result.put("error", throwable.getMessage());
        }
        result.put("result", responseString);
        result.put("code", statusCode);
        result.put("header", headerParam);
        if (success == true) {
            callbackContext.success(result);
        } else {
            callbackContext.error(result);
        }
    } catch (JSONException e) {
        callbackContext.error(0);
        e.printStackTrace();
    }
}

From source file:com.taobao.android.builder.tools.proguard.BundleProguarder.java

public static void execute(AppVariantContext appVariantContext, Input input) throws Exception {
    if (input.proguardOutputDir != null && input.proguardOutputDir.exists()) {
        FileUtils.cleanDirectory(input.proguardOutputDir);
    }//  www .  ja va  2s  .c  om
    if (!appVariantContext.getAtlasExtension().getTBuildConfig().isProguardCacheEnabled()) {
        doProguard(appVariantContext, input);
        return;
    }

    String md5 = input.getMd5();

    Result result = loadProguardFromCache(appVariantContext, input);

    String bundleName = input.getAwbBundles().get(0).getAwbBundle().getName();

    if (result.success) {
        fileLogger.log(bundleName + " hit cache " + result.cacheDir.getAbsolutePath());
        return;
    }
    fileLogger.log(bundleName + " miss cache " + result.cacheDir.getAbsolutePath());

    long startTime = System.currentTimeMillis();
    doProguard(appVariantContext, input);
    double during = (System.currentTimeMillis() - startTime) / 1000.0;
    fileLogger.log(bundleName + "proguard consume (s) " + during);

    //cache
    if (null != result.cacheDir) {
        try {
            cacheProguard(appVariantContext, input, result);
        } catch (Throwable e) {
            logger.error(e.getMessage(), e);
        }
    }

}