Example usage for org.apache.commons.lang3.exception ExceptionUtils getStackTrace

List of usage examples for org.apache.commons.lang3.exception ExceptionUtils getStackTrace

Introduction

In this page you can find the example usage for org.apache.commons.lang3.exception ExceptionUtils getStackTrace.

Prototype

public static String getStackTrace(final Throwable throwable) 

Source Link

Document

Gets the stack trace from a Throwable as a String.

The result of this method vary by JDK version as this method uses Throwable#printStackTrace(java.io.PrintWriter) .

Usage

From source file:com.aurel.track.fieldType.bulkSetters.IntegerBulkSetter.java

@Override
public Object fromDisplayString(Map<String, String> displayStringMap, Locale locale) {
    if (displayStringMap == null) {
        return null;
    }/* w  ww  .j  a v  a2 s  .co m*/
    String value = displayStringMap.get(getKeyPrefix());
    if (value == null) {
        return null;
    }
    switch (getRelation()) {
    case BulkRelations.SET_TO:
    case BulkRelations.ADD_IF_SET:
    case BulkRelations.ADD_OR_SET:
        try {
            return Integer.valueOf(value);
        } catch (Exception e) {
            LOGGER.warn(
                    "Converting the " + value + " to Integer for display string failed with " + e.getMessage());
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        }
    }
    return null;
}

From source file:ke.co.tawi.babblesms.server.persistence.logs.OutgoingGroupLogDAO.java

/**
        /*from   w ww .j av  a  2  s. c  o m*/
 * @see ke.co.tawi.babblesms.server.persistence.logs.BabbleOutgoingGroupLogDAO#get(java.lang.String)
 */
@Override

public OutgoingGrouplog get(String uuid) {
    OutgoingGrouplog log = null;
    try (Connection conn = dbCredentials.getConnection();
            PreparedStatement pstmt = conn
                    .prepareStatement("SELECT * FROM OutgoinggroupLog WHERE Uuid = ?;");) {

        pstmt.setString(1, uuid);

        try (ResultSet rset = pstmt.executeQuery();) {

            if (rset.next()) {
                log = beanProcessor.toBean(rset, OutgoingGrouplog.class);
            }
        }
    } catch (SQLException e) {
        logger.error("SQL Exception when getting outgoingGrouplog with uuid: " + uuid);

        logger.error(ExceptionUtils.getStackTrace(e));
    }

    return log;

}

From source file:ke.co.tawi.babblesms.server.persistence.contacts.ContactGroupDAO.java

/**
 * //from   w w w.j ava2  s .  co  m
 * @see ke.co.tawi.babblesms.server.persistence.contacts.BabbleContactGroupDAO#removeContact(ke.co.tawi.babblesms.server.beans.contact.Contact, ke.co.tawi.babblesms.server.beans.contact.Group)
 * 
 */
@Override
public boolean removeContact(Contact contact, Group group) {
    boolean success = true;

    try (Connection conn = dbCredentials.getConnection();
            PreparedStatement pstmt = conn.prepareStatement(
                    "DELETE FROM ContactGroup WHERE contactuuid = ? " + "AND groupuuid = ?;");) {
        pstmt.setString(1, contact.getUuid());
        pstmt.setString(2, group.getUuid());

        pstmt.executeUpdate();

    } catch (SQLException e) {
        logger.error("SQL Exception when deleting " + contact + " from " + group);
        logger.error(ExceptionUtils.getStackTrace(e));
        success = false;
    }

    return success;
}

From source file:com.linkedin.pinot.controller.api.restlet.resources.PinotSegmentResletResource.java

@Override
@Get/*from  w ww. ja va 2  s  . c  om*/
public Representation get() {
    StringRepresentation presentation = null;
    try {
        final String tableName = (String) getRequest().getAttributes().get("tableName");
        final String segmentName = (String) getRequest().getAttributes().get("segmentName");

        if (segmentName != null) {
            // TODO : {here we need to see if this is a realtime segment name then fetch realtime zk metadata}
            OfflineSegmentZKMetadata offlineSegmentZKMetadata = ZKMetadataProvider.getOfflineSegmentZKMetadata(
                    manager.getPropertyStore(), TableNameBuilder.OFFLINE_TABLE_NAME_BUILDER.forTable(tableName),
                    segmentName);

            String res = new ObjectMapper().writeValueAsString(offlineSegmentZKMetadata.toMap());
            return new StringRepresentation(res);
        }

        final String grouping = getQueryValue("grouping") == null ? "instances" : "arrivalDay";

        if (!grouping.equals("instances")) {
            throw new RuntimeException("currently only instance grouping is supported");
        }

        JSONArray ret = new JSONArray();
        if (manager.hasRealtimeTable(tableName)) {
            String realtimeTableName = TableNameBuilder.REALTIME_TABLE_NAME_BUILDER.forTable(tableName);
            JSONObject realtime = new JSONObject();
            realtime.put("tableType", "realtime");
            realtime.put("segments", new ObjectMapper()
                    .writeValueAsString(manager.getInstanceToSegmentsInATableMap(realtimeTableName)));
            ret.put(realtime);
        }

        if (manager.hasOfflineTable(tableName)) {
            String offlineTableName = TableNameBuilder.OFFLINE_TABLE_NAME_BUILDER.forTable(tableName);
            JSONObject offline = new JSONObject();
            offline.put("tableType", "offline");
            offline.put("segments", new ObjectMapper()
                    .writeValueAsString(manager.getInstanceToSegmentsInATableMap(offlineTableName)));
            ret.put(offline);
        }

        return new StringRepresentation(ret.toString());

    } catch (final Exception e) {
        presentation = new StringRepresentation(e.getMessage() + "\n" + ExceptionUtils.getStackTrace(e));
        LOGGER.error("Caught exception while processing get request", e);
        setStatus(Status.SERVER_ERROR_INTERNAL);
    }
    return presentation;
}

