Example usage for org.apache.commons.lang3.exception ExceptionUtils getStackFrames

List of usage examples for org.apache.commons.lang3.exception ExceptionUtils getStackFrames

Introduction

In this page you can find the example usage for org.apache.commons.lang3.exception ExceptionUtils getStackFrames.

Prototype

static String[] getStackFrames(final String stackTrace) 

Source Link

Document

Returns an array where each element is a line from the argument.

The end of line is determined by the value of SystemUtils#LINE_SEPARATOR .

Usage

From source file:com.creactiviti.piper.core.pipeline.YamlPipelineRepository.java

protected Pipeline parsePipeline(IdentifiableResource aResource) {
    try {/*  w w w  .j a va  2s  . c om*/
        Map<String, Object> yamlMap = parse(aResource);
        yamlMap.put(DSL.ID, aResource.getId());
        return new SimplePipeline(yamlMap);
    } catch (Exception e) {
        SimplePipeline pipeline = new SimplePipeline(Collections.singletonMap(DSL.ID, aResource.getId()));
        pipeline.setError(new ErrorObject(e.getMessage(), ExceptionUtils.getStackFrames(e)));
        return pipeline;
    }
}

From source file:com.creactiviti.piper.core.Worker.java

private void handleException(TaskExecution aTask, Exception aException) {
    logger.error(aException.getMessage(), aException);
    SimpleTaskExecution task = SimpleTaskExecution.createForUpdate(aTask);
    task.setError(new ErrorObject(aException.getMessage(), ExceptionUtils.getStackFrames(aException)));
    task.setStatus(TaskStatus.FAILED);/*  ww  w  . j a  va2  s.  c  o m*/
    messenger.send(Queues.ERRORS, task);
}

From source file:com.creactiviti.piper.core.Coordinator.java

/**
 * Complete a task of a given job.//from   w w  w. j  a  v a  2 s.  co m
 * 
 * @param aTask
 *          The task to complete.
 */
public void complete(TaskExecution aTask) {
    try {
        taskCompletionHandler.handle(aTask);
    } catch (Exception e) {
        SimpleTaskExecution exec = SimpleTaskExecution.createForUpdate(aTask);
        exec.setError(new ErrorObject(e.getMessage(), ExceptionUtils.getStackFrames(e)));
        handleError(exec);
    }
}

From source file:com.mirth.connect.client.ui.Frame.java

/**
 * Alerts the user with an exception dialog with the passed in stack trace.
 *///  w ww  . ja va 2 s. co  m
