Example usage for java.lang Throwable getCause

List of usage examples for java.lang Throwable getCause

Introduction

In this page you can find the example usage for java.lang Throwable getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:com.intel.podm.client.WebClientImpl.java

private void checkConnectException(URI requestUri, Throwable e)
        throws ExternalServiceApiReaderConnectionException {
    if (getRootCause(e) instanceof ConnectException) {
        throw new ExternalServiceApiReaderConnectionException(e.getMessage(), requestUri, e.getCause());
    }/*from   w ww  .  j a  v a 2s. c o  m*/
}

From source file:io.druid.storage.google.GoogleDataSegmentPuller.java

@Override
public Predicate<Throwable> shouldRetryPredicate() {
    return new Predicate<Throwable>() {
        @Override//from  ww w  .  j  av a 2s  .  c o  m
        public boolean apply(Throwable e) {
            if (e == null) {
                return false;
            }
            if (GoogleUtils.GOOGLE_RETRY.apply(e)) {
                return true;
            }
            // Look all the way down the cause chain, just in case something wraps it deep.
            return apply(e.getCause());
        }
    };
}

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

public void doRunDatabaseTask() {
    DatabaseTask databaseTask = (DatabaseTask) taskTable.getValueAt(taskTable.getSelectedRow(), 1);

    if (databaseTask.getConfirmationMessage() != null
            && !getFrame().alertOption(getFrame(), databaseTask.getConfirmationMessage())) {
        return;//  w w w.j  a  va 2 s.  c o  m
    }

    final String workingId = getFrame().startWorking("Running database task...");
    final String taskId = databaseTask.getId();

    SwingWorker<String, Void> worker = new SwingWorker<String, Void>() {

        @Override
        public String doInBackground() throws ClientException {
            return getFrame().mirthClient.runDatabaseTask(taskId);
        }

        @Override
        public void done() {
            try {
                String result = get();
                if (StringUtils.isNotBlank(result)) {
                    getFrame().alertInformation(getFrame(), result);
                }
            } catch (Throwable t) {
                if (t instanceof ExecutionException) {
                    t = t.getCause();
                }
                getFrame().alertThrowable(getFrame(), t, "Error running database task: " + t.getMessage());
            } finally {
                getFrame().stopWorking(workingId);
                doRefresh();
            }
        }
    };

    worker.execute();
    doRefresh();
}

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

public void doCancelDatabaseTask() {
    DatabaseTask databaseTask = (DatabaseTask) taskTable.getValueAt(taskTable.getSelectedRow(), 1);

    if (databaseTask.getStatus() != Status.RUNNING) {
        getFrame().alertError(getFrame(), "Task \"" + databaseTask.getName() + "\" is not currently running.");
        return;//  www. j ava  2  s.c o m
    }

    if (!getFrame().alertOption(getFrame(), "Are you sure you want to cancel the selected database task?")) {
        return;
    }

    final String workingId = getFrame().startWorking("Cancelling database task...");
    final String taskId = databaseTask.getId();

    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {

        @Override
        public Void doInBackground() throws ClientException {
            getFrame().mirthClient.cancelDatabaseTask(taskId);
            return null;
        }

        @Override
        public void done() {
            try {
                get();
            } catch (Throwable t) {
                if (t instanceof ExecutionException) {
                    t = t.getCause();
                }
                getFrame().alertThrowable(getFrame(), t, "Error cancelling database task: " + t.getMessage());
            } finally {
                getFrame().stopWorking(workingId);
                doRefresh();
            }
        }
    };

    worker.execute();
}

From source file:io.wcm.caravan.io.http.impl.CaravanHttpClientImpl.java

private Throwable mapToKnownException(CaravanHttpRequest request, Throwable ex) {
    if (ex instanceof RequestFailedRuntimeException || ex instanceof IllegalResponseRuntimeException) {
        return ex;
    }/*from  w  w  w. j a  v a 2s  .  c o  m*/
    if ((ex instanceof HystrixRuntimeException || ex instanceof ClientException) && ex.getCause() != null) {
        return mapToKnownException(request, ex.getCause());
    }
    throw new RequestFailedRuntimeException(request,
            StringUtils.defaultString(ex.getMessage(), ex.getClass().getSimpleName()), ex);
}

