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:ke.co.tawi.babblesms.server.persistence.contacts.ContactDAO.java

/**
* @see ke.co.tawi.babblesms.server.persistence.contacts.BabbleContactDAO#getContactByUuid(java.lang.String)
*//*w w  w  .j a v a 2s .  c o  m*/
@Override
public Contact getContact(String uuid) {
    Contact contact = null;

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

        if (rset.next()) {
            contact = beanProcessor.toBean(rset, Contact.class);
        }

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

    return contact;
}

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

@Override
public TExportTemplateBean loadByPrimaryKey(Integer objectID) {
    TExportTemplateBean templateBean = null;
    TExportTemplate tobject = null;/* w  w w  .  ja va  2  s  .  c  o m*/
    try {
        tobject = retrieveByPK(objectID);
    } catch (TorqueException e) {
        LOGGER.warn(
                "Loading of a ExportTemplate by primary key " + objectID + " failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    if (tobject != null) {
        templateBean = tobject.getBean();
    }
    return templateBean;

}

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

/**
 * Loads the attribute value by primary key
 * @param objectID//from w w  w .j ava  2  s  . c  o m
 * @return
 */
@Override
public TAttributeValueBean loadByPrimaryKey(Integer objectID) {
    TAttributeValue tAttributeValue = null;
    try {
        tAttributeValue = retrieveByPK(objectID);
    } catch (Exception e) {
        LOGGER.info(
                "Loading of an attribute value by primary key " + objectID + " failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    if (tAttributeValue != null) {
        return tAttributeValue.getBean();
    }
    return null;
}

From source file:com.aurel.track.lucene.util.FileUtil.java

/**
 * Copies a source file to a destination file
 * @param source//  w w w .j a  v a  2  s.  co  m
 * @param destination
 */
public static void copyFile(File source, File destination) {
    if (!source.exists()) {
        return;
    }

    if ((destination.getParentFile() != null) && (!destination.getParentFile().exists())) {

        destination.getParentFile().mkdirs();
    }

    FileChannel srcChannel = null;
    FileChannel dstChannel = null;

    try {
        srcChannel = new FileInputStream(source).getChannel();
        dstChannel = new FileOutputStream(destination).getChannel();

        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());

        srcChannel.close();
        dstChannel.close();
    } catch (IOException ioe) {
        LOGGER.error(ExceptionUtils.getStackTrace(ioe));
    } finally {
        if (srcChannel != null)
            try {
                srcChannel.close();
            } catch (IOException ioe) {
            }
        ;
        if (dstChannel != null)
            try {
                dstChannel.close();
            } catch (IOException ioe) {
            }
        ;
    }
}

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

/**
 * @see ke.co.tawi.babblesms.server.persistence.logs.BabbleIncomingLogDAO#getIncomingLog(java.lang.String)
 *///from   ww w  .java2s.c  om
@Override
public IncomingLog getIncomingLog(String uuid) {
    IncomingLog incomingLog = null;

    ResultSet rset = null;

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

        pstmt.setString(1, uuid);
        rset = pstmt.executeQuery();

        if (rset.next()) {
            incomingLog = beanProcessor.toBean(rset, IncomingLog.class);
        }

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

    }

    return incomingLog;
}

From source file:ke.co.tawi.babblesms.server.persistence.maskcode.ShortcodeDAO.java

/**
* @see ke.co.tawi.babblesms.server.persistence.maskcode.BabbleShortcodeDAO#get(java.lang.String)
 *//*from w w w  . j  a  v a 2s  . c o  m*/
@Override
public Shortcode get(String uuid) {
    Shortcode shortcode = null;

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

        pstmt.setString(1, uuid);
        try (ResultSet rset = pstmt.executeQuery();) {

            if (rset.next()) {
                shortcode = beanProcessor.toBean(rset, Shortcode.class);
            }
        }

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

    return shortcode;
}

From source file:ke.co.tawi.babblesms.server.persistence.smsgw.tawi.GatewayDAO.java

/**
 * @see ke.co.tawi.babblesms.server.persistence.smsgw.tawi.BabbleGatewayDAO#get(ke.co.tawi.babblesms.server.beans.account.Account)
 *///ww  w.j  a v a 2 s .c  o m
@Override
public TawiGateway get(Account account) {
    TawiGateway gw = null;

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

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

        if (rset.next()) {
            gw = beanProcessor.toBean(rset, TawiGateway.class);
        }

    } catch (SQLException e) {
        logger.error("SQLException when getting TawiGateway for: " + account);
        logger.error(ExceptionUtils.getStackTrace(e));
    }

    return gw;
}

From source file:com.gatf.executor.executor.PerformanceTestCaseExecutor.java

