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

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

Introduction

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

Prototype

public static Throwable getRootCause(final Throwable throwable) 

Source Link

Document

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.

Usage

From source file:gov.anl.aps.cdb.portal.controllers.CdbEntityController.java

/**
 * Create new entity instance and return view to the new instance.
 *
 * @param silent determines if a message should be shown at completion to
 * the user.//from ww w  .ja  v  a 2 s. c o m
 * @param skipSystemLog do not list entry in system logs.
 * @return URL to the new entity instance view
 */
public String create(Boolean silent, Boolean skipSystemLog) {
    try {
        performCreateOperations(current, skipSystemLog);
        if (!silent) {
            SessionUtility.addInfoMessage("Success",
                    "Created " + getDisplayEntityTypeName() + " " + getCurrentEntityInstanceName() + ".");
        }
        return view();
    } catch (CdbException ex) {
        logger.error("Could not create " + getDisplayEntityTypeName() + ": " + ex.getMessage());
        if (!silent) {
            SessionUtility.addErrorMessage("Error",
                    "Could not create " + getDisplayEntityTypeName() + ": " + ex.getMessage());
        }
        if (!skipSystemLog) {
            addCdbEntityWarningSystemLog("Failed to create", ex, current);
        }
        return null;
    } catch (RuntimeException ex) {
        Throwable t = ExceptionUtils.getRootCause(ex);
        logger.error("Could not create " + getDisplayEntityTypeName() + ": " + t.getMessage());
        if (!silent) {
            SessionUtility.addErrorMessage("Error",
                    "Could not create " + getDisplayEntityTypeName() + ": " + t.getMessage());
        }
        if (!skipSystemLog) {
            addCdbEntityWarningSystemLog("Failed to create", ex, current);
        }
        return null;
    }
}

From source file:gov.anl.aps.cdb.portal.controllers.CdbEntityController.java

/**
 * Update current entity and save changes in the database.
 *
 * @return URL to current entity instance view page
 *///from  w  w  w.  j av  a2  s.co m
public String update() {
    try {
        performUpdateOperations(current);
        SessionUtility.addInfoMessage("Success",
                "Updated " + getDisplayEntityTypeName() + " " + getCurrentEntityInstanceName() + ".");
        return viewForCurrentEntity();
    } catch (CdbException ex) {
        SessionUtility.addErrorMessage("Error",
                "Could not update " + getDisplayEntityTypeName() + ": " + ex.getMessage());
        addCdbEntityWarningSystemLog("Failed to update", ex, current);
        return null;
    } catch (RuntimeException ex) {
        Throwable t = ExceptionUtils.getRootCause(ex);
        logger.error("Could not update " + getDisplayEntityTypeName() + " " + getCurrentEntityInstanceName()
                + ": " + t.getMessage());
        SessionUtility.addErrorMessage("Error",
                "Could not update " + getDisplayEntityTypeName() + ": " + t.getMessage());
        addCdbEntityWarningSystemLog("Failed to update", ex, current);
        return null;
    }
}

From source file:com.nbt.TreeFrame.java

public void doImportDat(final File file) {
    Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
    setCursor(waitCursor);//w  w w  . j a  v  a 2s  . c om

    SwingWorkerUnlimited.execure(new SwingWorker<CompoundTag, Void>() {

        @Override
        protected CompoundTag doInBackground() throws Exception {
            NBTInputStream ns = null;
            try {
                ns = new NBTInputStream(new FileInputStream(file));
                return (CompoundTag) ns.readTag();
            } finally {
                IOUtils.closeQuietly(ns);
            }
        }

        @Override
        protected void done() {
            CompoundTag tag = null;
            try {
                tag = get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
                Throwable cause = ExceptionUtils.getRootCause(e);
                showErrorDialog(cause.getMessage());
                return;
            }
            textFile.setText(file.getAbsolutePath());

            updateTreeTable(tag);

            Cursor defaultCursor = Cursor.getDefaultCursor();
            setCursor(defaultCursor);
        }

    });
}

