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.adeptj.modules.jaxrs.resteasy.ApplicationExceptionMapper.java

@Override
public Response toResponse(ApplicationException exception) {
    LOGGER.error(exception.getMessage(), exception);
    return Response.serverError().type(TEXT_PLAIN)
            .entity(this.sendExceptionTrace ? ExceptionUtils.getStackTrace(exception) : DEFAULT_ERROR_MSG)
            .build();/*from   ww w  .  j a  v  a 2  s  . com*/
}

From source file:com.aurel.track.fieldType.fieldChange.converter.CompositeSelectSetterConverter.java

/**
 * Convert the string to object value after load
 * @param value//from   w  w w  .  j  ava2s. c o  m
 * @param setter
 * @return
 */
@Override
public Object getActualValueFromStoredString(String value, Integer setter) {
    if (value == null || setter == null) {
        return null;
    }
    switch (setter.intValue()) {
    case FieldChangeSetters.SET_TO:
        SortedMap<Integer, Integer[]> actualValuesMap = new TreeMap<Integer, Integer[]>();
        String[] partStringArr = value.split(PART_SPLITTER_STRING);
        if (partStringArr != null && partStringArr.length > 0) {
            for (int i = 0; i < partStringArr.length; i++) {
                String partString = partStringArr[i];
                if (partString != null && !"".equals(partString)) {
                    try {
                        Integer partValue = Integer.valueOf(partString);
                        actualValuesMap.put(Integer.valueOf(i + 1), new Integer[] { partValue });
                    } catch (Exception e) {
                        LOGGER.warn("Converting the " + i + 1 + "th part " + partString
                                + " to Integer failed with " + e.getMessage());
                        LOGGER.debug(ExceptionUtils.getStackTrace(e));
                    }
                }
            }
        }
        return actualValuesMap;
    }
    return null;
}

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

/**
 * Loads the screenConfig by primary key
 * @param objectID//  ww  w  .j ava2 s.  co m
 * @return
 */
