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.braffdev.server.core.io.logger.Logger.java

/**
 * Logs the given message with the <code>ERROR</code> tag and appends the given Throwable as "cause" section.
 *
 * @param msg/*from w ww . ja  v  a2s.  c o  m*/
 * @param t
 */
public void error(String msg, Throwable t) {
    this.error(msg, ExceptionUtils.getStackTrace(t));
}

From source file:com.aurel.track.util.StringArrayParameterUtils.java

public static Integer parseIntegerValue(Map/*<String, String[]>*/ configParameters, String fieldName) {
    Integer result = null;/*from  ww w. j a  v  a 2s .co  m*/
    String[] strArr = null;
    if (configParameters != null) {
        try {
            strArr = (String[]) configParameters.get(fieldName);
        } catch (Exception e) {
            LOGGER.info("parseIntegerValue: converting the " + fieldName + " parameter to String[] failed with "
                    + e.getMessage());
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        }
    }
    if (strArr != null && strArr.length > 0) {
        String str = strArr[0];
        if (str != null && !"".equals(str)) {
            try {
                result = new Integer(str);
            } catch (Exception e) {
                LOGGER.info("Converting the value " + str + " for field " + fieldName
                        + " to Integer failed with " + e.getMessage());
                LOGGER.debug(ExceptionUtils.getStackTrace(e));
            }
        }
    }
    return result;
}

From source file:com.aurel.track.fieldType.runtime.custom.picker.CustomPickerRT.java

/**
 * Get the value to be shown for a matcher
 * Typically same as for the getShowValue(), except the selects
 * (the value object's type differs for matchers compared to issue field values in getShowValue)  
 * @param fieldID//w  ww. j a v a  2 s.c om
 * @param value
 * @param locale
 * @return
 */
@Override
public String getMatcherShowValue(Integer fieldID, Object value, Locale locale) {
    Integer[] optionIDs = null;
    if (value != null) {
        try {
            optionIDs = (Integer[]) value;
        } catch (Exception e) {
            LOGGER.warn("Casting the value type " + value.getClass().getName() + " to Integer[] failed with "
                    + e.getMessage());
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
            return "";
        }
        return LookupContainer.getNotLocalizedLookupCommaSepatatedString(getSystemOptionType(), optionIDs,
                locale);
    }
    return "";
}

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

/**
 * @see ke.co.tawi.babblesms.server.persistence.logs.BabbleOutgoingLogDAO#get(java.lang.String)
 *//* w w  w  .j a v a  2  s  .c  om*/
@Override
public OutgoingLog get(String uuid) {
    OutgoingLog outgoingLog = null;

    try (Connection conn = dbCredentials.getConnection();
            PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM OutgoingLog WHERE Uuid = ?;");) {

        pstmt.setString(1, uuid);

        try (ResultSet rset = pstmt.executeQuery();) {
            if (rset.next()) {
                outgoingLog = beanProcessor.toBean(rset, OutgoingLog.class);
            }
        }

    } catch (SQLException e) {
        logger.error("SQL Exception when getting outgoingLog with uuid: " + uuid);
        logger.error(ExceptionUtils.getStackTrace(e));
    }

    return outgoingLog;
}

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

/**
 * Sets the workItemBean's attribute depending on the value and bulkRelation
 * @param workItemBean/*  ww w .  j a v a  2s .c  o  m*/
 * @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) {
    if (LOGGER.isDebugEnabled()) {
        try {
            String strValue = (String) value;
        } catch (Exception e) {
            LOGGER.info("Getting the string value for " + value + " failed with " + e.getMessage());
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        }
    }
    return super.setWorkItemAttribute(workItemBean, fieldID, parameterCode, bulkTranformContext, selectContext,
            value);
}

From source file:ke.co.tawi.babblesms.server.persistence.accounts.AccountDAO.java

/**
 * @see ke.co.tawi.babblesms.server.persistence.accounts.BabbleAccountDAO#getAllAccounts()
 *//*from   w  w  w  .  j av  a2s .  c o m*/

@Override
public List<Account> getAllAccounts() {
    List<Account> list = null;

    try (Connection conn = dbCredentials.getConnection();
            PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM Account;");
            ResultSet rset = pstmt.executeQuery();) {

        list = beanProcessor.toBeanList(rset, Account.class);

    } catch (SQLException e) {
        logger.error("SQL Exception when getting all accounts");
        logger.error(ExceptionUtils.getStackTrace(e));
    }

    return list;
}

From source file:com.aurel.track.fieldType.runtime.system.text.SystemIssueNoRT.java

/**
 * Get the value to be shown/*w  w w .  ja  va  2s  .  co m*/
 * For text fields typically the field value itself
 * For selects the (eventually localized) label corresponding to the value    
 * @param value
 * @param locale
 * @return
 */
