Example usage for java.lang Throwable printStackTrace

List of usage examples for java.lang Throwable printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.onesignal.OneSignalStateSynchronizer.java

private static boolean response400WithErrorsContaining(int statusCode, String response, String contains) {
    if (statusCode == 400 && response != null) {
        try {/*from   w  ww  .j  a  v a 2 s . com*/
            JSONObject responseJson = new JSONObject(response);
            return responseJson.has("errors") && responseJson.optString("errors").contains(contains);
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }

    return false;
}

From source file:models.data.providers.LogProvider.java

/**
 * 20130924: add for all none standard folder and folder of adhoc components
 * /*  w  w w  .  j  a  v a2 s.com*/
 * @param dateForArchive
 * @param logFolder
 */
public static void moveFilesForAppLogs(String dateForArchive, String logFolder) {

    try {
        String appLogsFolderPath = logFolder;
        List<String> fileNamesForAppLogs = FileIoUtils.getFileNamesInFolder(appLogsFolderPath);

        String destDirPath = generateAppLogAchiveFolderDate(dateForArchive, logFolder);

        // now create folder
        FileIoUtils.createFolder(destDirPath);

        File destDir = new File(destDirPath);

        for (String appLogFileName : fileNamesForAppLogs) {

            // only move for that date.
            if (!appLogFileName.startsWith(dateForArchive)
                    // 201309 for none standard logs and for ADHOCDATASTORE
                    // components
                    && !(appLogFileName.startsWith(VarUtils.ADHOCDATASTORE)
                            && appLogFileName.contains(dateForArchive))

            ) {
                continue;
            }

            String appLogAbsolutePath = generateAppLogAbsolutePath(logFolder);
            String appLogFileFullPath = appLogAbsolutePath + appLogFileName;

            File srcFile = new File(appLogFileFullPath);
            FileUtils.moveFileToDirectory(srcFile, destDir, true);

        } // end for loop

    } catch (Throwable e) {
        e.printStackTrace();
        models.utils.LogUtils
                .printLogError("Error in moveFilesForAppLogs " + DateUtils.getNowDateTimeStrSdsm());
    }

}

From source file:models.data.providers.LogProvider.java

public static boolean archiveAppLogsDailyJob() {
    boolean success = true;

    try {// w  w  w . j a  v a 2  s. c o  m

        List<String> noneAdhocLogArchiveDates = new ArrayList<String>();
        // keep 3 days
        // redundency here: in case some time the cron did not run.

        noneAdhocLogArchiveDates.add(DateUtils.getNDayBeforeTodayStr(VarUtils.ARCHIVE_LOG_DATE_BASE3));
        noneAdhocLogArchiveDates.add(DateUtils.getNDayBeforeTodayStr(VarUtils.ARCHIVE_LOG_DATE_BASE3 + 1));
        noneAdhocLogArchiveDates.add(DateUtils.getNDayBeforeTodayStr(VarUtils.ARCHIVE_LOG_DATE_BASE3 + 2));

        List<String> adhocLogArchiveDates = new ArrayList<String>();
        adhocLogArchiveDates.add(DateUtils.getNDayBeforeTodayStr(VarUtils.ARCHIVE_LOG_DATE_BASE3));
        adhocLogArchiveDates.add(DateUtils.getNDayBeforeTodayStr(VarUtils.ARCHIVE_LOG_DATE_BASE3 + 1));
        adhocLogArchiveDates.add(DateUtils.getNDayBeforeTodayStr(VarUtils.ARCHIVE_LOG_DATE_BASE3 + 2));

        for (String archiveDate : noneAdhocLogArchiveDates) {
            LogProvider.moveFilesForAppLogs(archiveDate, VarUtils.LOG_FOLDER_NAME_APP_WITH_SLASH);

        }

        for (String archiveDateAdhoc : adhocLogArchiveDates) {
            // 2013094: add other log folders
            LogProvider.moveFilesForAppLogs(archiveDateAdhoc, VarUtils.LOG_FOLDER_NAME_ADHOC_WITH_SLASH);
            LogProvider.moveFilesForAppLogs(archiveDateAdhoc, VarUtils.LOG_FOLDER_NAME_NONESTARDARD_WITH_SLASH);

            LogProvider.moveFilesForAppLogs(archiveDateAdhoc,
                    VarUtils.LOG_FOLDER_NAME_ADHOC_COMPONENTS_AGGREGATION_RULES + "/");
            LogProvider.moveFilesForAppLogs(archiveDateAdhoc,
                    VarUtils.LOG_FOLDER_NAME_ADHOC_COMPONENTS_COMMANDS + "/");
            LogProvider.moveFilesForAppLogs(archiveDateAdhoc,
                    VarUtils.LOG_FOLDER_NAME_ADHOC_COMPONENTS_NODE_GROUPS + "/");

        }

        models.utils.LogUtils.printLogNormal("Success archive app archiveAppLogsDailyJob");
    } catch (Throwable t) {
        t.printStackTrace();
        models.utils.LogUtils.printLogNormal("Error occured in archiveAppLogsDailyJob ");

        success = false;
    }
    return success;

}

From source file:models.data.providers.LogProvider.java

/**
 * 20131009 add cron to delete logs/*from w w  w . j  a  v a 2  s. co  m*/
 * 
 * @return
 */
public static boolean deleteAppLogsDailyJob() {
    boolean success = true;

    try {

        List<String> noneAdhocLogArchiveDates = new ArrayList<String>();
        // keep 7 days
        // redundency here: in case some time the cron did not run.

        noneAdhocLogArchiveDates.add(DateUtils.getNDayBeforeTodayStr(VarUtils.DELETE_LOG_DATE_BASE4));
        noneAdhocLogArchiveDates.add(DateUtils.getNDayBeforeTodayStr(VarUtils.DELETE_LOG_DATE_BASE4 + 1));
        noneAdhocLogArchiveDates.add(DateUtils.getNDayBeforeTodayStr(VarUtils.DELETE_LOG_DATE_BASE4 + 2));

        List<String> adhocLogArchiveDates = new ArrayList<String>();
        adhocLogArchiveDates.add(DateUtils.getNDayBeforeTodayStr(VarUtils.DELETE_LOG_DATE_BASE4));
        adhocLogArchiveDates.add(DateUtils.getNDayBeforeTodayStr(VarUtils.DELETE_LOG_DATE_BASE4 + 1));
        adhocLogArchiveDates.add(DateUtils.getNDayBeforeTodayStr(VarUtils.DELETE_LOG_DATE_BASE4 + 2));

        for (String archiveDate : noneAdhocLogArchiveDates) {
            LogProvider.deleteFilesForOneLogFolderOnDate(archiveDate, VarUtils.LOG_FOLDER_NAME_APP_WITH_SLASH);

        }

        for (String archiveDateAdhoc : adhocLogArchiveDates) {
            // 2013094: add other log folders
            LogProvider.deleteFilesForOneLogFolderOnDate(archiveDateAdhoc,
                    VarUtils.LOG_FOLDER_NAME_ADHOC_WITH_SLASH);
            LogProvider.deleteFilesForOneLogFolderOnDate(archiveDateAdhoc,
                    VarUtils.LOG_FOLDER_NAME_NONESTARDARD_WITH_SLASH);

            LogProvider.deleteFilesForOneLogFolderOnDate(archiveDateAdhoc,
                    VarUtils.LOG_FOLDER_NAME_ADHOC_COMPONENTS_AGGREGATION_RULES + "/");
            LogProvider.deleteFilesForOneLogFolderOnDate(archiveDateAdhoc,
                    VarUtils.LOG_FOLDER_NAME_ADHOC_COMPONENTS_COMMANDS + "/");
            LogProvider.deleteFilesForOneLogFolderOnDate(archiveDateAdhoc,
                    VarUtils.LOG_FOLDER_NAME_ADHOC_COMPONENTS_NODE_GROUPS + "/");

        }

        models.utils.LogUtils.printLogNormal("Success archive app archiveAppLogsDailyJob");
    } catch (Throwable t) {
        t.printStackTrace();
        models.utils.LogUtils.printLogNormal("Error occured in archiveAppLogsDailyJob ");

        success = false;
    }
    return success;

}

From source file:org.nebulaframework.grid.Grid.java

private static void initializeDefaultExceptionHandler() {
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override/* www. ja  va  2  s  .  c o  m*/
        public void uncaughtException(Thread t, Throwable e) {
            log.fatal("[Uncaught Thread Exception] on Thread " + t.getName() + " - " + e, e);
            e.printStackTrace();
        }

    });
}