From source file:com.streamsets.pipeline.stage.origin.tcp.TCPObjectToRecordHandler.java

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable t) {
    Throwable exception = t;
    if (exception instanceof DecoderException) {
        // unwrap the Netty decoder exception
        exception = exception.getCause();
    }/*from   ww  w  .  j  a  va 2  s .c o m*/
    if (exception instanceof IOException && StringUtils.contains(exception.getMessage(), RST_PACKET_MESSAGE)) {
        // client disconnected forcibly
        if (LOG.isDebugEnabled()) {
            LOG.debug("Client at {} (established at {}) sent RST to server; disconnecting",
                    ctx.channel().remoteAddress().toString(),
                    new SimpleDateFormat(LOG_DATE_FORMAT_STR).format(new Date(lastChannelStart)));
        }
        ctx.close();
        return;
    } else if (exception instanceof DataParserException) {
        exception = new OnRecordErrorException(Errors.TCP_08, exception.getMessage(), exception);
    }

    LOG.error("exceptionCaught in TCPObjectToRecordHandler", exception);
    if (exception instanceof OnRecordErrorException) {
        OnRecordErrorException errorEx = (OnRecordErrorException) exception;
        switch (context.getOnErrorRecord()) {
        case DISCARD:
            break;
        case STOP_PIPELINE:
            if (LOG.isErrorEnabled()) {
                LOG.error(String.format(
                        "OnRecordErrorException caught when parsing TCP data; failing pipeline %s as per stage configuration: %s",
                        context.getPipelineId(), exception.getMessage()), exception);
            }
            stopPipelineHandler.stopPipeline(context.getPipelineId(), errorEx);
            break;
        case TO_ERROR:
            batchContext.toError(context.createRecord(generateRecordId()), errorEx);
            break;
        }
    } else {
        context.reportError(Errors.TCP_07, exception.getClass().getName(), exception.getMessage(), exception);
    }
    // Close the connection when an exception is raised.
    ctx.close();
}

From source file:edu.harvard.iq.dataverse.GuestbookPage.java

public String save() {
    boolean create = false;
    if (!(guestbook.getCustomQuestions() == null)) {
        for (CustomQuestion cq : guestbook.getCustomQuestions()) {
            if (cq.getQuestionType().equals("text")) {
                cq.setCustomQuestionValues(null);
            }//from w w  w .  j  a  v a 2s. com
        }

        Iterator<CustomQuestion> cqIt = guestbook.getCustomQuestions().iterator();
        while (cqIt.hasNext()) {
            CustomQuestion cq = cqIt.next();
            if (StringUtils.isBlank(cq.getQuestionString())) {
                cqIt.remove();
            }
        }

        for (CustomQuestion cq : guestbook.getCustomQuestions()) {
            if (cq != null && cq.getQuestionType().equals("options")) {
                Iterator<CustomQuestionValue> cqvIt = cq.getCustomQuestionValues().iterator();
                while (cqvIt.hasNext()) {
                    CustomQuestionValue cqv = cqvIt.next();
                    if (StringUtils.isBlank(cqv.getValueString())) {
                        cqvIt.remove();
                    }
                }
            }
        }

        for (CustomQuestion cq : guestbook.getCustomQuestions()) {
            if (cq != null && cq.getQuestionType().equals("options")) {
                if (cq.getCustomQuestionValues() == null || cq.getCustomQuestionValues().isEmpty()) {
                    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(
                            FacesMessage.SEVERITY_ERROR, "Guestbook Save Failed",
                            " - An Option question requires multiple options. Please complete before saving."));
                    return null;
                }
                if (cq.getCustomQuestionValues().size() == 1) {
                    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(
                            FacesMessage.SEVERITY_ERROR, "Guestbook Save Failed",
                            " - An Option question requires multiple options. Please complete before saving."));
                    return null;
                }
            }
        }
        int i = 0;
        for (CustomQuestion cq : guestbook.getCustomQuestions()) {
            int j = 0;
            cq.setDisplayOrder(i);
            if (cq.getCustomQuestionValues() != null && !cq.getCustomQuestionValues().isEmpty()) {
                for (CustomQuestionValue cqv : cq.getCustomQuestionValues()) {
                    cqv.setDisplayOrder(j);
                    j++;
                }
            }
            i++;
        }
    }

    Command<Dataverse> cmd;
    try {
        if (editMode == EditMode.CREATE || editMode == EditMode.CLONE) {
            guestbook.setCreateTime(new Timestamp(new Date().getTime()));
            guestbook.setUsageCount(new Long(0));
            guestbook.setEnabled(true);
            dataverse.getGuestbooks().add(guestbook);
            cmd = new UpdateDataverseCommand(dataverse, null, null, dvRequestService.getDataverseRequest(),
                    null);
            commandEngine.submit(cmd);
            create = true;
        } else {
            cmd = new UpdateDataverseGuestbookCommand(dataverse, guestbook,
                    dvRequestService.getDataverseRequest());
            commandEngine.submit(cmd);
        }

    } catch (EJBException ex) {
        StringBuilder error = new StringBuilder();
        error.append(ex).append(" ");
        error.append(ex.getMessage()).append(" ");
        Throwable cause = ex;
        while (cause.getCause() != null) {
            cause = cause.getCause();
            error.append(cause).append(" ");
            error.append(cause.getMessage()).append(" ");
        }
        //
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL,
                "Guestbook Save Failed", " - " + error.toString()));
        logger.info("Guestbook Page EJB Exception. Dataverse: " + dataverse.getName());
        logger.info(error.toString());
        return null;
    } catch (CommandException ex) {
        logger.info("Guestbook Page Command Exception. Dataverse: " + dataverse.getName());
        logger.info(ex.toString());
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_FATAL, "Guestbook Save Failed", " - " + ex.toString()));
        //logger.severe(ex.getMessage());
    }
    editMode = null;
    String msg = (create) ? "The guestbook has been created." : "The guestbook has been edited and saved.";
    JsfHelper.addFlashMessage(msg);
    return "/manage-guestbooks.xhtml?dataverseId=" + dataverse.getId() + "&faces-redirect=true";
}

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

