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.lucene.index.associatedFields.LuceneFileExtractor.java

public static Reader getReader(File file) {
    Reader reader = null;/*from  w ww.  j  a v a2s . c om*/
    if (file == null || !file.exists()) {
        return null;
    }
    try {
        reader = new FileReader(file);
    } catch (FileNotFoundException e) {
        LOGGER.info("File " + file.getName() + " not found. " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    reader = new BufferedReader(reader);
    return reader;
}

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

/**
 * /*from w  ww . j av  a  2 s .com*/
 * @param notification
 * @return whether the action was successful or not
 */
@Override
public boolean putNotification(Notification notification) {
    boolean success = true;

    Connection conn = null;
    PreparedStatement pstmt = null;

    try {
        conn = dbCredentials.getConnection();
        pstmt = conn.prepareStatement(
                "INSERT INTO Notification (Uuid, origin, ShortDesc, LongDesc) " + "VALUES (?,?,?,?);");
        pstmt.setString(1, notification.getUuid());
        pstmt.setString(2, notification.getOrigin());
        pstmt.setString(3, notification.getShortDesc());
        pstmt.setString(4, notification.getLongDesc());

        pstmt.execute();

    } catch (SQLException e) {
        logger.error("SQL Exception when trying to put: " + notification);
        logger.error(ExceptionUtils.getStackTrace(e));
        success = false;
    } finally {
        if (pstmt != null) {
            try {
                pstmt.close();
            } catch (SQLException e) {
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
            }
        }
    }
    return success;
}

From source file:com.threewks.thundr.proxy.ProxyImpl.java

@Override
public void proxy(ProxyRule rule, HttpServletRequest request, HttpServletResponse response) {
    ProxyInterceptorRegistry interceptorRegistry = rule.getInterceptorRegistry();

    try {//from   w ww  .  j a  v  a2  s.c  o m
        Request inboundRequest = Request.from(request);
        Logger.info("Received request to proxy: %s", inboundRequest);

        Logger.info("Applying proxy rule: %s", rule);
        Request proxyRequest = buildProxyRequest.from(rule, inboundRequest);
        Logger.info("Resulting proxy request: %s", proxyRequest);

        Logger.debug("Invoking before proxy interceptors...");
        Response alternateResponse = interceptorRegistry.before(inboundRequest, proxyRequest);
        if (alternateResponse != null) {
            Logger.info("Before interceptor cancelled request. Sending alternate response: %s",
                    alternateResponse);
            sendResponse(alternateResponse, response);
            return;
        }

        Logger.debug("Sending proxy request: %s", proxyRequest);
        Response proxiedResponse = sendRequest(proxyRequest);
        Logger.info("Received response from target: %s", proxiedResponse);

        Logger.debug("Invoking after proxy interceptors...");
        alternateResponse = interceptorRegistry.after(inboundRequest, proxyRequest, proxiedResponse);
        if (alternateResponse != null) {
            Logger.info("After interceptor is overriding the proxied response.");
            proxiedResponse = alternateResponse;
        }

        Logger.info("Sending response: %s", proxiedResponse);
        sendResponse(proxiedResponse, response);
    } catch (Throwable t) {
        Logger.error("An unexpected error occurred while proxying: %s", ExceptionUtils.getStackTrace(t));
        Logger.debug("Invoking exception interceptors...");
        interceptorRegistry.exception(t, request, response);
    }
}

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

/**
 * This method sets to null all occurrences of oldOID
 * going through all related tables in the database.
 * @param oldOID object identifier to be replaced 
 *///w w  w.j  a v a2s. com
public static void setToNull(Class[] peerClasses, String[] fields, Integer oldOID) {
    Criteria selectCriteria = new Criteria();
    Criteria updateCriteria = new Criteria();
    for (int i = 0; i < peerClasses.length; ++i) {
        Class peerClass = peerClasses[i];
        String field = fields[i];
        selectCriteria.clear();
        updateCriteria.clear();
        selectCriteria.add(field, oldOID, Criteria.EQUAL);
        updateCriteria.add(field, (Object) null, Criteria.ISNULL);
        try {
            Class partypes[] = new Class[2];
            partypes[0] = Criteria.class;
            partypes[1] = Criteria.class;
            Method meth = peerClass.getMethod("doUpdate", partypes);

            Object arglist[] = new Object[2];
            arglist[0] = selectCriteria;
            arglist[1] = updateCriteria;
            meth.invoke(peerClass, arglist);
        } catch (Exception e) {
            LOGGER.error("Exception when trying to set " + "oldOID " + oldOID + " to null " + " for class "
                    + peerClass.toString() + " and field " + field + ": " + e.getMessage(), e);
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        }
    }
}

From source file:com.aurel.track.exchange.docx.exporter.HyperlinkUtil.java

public static Hyperlink createHyperlink(MainDocumentPart mdp, String url, String linkText) {
    try {//from   w w  w. j ava  2s.co  m
        // We need to add a relationship to word/_rels/document.xml.rels
        // but since its external, we don't use the 
        // usual wordMLPackage.getMainDocumentPart().addTargetPart
        // mechanism
        ObjectFactory factory = new ObjectFactory();
        Relationship rel = factory.createRelationship();
        rel.setType(Namespaces.HYPERLINK);
        rel.setTarget(url);
        rel.setTargetMode("External");
        mdp.getRelationshipsPart().addRelationship(rel);

        // addRelationship sets the rel's @Id
        String hpl = "<w:hyperlink r:id=\"" + rel.getId()
                + "\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" "
                + "xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" >" + "<w:r>"
                + "<w:rPr>" + "<w:rStyle w:val=\"Hyperlink\" />" + // TODO: enable this style in the document!
                "</w:rPr>" + "<w:t>" + linkText + "</w:t>" + "</w:r>" + "</w:hyperlink>";

        return (Hyperlink) XmlUtils.unmarshalString(hpl);

    } catch (Exception e) {
        LOGGER.error(ExceptionUtils.getStackTrace(e));
        return null;
    }

}

From source file:ke.co.tawi.babblesms.server.servlet.util.PropertiesConfig.java

/**
 * Populate the internal HashMap which will hold configuration keys and values
 *//*from ww  w.  j  a v a 2s  . com*/
private void initConfigHash() {
    PropertiesConfiguration config;
    String key;

    try {
        config = new PropertiesConfiguration();
        config.setListDelimiter('|'); // our array delimiter
        config.setFileName(configFile);
        config.load();

        Iterator<String> keys = config.getKeys();

        while (keys.hasNext()) {
            key = keys.next();
            configHash.put(key, (String) config.getProperty(key));
        }

    } catch (ConfigurationException e) {
        logger.error("ConfigurationException when trying to initialize configuration HashMap");
        logger.error(ExceptionUtils.getStackTrace(e));
    }
}

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

/**
 * Loads a notifyTriggerBean by primary key
 * @param objectID/* w w w .j  a va2  s  .  co  m*/
 * @return
 */
@Override
public TNotifyTriggerBean loadByPrimaryKey(Integer objectID) {
    TNotifyTrigger tNotifyTrigger = null;
    try {
        tNotifyTrigger = retrieveByPK(objectID);
    } catch (Exception e) {
        LOGGER.warn("Loading of a notificationTrigger by primary key " + objectID + " failed with "
                + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    if (tNotifyTrigger != null) {
        return tNotifyTrigger.getBean();
    }
    return null;
}

From source file:com.daou.terracelicense.controller.MachineController.java

/**
 * Machine-Controller-04/*  www.j av  a  2s.  c om*/
 * Add Machine
 */
@RequestMapping(value = "/add", method = RequestMethod.POST)
@ResponseBody
public int addMachine(@RequestBody Machine machine) {
    int result = 0;
    try {
        result = machineService.addMachine(machine);
    } catch (Exception e) {
        logger.error(ExceptionUtils.getStackTrace(e));
    }
    return result;
}

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

@Override
@Post("json")/*from w  w w.  ja v  a 2 s  . c  o  m*/
public Representation post(Representation entity) {
    StringRepresentation presentation;

    try {
        final String instanceName = (String) getRequest().getAttributes().get(INSTANCE_NAME);

        if (instanceName == null) {
            // This is a request to create an instance
            try {
                final Instance instance = mapper.readValue(ByteStreams.toByteArray(entity.getStream()),
                        Instance.class);
                presentation = addInstance(instance);
            } catch (final Exception e) {
                presentation = new StringRepresentation(
                        e.getMessage() + "\n" + ExceptionUtils.getStackTrace(e));
                LOGGER.error("Caught exception while processing post request", e);
                ControllerRestApplication.getControllerMetrics()
                        .addMeteredGlobalValue(ControllerMeter.CONTROLLER_INTERNAL_ERROR, 1L);
                setStatus(Status.SERVER_ERROR_INTERNAL);
            }
        } else {
            // This is a request to toggle the state of an instance
            if (_pinotHelixResourceManager.instanceExists(instanceName)) {
                final String state = getRequest().getEntityAsText().trim();

                if (isValidState(state)) {
                    presentation = toggleInstanceState(instanceName, state);
                } else {
                    LOGGER.error(INVALID_STATE_ERROR);
                    setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                    return new StringRepresentation(INVALID_STATE_ERROR);
                }
            } else {
                setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                presentation = new StringRepresentation("Error: Instance " + instanceName + " not found.");
            }
        }
    } catch (final Exception e) {
        presentation = new StringRepresentation(e.getMessage() + "\n" + ExceptionUtils.getStackTrace(e));
        LOGGER.error("Caught exception while processing post request", e);
        ControllerRestApplication.getControllerMetrics()
                .addMeteredGlobalValue(ControllerMeter.CONTROLLER_INSTANCE_POST_ERROR, 1L);
        setStatus(Status.SERVER_ERROR_INTERNAL);
    }

    return presentation;
}

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

/**
 * Convert the xml string to object value after load
 * @param value//from w  w w.j a  v  a2 s .c  om
 * @param matcherRelation
 * @return
 */
@Override
public Object fromXMLString(String value, Integer matcherRelation) {
    if (value == null || value.trim().length() == 0 || matcherRelation == null) {
        return null;
    }
    switch (matcherRelation) {
    case MatchRelations.EQUAL:
    case MatchRelations.NOT_EQUAL:
        Integer intValue = null;
        try {
            intValue = Integer.valueOf(value);
        } catch (Exception e) {
            LOGGER.warn("Converting the " + value + " to Integer failed with " + e.getMessage());
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        }
        if (intValue != null) {
            return new Integer[] { intValue };
        }
    }
    return null;
}