From source file:com.rsegismont.androlife.core.utils.AndrolifeUtils.java

private static String[][] getCursorValues(Context paramContext, int paramInt, Calendar... paramVarArgs) {

    String[] arrayOfString1;//from  w  w w  .ja v  a  2  s  . c  o m
    String[] arrayOfString2;
    try {
        final SharedPreferences localSharedPreferences = PreferenceManager
                .getDefaultSharedPreferences(paramContext);
        String str1 = SharedInformation.DatabaseColumn.TYPE.stringValue + "<>? AND "
                + SharedInformation.DatabaseColumn.TYPE.stringValue + "<>? AND "
                + SharedInformation.DatabaseColumn.TYPE.stringValue + "<>?";
        String str2 = "";
        String str3 = "";
        String str4 = "";
        if (!localSharedPreferences.getBoolean("settings_filters_clip", true)) {
            str2 = "Clip";
        }
        if (!localSharedPreferences.getBoolean("settings_filters_magazines", true)) {
            str3 = "Magazine";
        }
        if (!localSharedPreferences.getBoolean("settings_filters_series", true)) {
            str4 = "Fiction";
        }

        arrayOfString1 = new String[paramVarArgs.length >= 2 ? 5 : 3];
        arrayOfString1[0] = str2;
        arrayOfString1[1] = str4;
        arrayOfString1[2] = str3;

        if (paramVarArgs.length >= 2) {
            str1 = str1 + " AND " + SharedInformation.DatabaseColumn.DATE_UTC.stringValue + " BETWEEN ? AND ?";
            arrayOfString1[3] = "" + paramVarArgs[0].getTime().getTime();
            arrayOfString1[4] = "" + paramVarArgs[1].getTime().getTime();
        }

        switch (paramInt) {
        case Constantes.CURSOR_SELECTION:
            arrayOfString2 = new String[1 + arrayOfString1.length];
            System.arraycopy(arrayOfString1, 0, arrayOfString2, 0, arrayOfString1.length);
            str1 = str1 + " AND " + SharedInformation.DatabaseColumn.LEVELTYPE.stringValue + "=?";
            arrayOfString2[arrayOfString1.length] = "110";
            break;
        case Constantes.CURSOR_NEWS:
            arrayOfString2 = new String[1 + arrayOfString1.length];
            System.arraycopy(arrayOfString1, 0, arrayOfString2, 0, arrayOfString1.length);
            str1 = str1 + " AND " + SharedInformation.DatabaseColumn.PREMIERE_DIFFUSION.stringValue + "=?";
            arrayOfString2[arrayOfString1.length] = "1";
            break;
        default:
            arrayOfString2 = new String[arrayOfString1.length];
            System.arraycopy(arrayOfString1, 0, arrayOfString2, 0, arrayOfString1.length);
            break;
        }

        String[][] arrayOfString = (String[][]) Array.newInstance(String.class,
                new int[] { 2, arrayOfString2.length });
        arrayOfString[0][0] = str1;
        arrayOfString[1] = arrayOfString2;
        return arrayOfString;
    } catch (Throwable localThrowable) {
        localThrowable.printStackTrace();
        return null;
    }

}