From source file:gov.anl.aps.cdb.portal.controllers.CdbEntityController.java

public void performUpdateOperations(EntityType entity) throws CdbException, RuntimeException {
    try {//from  w w w.j  a v  a2  s.c o m
        setCurrent(entity);
        logger.debug("Updating " + getDisplayEntityTypeName() + " " + getCurrentEntityInstanceName());
        prepareEntityUpdate(entity);
        EntityType updatedEntity = getEntityDbFacade().edit(entity);
        addCdbEntitySystemLog(CDB_ENTITY_INFO_LOG_LEVEL, "Updated: " + entity.toString());
        resetListDataModel();
        resetSelectDataModel();
        resetLogText();
        setCurrent(updatedEntity);
        completeEntityUpdate(entity);
        entity.setPersitanceErrorMessage(null);
    } catch (CdbException ex) {
        entity.setPersitanceErrorMessage(ex.getMessage());
        throw ex;
    } catch (RuntimeException ex) {
        Throwable t = ExceptionUtils.getRootCause(ex);
        entity.setPersitanceErrorMessage(t.getMessage());
        throw ex;
    }
}

From source file:com.nbt.TreeFrame.java

public void doImportMCR(final File file) {
    Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
    setCursor(waitCursor);/*from  w  w w .ja v a  2s.  c  om*/

    SwingWorkerUnlimited.execure(new SwingWorker<Region, Void>() {

        @Override
        protected Region doInBackground() throws Exception {
            NBTRegion region = new NBTRegion(file);
            region.getChunks(); // load from disk
            return region;
        }

        @Override
        protected void done() {
            Region region = null;
            try {
                region = get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
                Throwable cause = ExceptionUtils.getRootCause(e);
                showErrorDialog(cause.getMessage());
                return;
            }
            textFile.setText(file.getAbsolutePath());

            updateTreeTable(region);

            Cursor defaultCursor = Cursor.getDefaultCursor();
            setCursor(defaultCursor);
        }

    });
}

From source file:gov.anl.aps.cdb.portal.controllers.CdbEntityController.java

/**
 * Update current entity and save changes in the database.
 *
 * This method is used when changes involve only removing associated objects
 * from the database.//from   w w w.  j  a v a2 s .  c om
 *
 * @return URL to current entity instance view page
 */
public String updateOnRemoval() {
    try {
        logger.debug("Updating " + getDisplayEntityTypeName() + " " + getCurrentEntityInstanceName());
        prepareEntityUpdateOnRemoval(current);
        EntityType updatedEntity = getEntityDbFacade().edit(current);
        SessionUtility.addInfoMessage("Success",
                "Updated " + getDisplayEntityTypeName() + " " + getCurrentEntityInstanceName() + ".");
        resetListDataModel();
        resetSelectDataModel();
        resetLogText();
        current = updatedEntity;
        return view();
    } catch (CdbException ex) {
        SessionUtility.addErrorMessage("Error",
                "Could not update " + getDisplayEntityTypeName() + ": " + ex.getMessage());
        return null;
    } catch (RuntimeException ex) {
        Throwable t = ExceptionUtils.getRootCause(ex);
        logger.error("Could not update " + getDisplayEntityTypeName() + " " + getCurrentEntityInstanceName()
                + ": " + t.getMessage());
        SessionUtility.addErrorMessage("Error",
                "Could not update " + getDisplayEntityTypeName() + ": " + t.getMessage());
        return null;
    }
}

From source file:com.nbt.TreeFrame.java

public void doImportDirectory(final File base) {
    Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
    setCursor(waitCursor);/*from   w  w  w .ja v  a2s  .c om*/

    SwingWorkerUnlimited.execure(new SwingWorker<NBTBranch, Void>() {

        @Override
        protected NBTBranch doInBackground() throws Exception {
            return createBranch(base);
        }

        // TODO: avoid duplicate code in NBTFileBranch#createBranchCache()
        private NBTBranch createBranch(File file) {
            String[] names = file.list();
            if (ArrayUtils.contains(names, WorldDirectory.DIRECTORY_REGION))
                return new NBTWorld(file);
            return new NBTFileBranch(file);
        }

        @Override
        protected void done() {
            NBTBranch branch = null;
            try {
                branch = get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
                Throwable cause = ExceptionUtils.getRootCause(e);
                showErrorDialog(cause.getMessage());
                return;
            }
            textFile.setText(base.getAbsolutePath());

            updateTreeTable(branch);

            Cursor defaultCursor = Cursor.getDefaultCursor();
            setCursor(defaultCursor);
        }

    });
}

