List of usage examples for org.apache.commons.lang3.exception ExceptionUtils getRootCause
public static Throwable getRootCause(final Throwable throwable)
Introspects the Throwable
to obtain the root cause.
This method walks through the exception chain to the last element, "root" of the tree, using #getCause(Throwable) , and returns that exception.
From version 2.2, this method handles recursive cause structures that might otherwise cause infinite loops.
From source file:gov.anl.aps.cdb.portal.controllers.CdbEntityController.java
/** * Remove current (selected) entity instance from the database and reset * list variables and data model.// w ww .j av a2 s.c o m * * @return URL to entity list page */ public String destroy() { logger.debug("Destroying " + getDisplayEntityTypeName() + " " + getCurrentEntityInstanceName()); try { performDestroyOperations(current); SessionUtility.addInfoMessage("Success", "Deleted " + getDisplayEntityTypeName() + " " + getCurrentEntityInstanceName() + "."); return prepareList(); } catch (CdbException ex) { SessionUtility.addErrorMessage("Error", "Could not delete " + getDisplayEntityTypeName() + ": " + ex.getMessage()); addCdbEntityWarningSystemLog("Failed to delete", ex, current); return null; } catch (RuntimeException ex) { Throwable t = ExceptionUtils.getRootCause(ex); logger.error("Could not delete " + getDisplayEntityTypeName() + " " + getCurrentEntityInstanceName() + ": " + t.getMessage()); SessionUtility.addErrorMessage("Error", "Could not delete " + getDisplayEntityTypeName() + ": " + t.getMessage()); addCdbEntityWarningSystemLog("Failed to delete", ex, current); return null; } }
From source file:com.nbt.TreeFrame.java
public void doExport(final File file) { textFile.setText(file.getAbsolutePath()); Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); setCursor(waitCursor);/*w ww . j a va 2 s .c o m*/ NBTTreeTableModel model = treeTable.getTreeTableModel(); final Object root = model.getRoot(); SwingWorkerUnlimited.execure(new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { if (root instanceof Saveable) { Saveable saveable = (Saveable) root; if (saveable.hasChanged()) saveable.save(); } return null; } @Override protected void done() { Cursor defaultCursor = Cursor.getDefaultCursor(); setCursor(defaultCursor); try { get(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); Throwable cause = ExceptionUtils.getRootCause(e); showErrorDialog(cause.getMessage()); return; } } }); }
From source file:com.thinkbiganalytics.feedmgr.service.template.ExportImportTemplateService.java
/** * Register the template with the metadata and save it * * @param importTemplate the template data to import * @param importOptions user options about what/how it should be imported * @return the registered template that was saved *//* www . j ava 2s .c om*/ private RegisteredTemplate registerTemplate(ImportTemplate importTemplate, ImportTemplateOptions importOptions) { RegisteredTemplate template = importTemplate.getTemplateToImport(); ImportComponentOption registeredTemplateOption = importOptions .findImportComponentOption(ImportComponent.TEMPLATE_DATA); if (registeredTemplateOption.isValidForImport()) { UploadProgressMessage statusMessage = uploadProgressService.addUploadStatus( importOptions.getUploadKey(), "Registering template " + template.getTemplateName() + " with Kylo metadata."); try { importTemplate.setNifiTemplateId(template.getNifiTemplateId()); //register it in the system metadataService.registerTemplate(template); //get the new template template = registeredTemplateService.findRegisteredTemplate(new RegisteredTemplateRequest.Builder() .templateId(template.getId()).templateName(template.getTemplateName()).build()); importTemplate.setTemplateId(template.getId()); statusMessage.update("Registered template with Kylo metadata.", true); } catch (Exception e) { importTemplate.setSuccess(false); Throwable root = ExceptionUtils.getRootCause(e); String msg = root != null ? root.getMessage() : e.getMessage(); importTemplate.getTemplateResults().addError(NifiError.SEVERITY.WARN, "Error registering the template " + template.getTemplateName() + " in the Kylo metadata. " + msg, ""); statusMessage.update("Error registering template with Kylo metadata. " + msg, false); } } return template; }
From source file:com.mirth.connect.cli.CommandLineInterface.java
private void commandExportMessages(Token[] arguments) { if (hasInvalidNumberOfArguments(arguments, 2)) { return;// w w w.j av a 2 s .co m } // file path String path = arguments[1].getText(); File fXml = new File(path); // message filter MessageFilter filter = new MessageFilter(); String channelId = arguments[2].getText(); // export mode ContentType contentType = null; boolean includeAttachments = false; if (arguments.length >= 4) { String modeArg = arguments[3].getText(); if (StringUtils.equals(modeArg, "raw")) { contentType = ContentType.RAW; } else if (StringUtils.equals(modeArg, "processedraw")) { contentType = ContentType.PROCESSED_RAW; } else if (StringUtils.equals(modeArg, "transformed")) { contentType = ContentType.TRANSFORMED; } else if (StringUtils.equals(modeArg, "encoded")) { contentType = ContentType.ENCODED; } else if (StringUtils.equals(modeArg, "sent")) { contentType = ContentType.SENT; } else if (StringUtils.equals(modeArg, "response")) { contentType = ContentType.RESPONSE; } else if (StringUtils.equals(modeArg, "responsetransformed")) { contentType = ContentType.RESPONSE_TRANSFORMED; } else if (StringUtils.equals(modeArg, "processedresponse")) { contentType = ContentType.PROCESSED_RESPONSE; } else if (StringUtils.equals(modeArg, "xml-attach")) { includeAttachments = true; } } // page size int pageSize = 100; if (arguments.length == 5) { pageSize = NumberUtils.toInt(arguments[4].getText()); } int messageCount = 0; try { filter.setMaxMessageId(client.getMaxMessageId(channelId)); MessageWriter messageWriter = null; try { out.println("Exporting messages to file: " + fXml.getPath()); PaginatedMessageList messageList = new PaginatedMessageList(); messageList.setChannelId(channelId); messageList.setClient(client); messageList.setIncludeContent(true); messageList.setMessageFilter(filter); messageList.setPageSize(pageSize); MessageWriterOptions writerOptions = new MessageWriterOptions(); writerOptions.setBaseFolder(new File(".").getPath()); writerOptions.setContentType(contentType); writerOptions.setDestinationContent(false); writerOptions.setEncrypt(false); writerOptions.setRootFolder(FilenameUtils.getFullPath(fXml.getAbsolutePath())); writerOptions.setFilePattern(FilenameUtils.getName(fXml.getAbsolutePath())); writerOptions.setArchiveFormat(null); writerOptions.setCompressFormat(null); writerOptions.setIncludeAttachments(includeAttachments); messageWriter = MessageWriterFactory.getInstance().getMessageWriter(writerOptions, client.getEncryptor()); AttachmentSource attachmentSource = null; if (writerOptions.includeAttachments()) { attachmentSource = new AttachmentSource() { @Override public List<Attachment> getMessageAttachments(Message message) throws ClientException { return client.getAttachmentsByMessageId(message.getChannelId(), message.getMessageId()); } }; } messageCount = new MessageExporter().exportMessages(messageList, messageWriter, attachmentSource); messageWriter.finishWrite(); } catch (Exception e) { Throwable cause = ExceptionUtils.getRootCause(e); error("unable to write file(s) " + path + ": " + cause, cause); } finally { if (messageWriter != null) { try { messageWriter.close(); } catch (Exception e) { Throwable cause = ExceptionUtils.getRootCause(e); error("unable to close file(s) " + path + ": " + cause, cause); } } } } catch (Exception e) { Throwable cause = ExceptionUtils.getRootCause(e); error("Unable to retrieve max message ID: " + cause, cause); } out.println("Messages Export Complete. " + messageCount + " Messages Exported."); }
From source file:no.digipost.api.client.errorhandling.DigipostClientException.java
private static String getMessage(Throwable t) { Throwable rootCause = ExceptionUtils.getRootCause(t); return rootCause != null ? rootCause.getClass().getName() + ": " + rootCause.getMessage() : null; }
From source file:org.activiti.engine.impl.bpmn.behavior.ScriptTaskActivityBehavior.java
public void execute(DelegateExecution execution) { ScriptingEngines scriptingEngines = Context.getProcessEngineConfiguration().getScriptingEngines(); if (Context.getProcessEngineConfiguration().isEnableProcessDefinitionInfoCache()) { ObjectNode taskElementProperties = Context.getBpmnOverrideElementProperties(scriptTaskId, execution.getProcessDefinitionId()); if (taskElementProperties != null && taskElementProperties.has(DynamicBpmnConstants.SCRIPT_TASK_SCRIPT)) { String overrideScript = taskElementProperties.get(DynamicBpmnConstants.SCRIPT_TASK_SCRIPT).asText(); if (StringUtils.isNotEmpty(overrideScript) && overrideScript.equals(script) == false) { script = overrideScript; }/*from w w w . ja v a 2s . c o m*/ } } boolean noErrors = true; try { Object result = scriptingEngines.evaluate(script, language, execution, storeScriptVariables); if (resultVariable != null) { execution.setVariable(resultVariable, result); } } catch (ActivitiException e) { LOGGER.warn("Exception while executing " + execution.getCurrentFlowElement().getId() + " : " + e.getMessage()); noErrors = false; Throwable rootCause = ExceptionUtils.getRootCause(e); if (rootCause instanceof BpmnError) { ErrorPropagation.propagateError((BpmnError) rootCause, execution); } else { throw e; } } if (noErrors) { leave(execution); } }
From source file:org.activiti.scripting.secure.behavior.SecureJavascriptTaskActivityBehavior.java
@Override public void execute(ActivityExecution execution) throws Exception { ProcessEngineConfigurationImpl config = (ProcessEngineConfigurationImpl) execution.getEngineServices() .getProcessEngineConfiguration(); if (Context.getProcessEngineConfiguration().isEnableProcessDefinitionInfoCache()) { ObjectNode taskElementProperties = Context.getBpmnOverrideElementProperties(scriptTaskId, execution.getProcessDefinitionId()); if (taskElementProperties != null && taskElementProperties.has(DynamicBpmnConstants.SCRIPT_TASK_SCRIPT)) { String overrideScript = taskElementProperties.get(DynamicBpmnConstants.SCRIPT_TASK_SCRIPT).asText(); if (StringUtils.isNotEmpty(overrideScript) && overrideScript.equals(script) == false) { script = overrideScript; }/* ww w .j a v a 2 s . c om*/ } } boolean noErrors = true; try { Object result = SecureJavascriptUtil.evaluateScript(execution, script, config.getBeans()); if (resultVariable != null) { execution.setVariable(resultVariable, result); } } catch (ActivitiException e) { LOGGER.warn("Exception while executing " + execution.getActivity().getId() + " : " + e.getMessage()); noErrors = false; Throwable rootCause = ExceptionUtils.getRootCause(e); if (rootCause instanceof BpmnError) { ErrorPropagation.propagateError((BpmnError) rootCause, execution); } else { throw e; } } if (noErrors) { leave(execution); } }
From source file:org.activiti5.engine.impl.bpmn.behavior.ScriptTaskActivityBehavior.java
public void execute(DelegateExecution execution) { ActivityExecution activityExecution = (ActivityExecution) execution; ScriptingEngines scriptingEngines = Context.getProcessEngineConfiguration().getScriptingEngines(); if (Context.getProcessEngineConfiguration().isEnableProcessDefinitionInfoCache()) { ObjectNode taskElementProperties = Context.getBpmnOverrideElementProperties(scriptTaskId, execution.getProcessDefinitionId()); if (taskElementProperties != null && taskElementProperties.has(DynamicBpmnConstants.SCRIPT_TASK_SCRIPT)) { String overrideScript = taskElementProperties.get(DynamicBpmnConstants.SCRIPT_TASK_SCRIPT).asText(); if (StringUtils.isNotEmpty(overrideScript) && overrideScript.equals(script) == false) { script = overrideScript; }//from www . j a v a 2 s . c om } } boolean noErrors = true; try { Object result = scriptingEngines.evaluate(script, language, execution, storeScriptVariables); if (resultVariable != null) { execution.setVariable(resultVariable, result); } } catch (ActivitiException e) { LOGGER.warn("Exception while executing " + activityExecution.getActivity().getId() + " : " + e.getMessage()); noErrors = false; Throwable rootCause = ExceptionUtils.getRootCause(e); if (rootCause instanceof BpmnError) { ErrorPropagation.propagateError((BpmnError) rootCause, activityExecution); } else { throw e; } } if (noErrors) { leave(activityExecution); } }
From source file:org.alfresco.bm.api.AbstractRestResource.java
/** * @throws WebApplicationException with the given status and wrapping the exception stack *//*from w w w .j a va 2s. c om*/ protected void throwAndLogException(Status status, Exception e) { Throwable cause = ExceptionUtils.getRootCause(e); // Handle any well-known exceptions if (e instanceof NotFoundException || (cause != null && cause instanceof NotFoundException)) { status = Status.NOT_FOUND; } // Only log locally if it's an internal server error switch (status) { case INTERNAL_SERVER_ERROR: logger.error(e); break; default: logger.info(e); } throw new WebApplicationException(e, status); }
From source file:org.alfresco.bm.test.TestRunServicesCache.java
/** * Create an application context holding the services for the given test run */// ww w. j a va2s. c om private ClassPathXmlApplicationContext createContext(String test, String run) { String testRunFqn = test + "." + run; DBObject runObj; try { runObj = dao.getTestRun(test, run, true); } catch (ObjectNotFoundException e1) { logger.error("Test '" + test + "." + run + "' not found.", e1); return null; } // Dig the properties out of the test run Properties testRunProps = new Properties(); { testRunProps.put(PROP_TEST_RUN_FQN, testRunFqn); BasicDBList propObjs = (BasicDBList) runObj.get(FIELD_PROPERTIES); for (Object obj : propObjs) { DBObject propObj = (DBObject) obj; String propName = (String) propObj.get(FIELD_NAME); String propDef = (String) propObj.get(FIELD_DEFAULT); String propValue = (String) propObj.get(FIELD_VALUE); if (propValue == null) { propValue = propDef; } testRunProps.put(propName, propValue); } } // Construct the properties ClassPathXmlApplicationContext testRunCtx = new ClassPathXmlApplicationContext( new String[] { PATH_TEST_SERVICES_CONTEXT }, false); ConfigurableEnvironment ctxEnv = testRunCtx.getEnvironment(); ctxEnv.getPropertySources().addFirst(new PropertiesPropertySource("run-props", testRunProps)); // Bind to shutdown testRunCtx.registerShutdownHook(); // Attempt to start the context try { testRunCtx.refresh(); testRunCtx.start(); // Make sure that the required components are present testRunCtx.getBean(EventService.class); testRunCtx.getBean(ResultService.class); testRunCtx.getBean(SessionService.class); } catch (Exception e) { Throwable root = ExceptionUtils.getRootCause(e); if (root != null && root instanceof MongoSocketException) { // We deal with this specifically as it's a simple case of not finding the MongoDB logger.error("Failed to start test run services context '" + testRunFqn + "': " + e.getCause().getMessage()); logger.error( "Set the test run property '" + PROP_MONGO_TEST_HOST + "' (<server>:<port>) as required."); } else if (root != null && root instanceof UnknownHostException) { // We deal with this specifically as it's a simple case of not finding the MongoDB logger.error("Failed to start test run services context '" + testRunFqn + "': " + e.getCause().getCause().getMessage()); logger.error( "Set the test run property '" + PROP_MONGO_TEST_HOST + "' (<server>:<port>) as required."); } else { logger.error("Failed to start test run services context '" + testRunFqn + "': ", e); } testRunCtx = null; } // Done if (testRunCtx == null) { logger.warn("Failed to start test run services context: " + testRunFqn); } else if (logger.isDebugEnabled()) { logger.debug("Started test run services context: " + testRunFqn); } return testRunCtx; }