From source file:com.aurel.track.fieldType.bulkSetters.ParentBulkSetter.java

/**
 * Sets the workItemBean's attribute depending on the value and bulkRelation
 * @param workItemBean//from w  ww.  j a  v  a2s.  c om
 * @param fieldID
 * @param parameterCode
 * @param bulkTranformContext
 * @param selectContext
 * @param value   
 * @return ErrorData if an error is found
 */
@Override
public ErrorData setWorkItemAttribute(TWorkItemBean workItemBean, Integer fieldID, Integer parameterCode,
        BulkTranformContext bulkTranformContext, SelectContext selectContext, Object value) {
    Integer parentID = null;
    try {
        parentID = (Integer) value;
    } catch (Exception e) {
        LOGGER.info("Getting the string value for " + value + " failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    switch (getRelation()) {
    case BulkRelations.SET_TO:
        if (parentID != null) {
            if (ItemBL.isAscendant(workItemBean.getObjectID(), parentID)) {
                return new ErrorData("itemov.massOperation.err.parentIsDescendant");
            } else {
                workItemBean.setAttribute(fieldID, parameterCode, parentID);
            }
        }
        break;
    case BulkRelations.SET_NULL:
        workItemBean.setAttribute(fieldID, parameterCode, null);
        break;
    }
    //no error
    return null;
}

From source file:io.bitsquare.seednode.SeedNodeMain.java

@Override
protected void doExecute(OptionSet options) {
    final BitsquareEnvironment environment = new BitsquareEnvironment(options);
    SeedNode.setEnvironment(environment);

    UserThread.execute(() -> seedNode = new SeedNode());

    Thread.UncaughtExceptionHandler handler = (thread, throwable) -> {
        if (throwable.getCause() != null && throwable.getCause().getCause() != null
                && throwable.getCause().getCause() instanceof BlockStoreException) {
            log.error(throwable.getMessage());
        } else {//ww  w .jav a  2 s  .c  o m
            log.error("Uncaught Exception from thread " + Thread.currentThread().getName());
            log.error("throwableMessage= " + throwable.getMessage());
            log.error("throwableClass= " + throwable.getClass());
            log.error("Stack trace:\n" + ExceptionUtils.getStackTrace(throwable));
            throwable.printStackTrace();
            log.error("We shut down the app because an unhandled error occurred");
            // We don't use the restart as in case of OutOfMemory errors the restart might fail as well
            // The run loop will restart the node anyway...
            System.exit(EXIT_FAILURE);
        }
    };
    Thread.setDefaultUncaughtExceptionHandler(handler);
    Thread.currentThread().setUncaughtExceptionHandler(handler);

    String maxMemoryOption = environment.getProperty(AppOptionKeys.MAX_MEMORY);
    if (maxMemoryOption != null && !maxMemoryOption.isEmpty()) {
        try {
            maxMemory = Integer.parseInt(maxMemoryOption);
        } catch (Throwable t) {
            log.error(t.getMessage());
        }
    }

    UserThread.runPeriodically(() -> {
        Profiler.printSystemLoad(log);
        long usedMemoryInMB = Profiler.getUsedMemoryInMB();
        if (!stopped) {
            if (usedMemoryInMB > (maxMemory - 100)) {
                log.warn(
                        "\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
                                + "We are over our memory warn limit and call the GC. usedMemoryInMB: {}"
                                + "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n",
                        usedMemoryInMB);
                System.gc();
                usedMemoryInMB = Profiler.getUsedMemoryInMB();
                Profiler.printSystemLoad(log);
            }

            final long finalUsedMemoryInMB = usedMemoryInMB;
            UserThread.runAfter(() -> {
                if (finalUsedMemoryInMB > maxMemory)
                    restart(environment);
            }, 1);
        }
    }, CHECK_MEMORY_PERIOD_SEC);

    while (true) {
        try {
            Thread.sleep(Long.MAX_VALUE);
        } catch (InterruptedException ignore) {
        }
    }
}

From source file:ke.co.tawi.babblesms.server.persistence.utils.CountUtils.java

/**
 * Gets the count of all incoming USSD sessions belonging to this account
 * holder as specified by the email and based on the network that they came
 * from./* ww w .  j  a v a 2 s. com*/
 * <p>
 * If the account has more than one USSD short code, then the count is the
 * total sum of sessions for each short code that belongs to it.
 * <br>
 * <b>Note:</b> This method assumes that a particular short code can only be
 * held by one account holder.
 *
 * @param accountuuid
 * @param network
 * @return  an integer
 */
public int getIncomingCount(String accountuuid, Network network) {
    int count = 0;

    try (Connection conn = dbCredentials.getConnection();
            PreparedStatement pstmt = conn.prepareStatement(
                    "SELECT COUNT(*) FROM incomingLog WHERE " + "networkuuid=? AND recipientuuid=?; ");) {

        pstmt.setString(1, network.getUuid());
        pstmt.setString(2, accountuuid);

        try (ResultSet rset = pstmt.executeQuery();) {

            if (rset.next()) {
                count = rset.getInt(1);
            }
        }

    } catch (SQLException e) {
        logger.error("SQLException while getting all incoming SMS count of account with uuid '" + accountuuid
                + "' and of '" + network + "'.");
        logger.error(ExceptionUtils.getStackTrace(e));

    }

    return count;
}

From source file:com.aurel.track.fieldType.runtime.matchers.run.IntegerMatcherRT.java

/**
 * Add a match expression to the criteria
 *//*ww w.  ja v a2  s  . com*/
@Override
public void addCriteria(Criteria crit) {
    String columnName = null;
    switch (fieldID.intValue()) {
    case SystemFields.SUPERIORWORKITEM:
        columnName = TWorkItemPeer.SUPERIORWORKITEM;
        break;
    case SystemFields.PROJECT_SPECIFIC_ISSUENO:
    case SystemFields.ISSUENO:
        columnName = TWorkItemPeer.WORKITEMKEY;
        break;
    default:
        String alias = addAliasAndJoin(crit);
        columnName = alias + "." + "INTEGERVALUE";
        break;
    }
    if (addNullExpressionToCriteria(crit, columnName)) {
        return;
    }
    Integer matcherValueInteger = null;
    try {
        matcherValueInteger = (Integer) matchValue;
    } catch (Exception e) {
        LOGGER.warn("Converting the matcher value " + matchValue + " of type " + matchValue.getClass().getName()
                + " to Integer failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    switch (relation) {
    case MatchRelations.EQUAL:
        crit.add(columnName, matcherValueInteger);
        break;
    case MatchRelations.NOT_EQUAL:
        crit.add(columnName, matcherValueInteger, Criteria.NOT_EQUAL);
        break;
    case MatchRelations.GREATHER_THAN:
        crit.add(columnName, matcherValueInteger, Criteria.GREATER_THAN);
        break;
    case MatchRelations.GREATHER_THAN_EQUAL:
        crit.add(columnName, matcherValueInteger, Criteria.GREATER_EQUAL);
        break;
    case MatchRelations.LESS_THAN:
        crit.add(columnName, matcherValueInteger, Criteria.LESS_THAN);
        break;
    case MatchRelations.LESS_THAN_EQUAL:
        crit.add(columnName, matcherValueInteger, Criteria.LESS_EQUAL);
        break;
    }
}

From source file:com.aurel.track.screen.action.AbstractPanelAction.java

/**
 * Update a panel property//from   w ww  .  j ava 2 s . co  m
 * @return
 */
public String updateProperty() {
    try {
        clearCache();
        IPanel panelDb = getAbstractPanelDesignBL().loadPanelWrapped(componentID);
        getAbstractPanelDesignBL().setPanelProperty(panelDb, panel);
        getAbstractPanelDesignBL().saveScreenPanel(panelDb);
        return properties();
    } catch (Exception ex) {
        LOGGER.error(ExceptionUtils.getStackTrace(ex));
    }
    return null;
}

From source file:com.aurel.track.persist.TLastExecutedQueryPeer.java

/**
 * Deletes the TQueryRepositoryBean satisfying a certain criteria 
 * together with the dependent database entries 
 * @param crit/*from ww w.j a  v  a  2  s  . c  om*/
 */
public static void doDelete(Criteria crit, Connection con) {
    List<TLastExecutedQuery> list = null;
    try {
        list = doSelect(crit, con);
    } catch (TorqueException e) {
        LOGGER.error("Getting the list of TNotifyTriggers to be deleted failed with " + e.getMessage());
    }
    if (list == null || list.isEmpty()) {
        return;
    }
    try {
        BaseTLastExecutedQueryPeer.doDelete(crit, con);
    } catch (TorqueException e) {
        LOGGER.warn("Deleting the last executed query failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    for (TLastExecutedQuery lastExecutedQuery : list) {
        Integer queryClobID = lastExecutedQuery.getQueryClob();
        if (queryClobID != null) {
            try {
                BaseTCLOBPeer.doDelete(SimpleKey.keyFor(queryClobID), con);
            } catch (TorqueException e) {
                LOGGER.warn("Deleting the last executed query failed with " + e.getMessage());
                LOGGER.debug(ExceptionUtils.getStackTrace(e));
            }
        }
    }
}