From source file:com.thinkbiganalytics.feedmgr.service.template.ExportImportTemplateService.java

private ImportTemplate importTemplate(ImportTemplate importTemplate) throws Exception {
    ImportTemplateOptions importOptions = importTemplate.getImportOptions();

    log.info("Importing Zip file template {}, overwrite: {}, reusableFlow: {}", importTemplate.getFileName(),
            importOptions.isImportAndOverwrite(ImportComponent.TEMPLATE_DATA),
            importOptions.isImport(ImportComponent.REUSABLE_TEMPLATE));
    if (importTemplate.isValid()) {
        // UploadProgressMessage startingStatusMessage = uploadProgressService.addUploadStatus(importOptions.getUploadKey(), "Starting import of the template");
        // startingStatusMessage.complete(true);
        UploadProgressMessage statusMessage = null;

        //Get information about the import

        RegisteredTemplate template = importTemplate.getTemplateToImport();
        //  validateTemplateProperties(template, importTemplate, importOptions);
        //1 ensure this template doesnt already exist
        importTemplate.setTemplateName(template.getTemplateName());

        RegisteredTemplate existingTemplate = registeredTemplateService.findRegisteredTemplate(
                RegisteredTemplateRequest.requestByTemplateName(template.getTemplateName()));
        if (existingTemplate != null) {
            template.setId(existingTemplate.getId());
        } else {//from  w w w .ja v a 2  s  .c  om
            template.setId(null);
        }

        List<ImportTemplate> connectingTemplates = importReusableTemplate(importTemplate, importOptions);
        if (importOptions.findImportComponentOption(ImportComponent.REUSABLE_TEMPLATE).hasErrorMessages()) {
            //return if invalid
            return importTemplate;
        }

        NiFiTemplateImport niFiTemplateImport = importNiFiXmlTemplate(importTemplate, importOptions);

        String oldTemplateXml = niFiTemplateImport.getOldTemplateXml();
        TemplateDTO dto = niFiTemplateImport.getDto();
        template.setNifiTemplateId(dto.getId());
        importTemplate.setNifiTemplateId(dto.getId());
        ImportComponentOption registeredTemplateImport = importOptions
                .findImportComponentOption(ImportComponent.TEMPLATE_DATA);
        if (existingTemplate != null) {
            importTemplate.setTemplateId(existingTemplate.getId());
        }
        if (registeredTemplateImport.isShouldImport() && registeredTemplateImport.isValidForImport()) {

            NifiProcessGroup newTemplateInstance = createTemplateInstance(importTemplate, importOptions);

            if (newTemplateInstance.isSuccess()) {
                importTemplate.setSuccess(true);
                RegisteredTemplate savedTemplate = registerTemplate(importTemplate, importOptions);
                if (savedTemplate != null) {
                    template = savedTemplate;
                }

            }
            if (!importTemplate.isSuccess()) {
                //ROLLBACK.. errrors
                statusMessage = uploadProgressService.addUploadStatus(importOptions.getUploadKey(),
                        "Errors were found registering the template.  Attempting to rollback.");
                rollbackTemplateImportInNifi(importTemplate, dto, oldTemplateXml);
                //also restore existing registered template with metadata
                //restore old registered template
                if (existingTemplate != null) {
                    try {
                        metadataService.registerTemplate(existingTemplate);
                    } catch (Exception e) {
                        Throwable root = ExceptionUtils.getRootCause(e);
                        String msg = root != null ? root.getMessage() : e.getMessage();
                        importTemplate.getTemplateResults()
                                .addError(
                                        NifiError.SEVERITY.WARN, "Error while restoring the template "
                                                + template.getTemplateName() + " in the Kylo metadata. " + msg,
                                        "");
                    }
                }
                statusMessage.update(
                        "Errors were found registering the template.  Rolled back to previous version.", true);
            }

            //remove the temporary Process Group we created
            removeTemporaryProcessGroup(importTemplate);
        } else {
            importTemplate.setSuccess(true);
        }

        //if we also imported the reusable template make sure that is all running properly
        for (ImportTemplate connectingTemplate : connectingTemplates) {
            //enable it
            nifiRestClient.markConnectionPortsAsRunning(
                    connectingTemplate.getTemplateResults().getProcessGroupEntity());
        }

        completeSection(importOptions, ImportSection.Section.IMPORT_REGISTERED_TEMPLATE);

    }

    return importTemplate;
}

