List of usage examples for org.apache.commons.lang3.exception ExceptionUtils indexOfThrowable
public static int indexOfThrowable(final Throwable throwable, final Class<?> clazz)
Returns the (zero based) index of the first Throwable
that matches the specified class (exactly) in the exception chain.
From source file:com.haulmont.cuba.web.gui.WebTimer.java
public WebTimer() { component = new Label(); timerImpl = new CubaTimer(); timerImpl.setExceptionHandler(e -> { int reIdx = ExceptionUtils.indexOfType(e, RemoteException.class); if (reIdx > -1) { RemoteException re = (RemoteException) ExceptionUtils.getThrowableList(e).get(reIdx); for (RemoteException.Cause cause : re.getCauses()) { //noinspection ThrowableResultOfMethodCallIgnored if (cause.getThrowable() instanceof NoUserSessionException) { log.warn("NoUserSessionException in timer {}, timer will be stopped", timerImpl.getLoggingTimerId()); stop();//from w ww . jav a2 s. c o m break; } } } else if (ExceptionUtils.indexOfThrowable(e, NoUserSessionException.class) > -1) { log.warn("NoUserSessionException in timer {}, timer will be stopped", timerImpl.getLoggingTimerId()); stop(); } throw new RuntimeException("Exception in timer", e); }); }
From source file:org.apache.carbondata.spark.vectorreader.VectorizedCarbonRecordReader.java
/** * Implementation of RecordReader API.//from w ww . j a v a 2s . c o m */ @Override public void initialize(InputSplit inputSplit, TaskAttemptContext taskAttemptContext) throws IOException, InterruptedException, UnsupportedOperationException { // The input split can contain single HDFS block or multiple blocks, so firstly get all the // blocks and then set them in the query model. List<CarbonInputSplit> splitList; if (inputSplit instanceof CarbonInputSplit) { splitList = new ArrayList<>(1); splitList.add((CarbonInputSplit) inputSplit); } else if (inputSplit instanceof CarbonMultiBlockSplit) { // contains multiple blocks, this is an optimization for concurrent query. CarbonMultiBlockSplit multiBlockSplit = (CarbonMultiBlockSplit) inputSplit; splitList = multiBlockSplit.getAllSplits(); } else { throw new RuntimeException("unsupported input split type: " + inputSplit); } List<TableBlockInfo> tableBlockInfoList = CarbonInputSplit.createBlocks(splitList); queryModel.setTableBlockInfos(tableBlockInfoList); queryModel.setVectorReader(true); try { queryExecutor = QueryExecutorFactory.getQueryExecutor(queryModel, taskAttemptContext.getConfiguration()); iterator = (AbstractDetailQueryResultIterator) queryExecutor.execute(queryModel); } catch (QueryExecutionException e) { if (ExceptionUtils.indexOfThrowable(e, FileNotFoundException.class) > 0) { LOGGER.error(e.getMessage(), e); throw new InterruptedException( "Insert overwrite may be in progress.Please check " + e.getMessage()); } throw new InterruptedException(e.getMessage()); } catch (Exception e) { if (ExceptionUtils.indexOfThrowable(e, FileNotFoundException.class) > 0) { LOGGER.error(e.getMessage(), e); throw new InterruptedException( "Insert overwrite may be in progress.Please check " + e.getMessage()); } throw e; } }
From source file:org.finra.dm.service.helper.DmErrorInformationExceptionHandler.java
/** * Returns {@code true} if the given throwable is or is not caused by a database constraint violation. * * @param exception - throwable to check. * * @return {@code true} if is constraint violation, {@code false} otherwise. *///ww w .j a v a 2 s .c o m private boolean isCausedByConstraintViolationException(Exception exception) { // some databases will throw ConstraintViolationException boolean isConstraintViolation = ExceptionUtils.indexOfThrowable(exception, ConstraintViolationException.class) != -1; // other databases will not throw a nice exception if (!isConstraintViolation) { // We must manually check the error codes Throwable rootThrowable = getRootCause(exception); if (rootThrowable instanceof SQLException) { SQLException sqlException = (SQLException) rootThrowable; isConstraintViolation = POSTGRES_SQL_STATE_CODE_FOREIGN_KEY_VIOLATION .equals(sqlException.getSQLState()); } } return isConstraintViolation; }
From source file:org.finra.dm.service.helper.DmErrorInformationExceptionHandler.java
/** * Handle Activiti exceptions. Note that this method properly handles a null response being passed in. * * @param exception the exception.//from w w w . jav a 2 s .c om * @param response the response. * * @return the error information. */ @ExceptionHandler(value = ActivitiException.class) @ResponseBody public ErrorInformation handleActivitiException(Exception exception, HttpServletResponse response) { if ((ExceptionUtils.indexOfThrowable(exception, ActivitiClassLoadingException.class) != -1) || (ExceptionUtils.indexOfType(exception, ELException.class) != -1)) { // These exceptions are caused by invalid workflow configurations (i.e. user error) so they are considered a bad request. return getErrorInformationAndSetStatus(HttpStatus.BAD_REQUEST, exception, response); } else { // For all other exceptions, something is wrong that we weren't expecting so we'll return this as an internal server error and log the error. logError("An Activiti error occurred.", exception); return getErrorInformationAndSetStatus(HttpStatus.INTERNAL_SERVER_ERROR, exception, response); } }
From source file:org.jasig.ssp.util.importer.job.report.ReportGenerator.java
@SuppressWarnings("unchecked") private String buildReport(JobExecution jobExecution) { StringBuffer emailMessage = new StringBuffer(); String EOL = System.getProperty("line.separator"); SimpleDateFormat dt = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss"); long diff = jobExecution.getEndTime().getTime() - jobExecution.getCreateTime().getTime();//as given emailMessage.append("Start Time: " + dt.format(jobExecution.getCreateTime()) + EOL); emailMessage.append("End Time: " + dt.format(jobExecution.getEndTime()) + EOL); emailMessage.append("Duration: " + DurationFormatUtils.formatDurationWords(diff, true, true) + " (" + DurationFormatUtils.formatDurationHMS(diff) + ")" + EOL); emailMessage.append("Job Id: " + jobExecution.getJobId() + EOL); emailMessage.append("Job Paramters: " + jobExecution.getJobParameters() + EOL); emailMessage.append("Job Status: " + jobExecution.getExitStatus().getExitCode() + EOL); emailMessage.append(EOL).append(EOL); emailMessage.append("Job Details: " + EOL); Map<String, ReportEntry> report = (Map<String, ReportEntry>) jobExecution.getExecutionContext() .get("report"); if (report != null) { Set<Entry<String, ReportEntry>> entrySet = report.entrySet(); for (Entry<String, ReportEntry> entry : entrySet) { emailMessage.append(entry.getValue().toString() + EOL); }/*from w w w . jav a 2s. c o m*/ if (entrySet.size() > 0) emailReport = true; } else { emailMessage.append("NO FILES PROCESSED." + EOL); } emailMessage.append(EOL).append(EOL); emailMessage.append("Errors: " + EOL); List<ErrorEntry> errors = (List<ErrorEntry>) jobExecution.getExecutionContext().get("errors"); List<Throwable> failureExceptions = jobExecution.getAllFailureExceptions(); if (errors != null) { for (ErrorEntry errorEntry : errors) { emailMessage.append(errorEntry.toString() + EOL); emailMessage.append(EOL); } } else if (failureExceptions == null || failureExceptions.size() == 0) { emailMessage.append("No Errors Found." + EOL); } if (failureExceptions != null) { for (Throwable failureException : failureExceptions) { if (ExceptionUtils.indexOfThrowable(failureException, PartialUploadGuardException.class) >= 0 || ExceptionUtils.indexOfThrowable(failureException, BeanCreationException.class) >= 0) { emailReport = true; logger.info("emailReport:" + emailReport); } logger.info("failureException:" + failureException.getClass().getName()); emailMessage.append(failureException.getMessage() + EOL); } } String validations = (String) jobExecution.getExecutionContext().get("databaseValidations"); if (validations != null) { emailMessage.append("Database Validations:" + EOL + validations); } logger.info(emailMessage.toString()); return emailMessage.toString(); }
From source file:org.jasig.ssp.util.importer.job.tasklet.BatchFinalizer.java
@Override public void afterJob(JobExecution jobExecution) { List<Throwable> failureExceptions = jobExecution.getAllFailureExceptions(); if (failureExceptions != null) { for (Throwable failureException : failureExceptions) { if (ExceptionUtils.indexOfThrowable(failureException, JobInterruptedException.class) >= 0) { return; }//from w w w .j av a2s.c o m } } logger.info("Files deleted and archived"); Long diff = TimeUnit.MILLISECONDS .toMinutes(jobExecution.getEndTime().getTime() - jobExecution.getStartTime().getTime()); logger.info("Job Duration in minutes: " + diff.toString()); try { if (!archiveFiles.equals(ArchiveType.NONE)) { try { archive(); } catch (Exception e) { logger.error("Error Archiving. Proceeding with file cleanup anyway.", e); } } // Always want to at least attempt clean up. Else behavior of next upload probably isn't what you expect. cleanDirectoryQuietly(processDirectory.getFile()); cleanDirectoryQuietly(upsertDirectory.getFile()); if (!retainInputFiles) { cleanCsvFilesQuietly(inputDirectory.getFile()); } } catch (Exception e) { logger.error("Error Delete Process, Upsert And Input Directory", e); } }
From source file:uk.q3c.krail.core.shiro.KrailErrorHandler.java
@Override public void error(ErrorEvent event) { Throwable originalError = event.getThrowable(); // handle an attempt to navigate to an invalid page int invalidURI = ExceptionUtils.indexOfThrowable(originalError, InvalidURIException.class); if (invalidURI >= 0) { InvalidURIException e = (InvalidURIException) ExceptionUtils.getThrowables(originalError)[invalidURI]; invalidUriHandler.invoke(e);// w ww.j av a2s.c o m return; } // handle an unauthenticated access attempt int unauthenticated = ExceptionUtils.indexOfThrowable(originalError, UnauthenticatedException.class); if (unauthenticated >= 0) { authenticationHandler.invoke(); return; } // handle an unauthorised access attempt int unauthorised = ExceptionUtils.indexOfThrowable(originalError, UnauthorizedException.class); if (unauthorised >= 0) { authorisationHandler.invoke(); return; } navigator.error(event.getThrowable()); }