public void alertThrowable(Component parentComponent, Throwable t, String customMessage,
        boolean showMessageOnForbidden, String safeErrorKey) {
    if (connectionError) {
        return;
    }

    if (safeErrorKey != null) {
        increaseSafeErrorFailCount(safeErrorKey);

        if (getSafeErrorFailCount(safeErrorKey) < 3) {
            return;
        }
    }

    parentComponent = getVisibleComponent(parentComponent);
    String message = StringUtils.trimToEmpty(customMessage);
    boolean showDialog = true;

    if (t != null) {
        // Always print the stacktrace for troubleshooting purposes
        t.printStackTrace();

        if (t instanceof ExecutionException && t.getCause() != null) {
            t = t.getCause();
        }
        if (t.getCause() != null && t.getCause() instanceof ClientException) {
            t = t.getCause();
        }

        if (StringUtils.isBlank(message) && StringUtils.isNotBlank(t.getMessage())) {
            message = t.getMessage();
        }

        /*
         * Logout if an exception occurs that indicates the server is no longer running or
         * accessible. We only want to do this if a ClientException was passed in, indicating it
         * was actually due to a request to the server. Other places in the application could
         * call this method with an exception that happens to contain the string
         * "Connection reset", for example.
         */
        if (t instanceof ClientException) {
            if (t instanceof ForbiddenException
                    || t.getCause() != null && t.getCause() instanceof ForbiddenException) {
                message = "You are not authorized to perform this action.\n\n" + message;
                if (!showMessageOnForbidden) {
                    showDialog = false;
                }
            } else if (StringUtils.contains(t.getMessage(), "Received close_notify during handshake")) {
                return;
            } else if (t.getCause() != null && t.getCause() instanceof IllegalStateException
                    && mirthClient.isClosed()) {
                return;
            } else if (StringUtils.contains(t.getMessage(), "reset") || (t instanceof UnauthorizedException
                    || t.getCause() != null && t.getCause() instanceof UnauthorizedException)) {
                connectionError = true;
                statusUpdaterExecutor.shutdownNow();

                alertWarning(parentComponent,
                        "Sorry your connection to Mirth has either timed out or there was an error in the connection.  Please login again.");
                if (!exportChannelOnError()) {
                    return;
                }
                mirthClient.close();
                this.dispose();
                LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
                return;
            } else if (t.getCause() != null && t.getCause() instanceof HttpHostConnectException
                    && StringUtils.contains(t.getCause().getMessage(), "Connection refused")) {
                connectionError = true;
                statusUpdaterExecutor.shutdownNow();

                String server;
                if (!StringUtils.isBlank(PlatformUI.SERVER_NAME)) {
                    server = PlatformUI.SERVER_NAME + "(" + PlatformUI.SERVER_URL + ")";
                } else {
                    server = PlatformUI.SERVER_URL;
                }
                alertWarning(parentComponent, "The Mirth Connect server " + server
                        + " is no longer running.  Please start it and log in again.");
                if (!exportChannelOnError()) {
                    return;
                }
                mirthClient.close();
                this.dispose();
                LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
                return;
            }
        }

        for (String stackFrame : ExceptionUtils.getStackFrames(t)) {
            if (StringUtils.isNotEmpty(message)) {
                message += '\n';
            }
            message += StringUtils.trim(stackFrame);
        }
    }

    logger.error(message);

    if (showDialog) {
        Window owner = getWindowForComponent(parentComponent);

        if (owner instanceof java.awt.Frame) {
            new ErrorDialog((java.awt.Frame) owner, message);
        } else { // window instanceof Dialog
            new ErrorDialog((java.awt.Dialog) owner, message);
        }
    }
}

From source file:org.csstudio.diirt.util.core.preferences.ExceptionUtilities.java

/**
 * Return a reduced version of the stack frame string, containing the given
 * {@code pattern} string./*from   ww w  .  j  a v  a2s.co  m*/
 *
 * @param ex The exception.
 * @param pattern The string to be matched.
 * @return The reduced version of the stack frame string, containing the
 *         given {@code pattern} string, or the full stack trace if the
 *         {@code pattern} string is not found or {@code null}.
 *         {@code null} is returned if the given exception is {@code null}.
 */
public static String reducedStackTrace(Throwable ex, String pattern) {

    if (ex == null) {
        return null;
    } else if (pattern == null) {
        pattern = "";
    }

    StringBuilder builder = new StringBuilder();
    String[] stackFrames = ExceptionUtils.getStackFrames(ex);

    builder.append(stackFrames[0]);

    boolean patternFound = false;

    for (int i = 1; i < stackFrames.length; i++) {

        String frame = stackFrames[i];

        builder.append("\n").append(frame);

        boolean found = frame.contains(pattern);

        if (!patternFound || found) {
            if (found) {
                patternFound = true;
            }
        } else if (patternFound && !found && i < stackFrames.length - 1) {
            builder.append("\n\t...");
            break;
        }

    }

    builder.append('\n');

    return builder.toString();

}

From source file:org.openmrs.module.openconceptlab.updater.Updater.java

public static String getErrorMessage(Throwable e) {
    String message = e.getMessage();
    Throwable rootCause = ExceptionUtils.getRootCause(e);
    if (rootCause == null) {
        rootCause = e;// ww w. j av a2s  . c o m
    }

    String[] stackFrames = ExceptionUtils.getStackFrames(rootCause);
    int endIndex = stackFrames.length > 5 ? 5 : stackFrames.length;
    message += "\n caused by: " + StringUtils.join(stackFrames, "\n", 0, endIndex);

    if (message.length() > 1024) {
        return message.substring(0, 1024);
    } else {
        return message;
    }
}