From source file:gov.anl.aps.cdb.portal.controllers.CdbEntityController.java

public void performDestroyOperations(EntityType entity) throws CdbException, RuntimeException {
    try {/*from  w  ww. j a  va  2 s .  co  m*/
        if (entity == null) {
            logger.warn("entity item is not set");
            // Do nothing if entity item is not set.
            return;
        } else if (entity.getId() == null) {
            logger.warn("entity item id is null");
            completeEntityDestroy(entity);
            // Do nothing if there is no id.
            return;
        }

        prepareEntityDestroy(entity);
        getEntityDbFacade().remove(entity);
        completeEntityDestroy(entity);
        addCdbEntitySystemLog(CDB_ENTITY_INFO_LOG_LEVEL, "Deleted: " + entity.toString());
        resetListDataModel();
        resetSelectDataModel();
        settingObject.clearListFilters();
    } catch (CdbException ex) {
        entity.setPersitanceErrorMessage(ex.getMessage());
        throw ex;
    } catch (RuntimeException ex) {
        Throwable t = ExceptionUtils.getRootCause(ex);
        entity.setPersitanceErrorMessage(t.getMessage());
        throw ex;
    }
}

From source file:com.nbt.TreeFrame.java

private void createAndShowTileCanvas(World world) {
    String title = world.getName();
    JFrame frame = new JFrame(title);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    this.tileCanvas = new TileCanvas(world) {
        @Override// www  . j  a  va2s. co  m
        protected void blockClicked(final Block block) {
            Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
            setCursor(waitCursor);

            SwingWorkerUnlimited.execure(new SwingWorker<TreePath, Void>() {

                @Override
                protected TreePath doInBackground() throws Exception {
                    WorldBlock b = (WorldBlock) block;
                    NBTChunk chunk = (NBTChunk) b.getChunk();
                    NBTRegion region = (NBTRegion) chunk.getRegion();
                    Tag<?> chunkTag = chunk.getTag();
                    CompoundTag compoundTag = (CompoundTag) chunkTag;
                    Tag<?> level = compoundTag.search("Level");
                    CompoundTag levelTag = (CompoundTag) level;
                    Tag<?> blocks = levelTag.search("Blocks");
                    ByteArrayTag blocksTag = (ByteArrayTag) blocks;
                    int index = b.getIndex();
                    Object child = blocksTag.getChild(index);
                    return treeTable.getPathForNode(region).pathByAddingChild(chunk).pathByAddingChild(level)
                            .pathByAddingChild(blocks).pathByAddingChild(child);
                }

                @Override
                protected void done() {
                    Cursor defaultCursor = Cursor.getDefaultCursor();
                    setCursor(defaultCursor);

                    try {
                        TreePath path = get();
                        selectAndScroll(path);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    } catch (ExecutionException e) {
                        e.printStackTrace();
                        Throwable cause = ExceptionUtils.getRootCause(e);
                        showErrorDialog(cause.getMessage());
                        return;
                    }
                }

            });
        }
    };
    tileCanvas.restore();
    frame.add(tileCanvas);
    frame.pack();
    frame.setVisible(true);
}