@Override
public void doRefresh() {
    final String workingId = getFrame().startWorking("Loading database tasks...");
    final int selectedRow = taskTable.getSelectedRow();

    SwingWorker<Map<String, DatabaseTask>, Void> worker = new SwingWorker<Map<String, DatabaseTask>, Void>() {

        @Override// w w  w . j  a  v a  2 s. c  o m
        public Map<String, DatabaseTask> doInBackground() throws ClientException {
            return getFrame().mirthClient.getDatabaseTasks();
        }

        @Override
        public void done() {
            try {
                Map<String, DatabaseTask> databaseTasks = get();
                if (databaseTasks == null) {
                    databaseTasks = new HashMap<String, DatabaseTask>();
                }

                Object[][] data = new Object[databaseTasks.size()][4];
                int i = 0;

                for (DatabaseTask databaseTask : databaseTasks.values()) {
                    Status status = databaseTask.getStatus();
                    data[i][0] = new CellData(status == Status.IDLE ? UIConstants.ICON_BULLET_YELLOW
                            : UIConstants.ICON_BULLET_GREEN, status.toString());
                    data[i][1] = databaseTask;
                    data[i][2] = databaseTask.getDescription();
                    data[i][3] = databaseTask.getStartDateTime();
                    i++;
                }

                ((RefreshTableModel) taskTable.getModel()).refreshDataVector(data);

                if (selectedRow > -1 && selectedRow < taskTable.getRowCount()) {
                    taskTable.setRowSelectionInterval(selectedRow, selectedRow);
                }
            } catch (Throwable t) {
                if (t instanceof ExecutionException) {
                    t = t.getCause();
                }
                getFrame().alertThrowable(getFrame(), t, "Error loading database tasks: " + t.toString());
            } finally {
                getFrame().stopWorking(workingId);
            }
        }
    };

    worker.execute();
}

From source file:de.iteratec.iteraplan.presentation.responsegenerators.GraphicsResponseGenerator.java

/**
 * Checks whether the generation of the HTTP response containing the SVG document has been aborted
 * by the user. This method makes the assumption that if the root cause of the given IOException
 * is an instance of TransformerException the operation has been canceled. Of course this
 * assumption might hide other reasons for why this kind of exception might have been thrown, but
 * it's the main reason./*from  w w w  .  j ava  2s .  c o m*/
 * <p>
 * There's a problem that makes it cumbersome to reliably detect if the generation of the response
 * has been canceled: The actual exception type at the bottom of the stack of Throwables that make
 * up the given IOException is a java.net.SocketException which in turn is probably wrapped by app
 * server specific exception types. These are then wrapped by exceptions of the various frameworks
 * that are used to write the SVG document to the HTTP response. For example, on Tomcat the stack
 * (from top to bottom) looks like the following:
 * <ul>
 * <li>java.io.IOException</li>
 * <li>javax.xml.transform.TransformerException</li>
 * <li>org.xml.sax.SAXException</li>
 * <li>org.apache.catalina.connector.ClientAbortException</
 * <li>java.net.SocketException</li>
 * </ul>
 * Therefore the above assumption is made for brevity.
 * 
 * @param ex
 *          The IOException that might indicate that the operation has been cancelled.
 * @return {@code true}, if the operation has probably been cancelled, {@code false} otherwise.
 */
protected boolean hasBeenAborted(Exception ex) {
    Throwable t = ex;
    while ((t.getCause() != null) && !t.getCause().equals(t)) {
        if ((t.getCause() instanceof javax.net.ssl.SSLException)
                || (t.getCause() instanceof javax.xml.transform.TransformerException)
                || (t.getCause() instanceof java.net.SocketException)) {
            return true;
        }
        t = t.getCause();
    }
    return false;
}

From source file:sample.contact.web.IndexController.java

/**
 * Error page./*from ww  w. j  ava 2 s  .c  om*/
 */
@RequestMapping("/error.html")
public String error(HttpServletRequest request, Model model) {
    model.addAttribute("errorCode", "Error " + request.getAttribute("javax.servlet.error.status_code"));
    Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception");
    StringBuilder errorMessage = new StringBuilder();
    errorMessage.append("<ul>");
    while (throwable != null) {
        errorMessage.append("<li>").append(escapeTags(throwable.getMessage())).append("</li>");
        throwable = throwable.getCause();
    }
    errorMessage.append("</ul>");
    model.addAttribute("errorMessage", errorMessage.toString());
    return "error.html";
}