@Override
public TScreenConfigBean loadByPrimaryKey(Integer objectID) {
    TScreenConfig tobject = null;
    try {
        tobject = retrieveByPK(objectID);
    } catch (Exception e) {
        LOGGER.warn("Loading of a screenConfig by primary key " + objectID + " failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    if (tobject != null) {
        return tobject.getBean();
    }
    return null;
}

From source file:com.qwazr.server.ServerException.java

public WebApplicationException getTextException(boolean withStackTrace) {
    final String message = getMessage();
    final StringBuilder sb = new StringBuilder(message);
    if (withStackTrace) {
        sb.append("\n");
        sb.append(ExceptionUtils.getStackTrace(this));
    }/*from   w w  w.j a v  a 2 s. c o m*/
    final Response response = Response.status(statusCode).type(MediaType.TEXT_PLAIN).entity(sb.toString())
            .build();
    return new WebApplicationException(message, this, response);
}

From source file:com.aurel.track.fieldType.fieldChange.apply.DateFieldChangeApply.java

/**
 * Sets the workItemBean's attribute/*from w  w  w .ja  v a  2 s .c o  m*/
 * @param workItemContext
 * @param workItemBean
 * @param fieldID
 * @param parameterCode
 * @param value   
 * @return ErrorData if an error is found
 */
@Override
public List<ErrorData> setWorkItemAttribute(WorkItemContext workItemContext, TWorkItemBean workItemBean,
        Integer parameterCode, Object value) {
    if (getSetter() == FieldChangeSetters.SET_NULL || getSetter() == FieldChangeSetters.SET_REQUIRED) {
        return super.setWorkItemAttribute(workItemContext, workItemBean, parameterCode, value);
    }
    if (getSetter() == FieldChangeSetters.SET_TO) {
        Date dateValue = null;
        try {
            dateValue = (Date) value;
        } catch (Exception e) {
            LOGGER.warn("Getting the date value for " + value + " failed with " + e.getMessage());
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        }
        workItemBean.setAttribute(activityType, parameterCode, dateValue);
        return null;
    }
    if (getSetter() == FieldChangeSetters.SET_TO_DATE_FIELD_VALUE) {
        Integer dateFieldID = null;
        try {
            dateFieldID = (Integer) value;
        } catch (Exception e) {
            LOGGER.warn("Getting the integer value for " + value + " failed with " + e.getMessage());
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        }
        if (dateFieldID != null) {
            Object otherDateValue = null;
            if (dateFieldID.intValue() == SystemFields.CREATEDATE && workItemBean.getObjectID() == null) {
                //new item, create date not yet set
                otherDateValue = new Date();
            } else {
                otherDateValue = workItemBean.getAttribute(dateFieldID, parameterCode);
            }
            if (otherDateValue != null) {
                workItemBean.setAttribute(activityType, parameterCode, otherDateValue);
            }
        }
        return null;
    }
    //the other relations depend on original date
    Object originalValue = workItemBean.getAttribute(activityType, parameterCode);
    if (originalValue == null) {
        return null;
    }
    Date originalDate = null;
    try {
        originalDate = (Date) originalValue;
    } catch (Exception e) {
        LOGGER.warn(
                "Converting the original value " + originalValue + " to Date failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    if (originalDate == null) {
        return null;
    }

    switch (getSetter()) {
    case FieldChangeSetters.MOVE_BY_DAYS:
        Integer intValue = null;
        try {
            intValue = (Integer) value;
        } catch (Exception e) {
            LOGGER.warn("Getting the integer value for " + value + " failed with " + e.getMessage());
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        }
        workItemBean.setAttribute(activityType, parameterCode, shiftByDays(originalDate, intValue));
        break;
    }
    return null;
}

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

/**
 * Loads the screenConfig by primary key
 * @param objectID/*from   w w  w .  j av a 2  s.  c  o m*/
 * @return
 */
@Override
public TMailTemplateConfigBean loadByPrimaryKey(Integer objectID) {
    TMailTemplateConfig tobject = null;
    try {
        tobject = retrieveByPK(objectID);
    } catch (Exception e) {
        LOGGER.warn("Loading of a mailConfig by primary key " + objectID + " failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    if (tobject != null) {
        return tobject.getBean();
    }
    return null;
}

From source file:com.aurel.track.admin.server.dbbackup.DatabaseBackupBL.java

public static void checkBackupNumber(int backupNumber) throws DatabaseBackupBLException {
    //Obtain the backup list file name sorted by lastModified.
    //The first element is the most recent 
    List<File> backups = getBackupFiles();
    if (backups.size() > backupNumber) {
        LOGGER.debug("Must Remove " + (backups.size() - backupNumber) + " backup files!");
        while (backups.size() > backupNumber) {
            File backupFile = backups.get(backups.size() - 1);
            try {
                backupFile.delete();//from  w w w  . j av  a2s.  c  om
            } catch (Exception ex) {
                LOGGER.error("Can't delete backup file:" + backupFile.getAbsolutePath());
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.error(ExceptionUtils.getStackTrace(ex));
                }
            }
            backups.remove(backups.size() - 1);
        }
    }
}

From source file:info.magnolia.ui.framework.app.stub.ExceptionMessage.java

private String prepareMessage() {
    final StringBuilder sb = new StringBuilder();
    if (relatedException.getLocalizedMessage() != null) {
        sb.append(i18n.translate(EXCEPTION_MSG_KEY)).append(" ")
                .append(EscapeUtil.escapeXss(relatedException.getLocalizedMessage()));
        sb.append(". ");
    }/*w  w  w.  j  a v  a  2 s. c  o m*/
    sb.append(i18n.translate(STACK_TRACE_KEY)).append(" ")
            .append(ExceptionUtils.getStackTrace(relatedException));
    return sb.toString();
}

From source file:com.aurel.track.report.query.ReportQueryBL.java

private static String encrypt(String clearText, char[] password) {
    // Create PBE parameter set
    PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, count);
    byte[] ciphertext = { 0 };

    PBEKeySpec pbeKeySpec = new PBEKeySpec(password);
    try {//from   w w w. j ava 2 s.  c o m
        SecretKeyFactory keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
        SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);

        // Create PBE Cipher
        Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");

        // Initialize PBE Cipher with key and parameters
        pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);

        // Encrypt the cleartext
        ciphertext = pbeCipher.doFinal(clearText.getBytes());
    } catch (Exception e) {
        LOGGER.error(ExceptionUtils.getStackTrace(e));
    }
    return new String(Base64.encodeBase64(ciphertext));
}

From source file:net.mindengine.blogix.web.BlogixServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res) {
    String uri = req.getRequestURI();
    try {//from   w w w  . j  a v  a  2 s .  c  om
        res.setStatus(200);
        String contentType = findContentTypeFor(uri);
        if (contentType != null) {
            res.setContentType(contentType);
        }
        blogix.processUri(uri, res.getOutputStream());
    } catch (Throwable e) {
        res.setStatus(400);
        printResponseText(res, ExceptionUtils.getMessage(e) + "\n" + ExceptionUtils.getStackTrace(e));
    }
}