From source file:com.aw.support.reflection.MethodInvoker.java

/**
 * @param target/*from  w  ww . j  a  v  a2  s. c  o m*/
 * @param methodName
 * @param parameter
 * @return
 * @throws Throwable
 */
public static Object invoke(Object target, String methodName, Object parameter) throws Throwable {
    Object result = null;
    try {
        Class cls = target.getClass();
        Class[] paramTypes = new Class[] { Object.class };
        Method method = cls.getMethod(methodName, paramTypes);
        result = method.invoke(target, new Object[] { parameter });
    } catch (Throwable e) {
        Throwable cause = e.getCause();
        if ((cause instanceof FlowBreakSilentlyException) || (cause instanceof AWException)
                || (cause instanceof DataIntegrityViolationException)) {
            throw cause;
        }
        e.printStackTrace();
        throw e;

    }
    return result;
}

From source file:com.aw.support.reflection.MethodInvoker.java

/**
 * @param target/* w  w  w. j av  a  2s.c o  m*/
 * @param methodName
 * @param parameter
 * @return
 * @throws Throwable
 */
public static Object invoke(Object target, String methodName, Object parameter, Class parameterType)
        throws Throwable {
    Object result = null;
    try {
        Class cls = target.getClass();
        Class[] paramTypes = new Class[] { parameterType };
        Method method = cls.getMethod(methodName, paramTypes);
        result = method.invoke(target, new Object[] { parameter });
    } catch (Throwable e) {
        Throwable cause = e.getCause();
        if ((cause instanceof FlowBreakSilentlyException) || (cause instanceof AWException)
                || (cause instanceof DataIntegrityViolationException)) {
            throw cause;
        }
        e.printStackTrace();
        throw e;
    }
    return result;
}

