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.persist.TWorkflowTransitionPeer.java

/**
 * Loads the station by primary key//from www . ja  va 2  s  .  co m
 * @param objectID
 * @return
 */
@Override
public TWorkflowTransitionBean loadByPrimaryKey(Integer objectID) {
    TWorkflowTransition tobject = null;
    try {
        tobject = retrieveByPK(objectID);
    } catch (Exception e) {
        LOGGER.warn("Loading of a workflow transition 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.hortonworks.streamline.streams.security.impl.DefaultStreamlineAuthorizer.java

private void mayBeAddAdminUsers() {
    LOG.info("Checking user entries for admin users");
    adminUsers.stream().filter(name -> {
        User user = catalogService.getUser(name);
        if (user != null) {
            LOG.info("Entry for user '{}' already exists", name);
            return false;
        } else {/*from  www .  j a  v  a  2s . c  om*/
            return true;
        }
    }).forEach(name -> {
        User user = new User();
        user.setName(name);
        user.setEmail(name + "@auto-generated.com");
        user.setMetadata("{\"colorCode\":\"#8261be\",\"colorLabel\":\"purple\",\"icon\":\"gears\"}");
        try {
            User addedUser = catalogService.addUser(user);
            LOG.info("Added admin user entry: {}", addedUser);
        } catch (DuplicateEntityException exception) {
            // In HA setup the other server may have already added the user.
            LOG.info("Caught exception: " + ExceptionUtils.getStackTrace(exception));
            LOG.info("Admin user entry: {} already exists.", user);
        }
    });
}

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

/**
 * This is used to export the results of an SQL query into a CSV text file.
 *
 * @param sqlQuery//from   w ww  .j a va  2  s.c  om
 * @param fileName this should include the full path of the file e.g.
 * /tmp/myFile.csv
 * @param delimiter
 *
 * @return whether the action was successful or not
 */
public boolean sqlResultToCSV(String sqlQuery, String fileName, char delimiter) {
    boolean success = true;

    String sanitizedQuery = StringUtils.remove(sqlQuery, ';');

    BufferedWriter writer;

    try (
            // Return a database connection that is not pooled
            // to enable the connection to be cast to BaseConnection
            Connection conn = dbCredentials.getJdbcConnection();) {

        FileUtils.deleteQuietly(new File(fileName));
        FileUtils.touch(new File(fileName));
        writer = new BufferedWriter(new FileWriter(fileName));

        CopyManager copyManager = new CopyManager((BaseConnection) conn);

        StringBuffer query = new StringBuffer("COPY (").append(sanitizedQuery)
                .append(") to STDOUT WITH DELIMITER '").append(delimiter).append("'");

        copyManager.copyOut(query.toString(), writer);
        writer.close();

    } catch (SQLException e) {
        logger.error(
                "SQLException while exporting results of query '" + sqlQuery + "' to file '" + fileName + "'.");
        logger.error(ExceptionUtils.getStackTrace(e));
        success = false;

    } catch (IOException e) {
        logger.error(
                "IOException while exporting results of query '" + sqlQuery + "' to file '" + fileName + "'.");
        logger.error(ExceptionUtils.getStackTrace(e));
        success = false;
    }

    return success;
}

From source file:jp.mathes.databaseWiki.web.DbwConfiguration.java

public void davLog(String message, Throwable e) {
    if (this.davLogFile != null) {
        try {/*from  w  w  w .  j a va 2  s  . c  om*/
            FileUtils.write(this.davLogFile, message, true);
            FileUtils.write(this.davLogFile, "\n", true);
            if (e != null) {
                FileUtils.write(this.davLogFile, ExceptionUtils.getStackTrace(e), true);
                FileUtils.write(this.davLogFile, "\n", true);
            }
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}

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

/**
*
* @param description/*from w  ww .j  a v  a  2 s.c o m*/
* @return network
*
*/
@Override
public Status getStatusByName(String description) {
    Status status = null;

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

        pstmt.setString(1, description);
        ResultSet rset = pstmt.executeQuery();

        if (rset.next()) {
            status = beanProcessor.toBean(rset, Status.class);
        }

        rset.close();

    } catch (SQLException e) {
        logger.error("SQLException when getting Status with description: " + description);
        logger.error(ExceptionUtils.getStackTrace(e));
    }

    return status;
}

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

/**
 * Loads the saved custom attribute value from the database 
 * to the workItem customAttributeValues Map
 * The comments are stored in a dumped string to be used in matchers
 * For showing the comments they should be stored separately 
 * @param fieldID /* ww w . j  ava2s. c  o  m*/
 * @param parameterCode neglected for single custom fields
 * @param workItemBean
 * @param attributeValueMap: 
 *    -   key: fieldID_parameterCode
 *    -   value: TAttributeValueBean or list of TAttributeValueBeans
 */
@Override
public void loadAttribute(Integer fieldID, Integer parameterCode, TWorkItemBean workItemBean,
        Map<String, Object> attributeValueMap) {
    List<TAttributeValueBean> attributeValueList = null;
    //get the attributes list from the custom attributes map
    try {
        attributeValueList = (List<TAttributeValueBean>) attributeValueMap
                .get(MergeUtil.mergeKey(fieldID, parameterCode));
    } catch (Exception e) {
        LOGGER.error("Converting the attribute value for field " + fieldID + " and parameterCode "
                + parameterCode + " for workItem " + workItemBean.getObjectID() + " to List failed with "
                + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    //dump all comments into a single string to be used in the matcher
    StringBuilder stringBuilder = new StringBuilder();
    if (attributeValueList != null) {
        for (int i = 0; i < attributeValueList.size(); i++) {
            TAttributeValueBean attributeValueBean = attributeValueList.get(i);
            stringBuilder.append(AttributeValueBL.getSpecificAttribute(attributeValueBean, getValueType()));
        }
    }
    //set the attribute on workItem
    if (stringBuilder.length() > 0) {
        //leave null if no comment was added for matching also the the NULL/NOT NULL matcher
        workItemBean.setAttribute(fieldID, parameterCode, stringBuilder.toString());
    }
}

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

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

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

/**
 * @see ke.co.tawi.babblesms.server.persistence.logs.BabbleOutgoingLogDAO#put(ke.co.tawi.babblesms.server.beans.log.OutgoingLog)
 *//*from  w ww.  j ava2 s. co  m*/
@Override
public boolean put(OutgoingLog outgoingLog) {
    boolean success = true;

    try (Connection conn = dbCredentials.getConnection();
            PreparedStatement pstmt = conn.prepareStatement("INSERT INTO OutgoingLog "
                    + "(Uuid, origin, destination, message, logtime, networkuuid, sender, messagestatusuuid, phoneuuid) "
                    + "VALUES (?,?,?,?,?,?,?,?,?);");) {

        pstmt.setString(1, outgoingLog.getUuid());
        pstmt.setString(2, outgoingLog.getOrigin());
        pstmt.setString(3, outgoingLog.getDestination());
        pstmt.setString(4, outgoingLog.getMessage());
        pstmt.setTimestamp(5, new Timestamp(outgoingLog.getLogTime().getTime()));
        pstmt.setString(6, outgoingLog.getNetworkUuid());
        pstmt.setString(7, outgoingLog.getSender());
        pstmt.setString(8, outgoingLog.getMessagestatusuuid());
        pstmt.setString(9, outgoingLog.getPhoneUuid());

        pstmt.execute();

    } catch (SQLException e) {
        logger.error("SQL Exception when trying to put " + outgoingLog);
        logger.error(ExceptionUtils.getStackTrace(e));
        success = false;
    }

    return success;
}

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

/**
 * Loads an issueType by primary key/* w  ww  .j  a v a  2 s.  c om*/
 * @param objectID
 * @return
 */
@Override
public TListTypeBean loadByPrimaryKey(Integer objectID) {
    TListType tListType = null;
    try {
        tListType = retrieveByPK(objectID);
    } catch (Exception e) {
        LOGGER.info("Loading of an issueType by primary key " + objectID + " failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    if (tListType != null) {
        return tListType.getBean();
    }
    return null;
}

From source file:com.aurel.track.lucene.util.openOffice.OOIndexer.java

/**
 * Get the string content of an xml file
 *///from  www.  j  a va 2  s. c o  m
public String parseXML(File file) {
    Document document = null;
    DocumentBuilderFactory documentBuilderfactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = null;
    try {
        builder = documentBuilderfactory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        LOGGER.info("Building the document builder from factory failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
        return null;
    }
    try {
        document = builder.parse(file);
    } catch (SAXException e) {
        LOGGER.info("Parsing the XML document " + file.getPath() + " failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    } catch (IOException e) {
        LOGGER.info("Reading the XML document " + file.getPath() + " failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    if (document == null) {
        return null;
    }
    StringWriter result = new StringWriter();
    Transformer transformer = null;
    try {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
    } catch (TransformerConfigurationException e) {
        LOGGER.warn(
                "Creating the transformer failed with TransformerConfigurationException: " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
        return null;
    }
    try {
        transformer.transform(new DOMSource(document), new StreamResult(result));
    } catch (TransformerException e) {
        LOGGER.warn("Transform failed with TransformerException: " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    return result.getBuffer().toString();
}