public List<TestCaseReport> execute(TestCase testCase, TestCaseExecutorUtil testCaseExecutorUtil) {

    WorkflowContextHandler workflowContextHandler = testCaseExecutorUtil.getContext()
            .getWorkflowContextHandler();

    SingleTestCaseExecutor singleTestCaseExecutor = new SingleTestCaseExecutor();
    List<TestCaseReport> reports = singleTestCaseExecutor.execute(testCase, testCaseExecutorUtil);

    TestCaseReport testCaseReport = reports == null || reports.isEmpty() ? null : reports.get(0);
    reports.add(new TestCaseReport(testCaseReport));

    testCaseReport.setNumberOfRuns(1);//from   ww  w.jav  a2  s . co m
    testCaseReport.getExecutionTimes().add(testCaseReport.getExecutionTime());

    if (testCase.isStopOnFirstFailureForPerfTest() && testCase.isFailed()) {
        return reports;
    }

    int numParallel = Runtime.getRuntime().availableProcessors() * 2;

    int counter = 0;

    List<ListenableFuture<TestCaseReport>> futures = new ArrayList<ListenableFuture<TestCaseReport>>();
    for (int i = 0; i < testCase.getNumberOfExecutions() - 1; i++) {

        testCaseReport.setNumberOfRuns(testCaseReport.getNumberOfRuns() + 1);
        TestCase testCaseCopy = new TestCase(testCase);
        TestCaseReport testCaseReportCopy = new TestCaseReport(testCaseReport);
        reports.add(testCaseReportCopy);

        try {
            workflowContextHandler.handleContextVariables(testCaseCopy, new HashMap<String, String>(),
                    testCaseExecutorUtil.getContext());
        } catch (Throwable e) {
            testCaseReportCopy.setExecutionTime(0L);
            testCaseReportCopy.setStatus(TestStatus.Failed.status);
            testCaseReport.setFailureReason(TestFailureReason.Exception.status);
            testCaseReportCopy.setErrorText(ExceptionUtils.getStackTrace(e));
            testCaseReportCopy.setError(e.getMessage());
            if (e.getMessage() == null && testCaseReportCopy.getErrorText() != null
                    && testCaseReportCopy.getErrorText().indexOf("\n") != -1) {
                testCaseReportCopy.setError(testCaseReportCopy.getErrorText().substring(0,
                        testCaseReportCopy.getErrorText().indexOf("\n")));
            }

            testCaseReport.setExecutionTime(
                    testCaseReport.getExecutionTime() + testCaseReportCopy.getExecutionTime());
            testCaseReport.getExecutionTimes().add(testCaseReportCopy.getExecutionTime());
            testCaseReport.getErrors().put(i + 2 + "", testCaseReportCopy.getError());

            e.printStackTrace();
            continue;
        }

        ListenableFuture<TestCaseReport> listenableFuture = testCaseExecutorUtil.executeTestCase(testCaseCopy,
                testCaseReportCopy);
        futures.add(listenableFuture);

        if (futures.size() == numParallel) {
            for (ListenableFuture<TestCaseReport> listenableFutureT : futures) {

                try {
                    TestCaseReport tc = listenableFutureT.get();
                    testCaseReport.setExecutionTime(testCaseReport.getExecutionTime() + tc.getExecutionTime());
                    testCaseReport.getExecutionTimes().add(tc.getExecutionTime());
                    if (tc.getError() != null) {
                        testCaseReport.getErrors().put(i + 2 + "", tc.getError());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                counter++;
            }
            futures.clear();
        }
    }

    for (int i = counter; i < counter + futures.size(); i++) {

        ListenableFuture<TestCaseReport> listenableFuture = futures.get(i);
        try {
            TestCaseReport tc = listenableFuture.get();
            testCaseReport.setExecutionTime(testCaseReport.getExecutionTime() + tc.getExecutionTime());
            testCaseReport.getExecutionTimes().add(tc.getExecutionTime());
            if (tc.getError() != null) {
                testCaseReport.getErrors().put(i + 2 + "", tc.getError());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    testCaseReport
            .setAverageExecutionTime(testCaseReport.getExecutionTime() / testCaseReport.getNumberOfRuns());
    return reports;
}

From source file:io.galeb.router.sync.HttpClient.java

private static String localIpsEncoded() {
    final List<String> ipList = new ArrayList<>();
    try {/*from   ww w .jav  a 2  s.  co m*/
        Enumeration<NetworkInterface> ifs = NetworkInterface.getNetworkInterfaces();
        while (ifs.hasMoreElements()) {
            NetworkInterface localInterface = ifs.nextElement();
            if (!localInterface.isLoopback() && localInterface.isUp()) {
                Enumeration<InetAddress> ips = localInterface.getInetAddresses();
                while (ips.hasMoreElements()) {
                    InetAddress ipaddress = ips.nextElement();
                    if (ipaddress instanceof Inet4Address) {
                        ipList.add(ipaddress.getHostAddress());
                        break;
                    }
                }
            }
        }
    } catch (Exception e) {
        LOGGER.error(ExceptionUtils.getStackTrace(e));
    }
    String ip = String.join("-", ipList);
    if (ip == null || "".equals(ip)) {
        ip = "undef-" + System.currentTimeMillis();
    }
    return ip.replaceAll("[:%]", "");
}

From source file:com.aurel.track.fieldType.runtime.matchers.converter.IntegerMatcherConverter.java

/**
 * Convert the xml string to object value after load
 * @param value/*ww w . j  a  va2 s .co  m*/
 * @param matcherRelation
 * @return
 */
@Override
public Object fromXMLString(String value, Integer matcherRelation) {
    if (value == null || "".equals(value) || matcherRelation == null) {
        return null;
    }
    switch (matcherRelation.intValue()) {
    case MatchRelations.EQUAL:
    case MatchRelations.NOT_EQUAL:
    case MatchRelations.GREATHER_THAN:
    case MatchRelations.GREATHER_THAN_EQUAL:
    case MatchRelations.LESS_THAN:
    case MatchRelations.LESS_THAN_EQUAL:
        try {
            return Integer.valueOf(value);
        } catch (Exception e) {
            LOGGER.warn("Converting the " + value + " to Integer failed with " + e.getMessage());
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        }
    }
    return null;
}