@Override
public String getShowValue(Object value, Locale locale) {
    Integer optionID = null;
    try {
        optionID = (Integer) value;
    } catch (Exception e) {
        LOGGER.error("Converting the value to integer failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    if (optionID != null) {
        if (ApplicationBean.getInstance().getSiteBean().getProjectSpecificIDsOn()) {
            TWorkItemBean parentWorkItemBean = null;
            try {
                parentWorkItemBean = ItemBL.loadWorkItem(optionID);
                if (parentWorkItemBean != null) {
                    return SystemProjectSpecificIssueNoRT.getShowValue(parentWorkItemBean.getIDNumber(),
                            parentWorkItemBean);
                }
            } catch (ItemLoaderException e) {
            }
        } else {
            return optionID.toString();
        }
    } else {
        LOGGER.debug("The parentID " + optionID + " was not found");
    }
    return "";
}

From source file:ke.co.tawi.babblesms.server.persistence.items.messageTemplate.MessageTemplateDAO.java

/**
 *
 *///from   w ww .j  a  v a  2 s. c  o m
@Override
public MessageTemplate getMessageTemplate(String uuid) {
    MessageTemplate messageTemplate = null;

    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rset = null;
    BeanProcessor b = new BeanProcessor();

    try {
        conn = dbCredentials.getConnection();
        pstmt = conn.prepareStatement("SELECT * FROM MessageTemplate WHERE Uuid = ?;");
        pstmt.setString(1, uuid);
        rset = pstmt.executeQuery();

        if (rset.next()) {
            messageTemplate = b.toBean(rset, MessageTemplate.class);
        }

    } catch (SQLException e) {
        logger.error("SQL Exception when getting messageTemplate with uuid: " + uuid);
        logger.error(ExceptionUtils.getStackTrace(e));
    } finally {
        if (rset != null) {
            try {
                rset.close();
            } catch (SQLException e) {
            }
        }
        if (pstmt != null) {
            try {
                pstmt.close();
            } catch (SQLException e) {
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
            }
        }
    }
    return messageTemplate;
}

From source file:ke.co.tawi.babblesms.server.persistence.notification.NotificationDAO.java

/**
 * /*from   w w w .j ava2  s .c  om*/
 * @param origin
 * @return 
 */
@Override
public List<Notification> getNotificationbyOrigin(String origin) {
    List<Notification> notification = null;

    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rset = null;

    BeanProcessor b = new BeanProcessor();

    try {
        conn = dbCredentials.getConnection();
        pstmt = conn.prepareStatement("SELECT * FROM Notification WHERE origin = ?;");
        pstmt.setString(1, origin);

        rset = pstmt.executeQuery();

        if (rset.next()) {
            notification = b.toBeanList(rset, Notification.class);
        }

    } catch (SQLException e) {
        logger.error("SQL Exception when trying to get Notification with Uuid: " + origin);
        logger.error(ExceptionUtils.getStackTrace(e));
    } finally {
        if (rset != null) {
            try {
                rset.close();
            } catch (SQLException e) {
            }
        }
        if (pstmt != null) {
            try {
                pstmt.close();
            } catch (SQLException e) {
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
            }
        }
    }
    return notification;
}

From source file:io.galeb.router.handlers.completionListeners.AccessLogCompletionListener.java

@Override
public void exchangeEvent(HttpServerExchange exchange, NextListener nextListener) {
    try {//from   w ww.  ja v  a  2s .  c  om
        final String remoteAddr = remoteIp().readAttribute(exchange); // %a
        final String host = localServerName().readAttribute(exchange); // %v
        final String requestElements[] = requestList().readAttribute(exchange).split(" "); // %r
        final String method = exchange.getRequestMethod().toString();
        final String requestUri = exchange.getRequestURI();
        final String proto = exchange.getProtocol().toString();
        final String refer = requestElements.length > 3 ? requestElements[3] : null;
        final String xMobileGroup = requestElements.length > 4 ? requestElements[4] : null;
        final int originalStatusCode = Integer.parseInt(responseCode().readAttribute(exchange)); // %s
        final long responseBytesSent = exchange.getResponseBytesSent();
        final String bytesSent = Long.toString(responseBytesSent); // %B
        final String bytesSentOrDash = responseBytesSent == 0L ? "-" : bytesSent; // %b
        final Integer responseTime = Math
                .round(Float.parseFloat(responseTimeAttribute.readAttribute(exchange))); // %D
        final String realDestAttached = exchange.getAttachment(HostSelector.REAL_DEST);
        final String realDest = extractUpstreamField(exchange.getResponseHeaders(), realDestAttached);
        final String userAgent = requestHeader(Headers.USER_AGENT).readAttribute(exchange); // %{i,User-Agent}
        final String requestId = !"".equals(REQUESTID_HEADER)
                ? requestHeader(RequestIDHandler.requestIdHeader()).readAttribute(exchange)
                : null; // %{i,?REQUEST_ID?}
        final String xForwardedFor = requestHeader(Headers.X_FORWARDED_FOR).readAttribute(exchange); // %{i,X-Forwarded-For}

        final int fakeStatusCode = getFakeStatusCode(realDestAttached, originalStatusCode, responseBytesSent,
                responseTime, MAX_REQUEST_TIME);
        final int statusCode = fakeStatusCode != ProcessorLocalStatusCode.NOT_MODIFIED ? fakeStatusCode
                : originalStatusCode;

        final String message = remoteAddr + TAB + host + TAB + method + TAB + requestUri + TAB + proto + TAB
                + (refer != null ? refer : "-") + TAB + (xMobileGroup != null ? xMobileGroup : "-") + TAB
                + "Local:" + TAB + statusCode + TAB + "*-" + TAB + bytesSent + TAB + responseTime + TAB
                + "Proxy:" + TAB + realDest + TAB + statusCode + TAB + "-" + TAB + bytesSentOrDash + TAB + "-"
                + TAB + "-" + TAB + "Agent:" + TAB + (userAgent != null ? userAgent : "-")
                + (requestId != null ? TAB + requestId : "") + TAB + "Fwd:" + TAB
                + (xForwardedFor != null ? xForwardedFor : "-") + TAB + "tags: " + TAGS;

        logger.info(message);

    } catch (Exception e) {
        logger.error(ExceptionUtils.getStackTrace(e));
    } finally {
        nextListener.proceed();
    }
}