From source file:de.dailab.plistacontest.client.RecommenderItem.java

/**
 * parse the event notification./*w  ww. jav  a2 s  .  c o m*/
 * 
 * @param _jsonMessageBody
 * @return
 */
public static RecommenderItem parseEventNotification(final String _jsonMessageBody) {

    try {
        final JSONObject jsonObj = (JSONObject) JSONValue.parse(_jsonMessageBody);

        // parse JSON structure to obtain "context.simple"
        JSONObject jsonObjectContext = (JSONObject) jsonObj.get("context");
        JSONObject jsonObjectContextSimple = (JSONObject) jsonObjectContext.get("simple");

        Long domainID = -3L;
        try {
            domainID = Long.valueOf(jsonObjectContextSimple.get("27").toString());
        } catch (Exception ignored) {
            try {
                domainID = Long.valueOf(jsonObj.get("domainID").toString());
            } catch (Exception e) {
                System.err.println("[Exception] no domainID found in " + _jsonMessageBody);
            }
        }

        Long itemID = null;
        try {
            itemID = Long.valueOf(jsonObjectContextSimple.get("25").toString());
        } catch (Exception ignored) {
            try {
                itemID = Long.valueOf(jsonObj.get("itemID").toString());
            } catch (Exception e) {
                System.err.println("[Exception] no itemID found in " + _jsonMessageBody);
            }
        }

        Long userID = -2L;
        try {
            userID = Long.valueOf(jsonObjectContextSimple.get("57").toString());
        } catch (Exception ignored) {
            try {
                userID = Long.valueOf(jsonObj.get("userID").toString());
            } catch (Exception e) {
                System.err.println("[Exception] no userID found in " + _jsonMessageBody);
            }
        }

        // impressionType
        String notificationType = null;
        try {
            notificationType = jsonObj.get("type") + "";
        } catch (Exception e) {
            e.printStackTrace();
        }

        // event_type due to the idomaar data format
        String eventType = null;
        try {
            eventType = jsonObj.get("event_type") + "";
            if (!"null".equals(eventType)) {
                notificationType = eventType;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        // list of displayed recs
        List<Long> listOfDisplayedRecs = new ArrayList<Long>(6);
        try {
            Object jsonObjectRecsTmp = jsonObj.get("recs");
            if (jsonObjectRecsTmp == null || !(jsonObjectRecsTmp instanceof JSONObject)) {
                System.err.println("[INFO] impression without recs " + jsonObj);
            } else {
                JSONObject jsonObjectRecs = (JSONObject) jsonObjectRecsTmp;
                JSONObject jsonObjectRecsInt = (JSONObject) jsonObjectRecs.get("ints");
                JSONArray array = (JSONArray) jsonObjectRecsInt.get("3");
                for (Object arrayEntry : array) {
                    listOfDisplayedRecs.add(Long.valueOf(arrayEntry + ""));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("invalid jsonObject: " + jsonObj);
        }

        long timeStamp = 0;
        try {
            timeStamp = (Long) jsonObj.get("created_at") + 0L;
        } catch (Exception ignored) {
            timeStamp = (Long) jsonObj.get("timestamp");
        }

        // create the result and return
        RecommenderItem result = new RecommenderItem(userID, itemID, domainID, timeStamp);
        result.setNotificationType(notificationType);
        result.setListOfDisplayedRecs(listOfDisplayedRecs);

        return result;

    } catch (Throwable t) {
        t.printStackTrace();
        return null;
    }
}

From source file:com.l2jfree.L2Config.java

protected static void shutdownApplication() {
    try {/*from  www.  j a va 2 s .c  o  m*/
        L2Database.shutdown();
    } catch (Throwable t) {
        t.printStackTrace();
    }

    try {
        L2ThreadPool.shutdown();
    } catch (Throwable t) {
        t.printStackTrace();
    }

    try {
        L2Config.storeConfigs();
    } catch (Throwable t) {
        t.printStackTrace();
    }
}