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

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

Introduction

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

Prototype

public static String getRootCauseMessage(final Throwable th) 

Source Link

Document

Gets a short message summarising the root cause exception.

Usage

From source file:org.xwiki.extension.repository.internal.core.DefaultCoreExtensionScanner.java

@Override
public void updateExtensions(Collection<DefaultCoreExtension> extensions) {
    for (DefaultCoreExtension extension : extensions) {
        if (!extension.isCached()) {
            try {
                Extension remoteExtension = this.repositoryManager.resolve(extension.getId());

                extension.set(remoteExtension);

                // Cache it
                if (extension.getDescriptorURL() != null) {
                    this.cache.store(extension);
                    extension.setCached(true);
                }//from   w w  w .jav  a2 s. co  m
            } catch (ResolveException e) {
                this.logger.debug("Can't find remote extension with id [{}]", extension.getId(), e);
            } catch (Exception e) {
                this.logger.warn("Failed to update core extension [{}]: [{}]", extension.getId(),
                        ExceptionUtils.getRootCauseMessage(e), e);
            }
        }
    }
}

From source file:org.xwiki.extension.repository.internal.DefaultExtensionRepositoryManager.java

@Override
public Extension resolve(ExtensionDependency extensionDependency) throws ResolveException {
    Set<ExtensionRepositoryDescriptor> checkedRepositories = new HashSet<>();

    Exception lastExtension = null;

    for (ExtensionRepositoryDescriptor repositoryDescriptor : extensionDependency.getRepositories()) {
        if (checkedRepositories.contains(repositoryDescriptor)) {
            continue;
        }/*www .j  a  v  a 2s  .c  o m*/

        // Remember we tried that repository
        checkedRepositories.add(repositoryDescriptor);

        ExtensionRepository repository;
        try {
            repository = getRepository(repositoryDescriptor);
        } catch (ExtensionRepositoryException e) {
            this.logger.warn("Invalid repository [{}] in extension dependency",
                    extensionDependency.getRepositories(), extensionDependency,
                    ExceptionUtils.getRootCauseMessage(e));

            continue;
        }

        try {
            return repository.resolve(extensionDependency);
        } catch (ResolveException e) {
            this.logger.debug("Could not find extension dependency [{}] in repository [{}]",
                    extensionDependency, repository.getDescriptor(), e);

            lastExtension = e;
        }
    }

    for (ExtensionRepository repository : this.repositories) {
        if (checkedRepositories.contains(repository.getDescriptor())) {
            continue;
        }

        // Remember we tried that repository
        checkedRepositories.add(repository.getDescriptor());

        try {
            return repository.resolve(extensionDependency);
        } catch (ResolveException e) {
            this.logger.debug("Could not find extension dependency [{}] in repository [{}]",
                    extensionDependency, repository.getDescriptor(), e);

            lastExtension = e;
        }
    }

    throw new ResolveException(
            MessageFormat.format("Could not find extension dependency [{0}]", extensionDependency),
            lastExtension);
}

From source file:org.xwiki.extension.repository.internal.installed.DefaultInstalledExtensionRepository.java

/**
 * Check extension validity and set it as not installed if not.
 *
 * @param localExtension the extension to validate
 * @throws InvalidExtensionException when the passed extension is fond invalid
 *///from  ww  w  . j av a  2s .  c o m
private void validateExtension(LocalExtension localExtension) {
    Collection<String> namespaces = DefaultInstalledExtension.getNamespaces(localExtension);

    if (namespaces == null) {
        try {
            validateExtension(localExtension, null);
        } catch (InvalidExtensionException e) {
            if (this.logger.isDebugEnabled()) {
                this.logger.warn("Invalid extension [{}]", localExtension.getId(), e);
            } else {
                this.logger.warn("Invalid extension [{}] ({})", localExtension.getId(),
                        ExceptionUtils.getRootCauseMessage(e));
            }

            addInstalledExtension(localExtension, null, false);
        }
    } else {
        for (String namespace : namespaces) {
            try {
                validateExtension(localExtension, namespace);
            } catch (InvalidExtensionException e) {
                if (this.logger.isDebugEnabled()) {
                    this.logger.warn("Invalid extension [{}] on namespace [{}]", localExtension.getId(),
                            namespace, e);
                } else {
                    this.logger.warn("Invalid extension [{}] on namespace [{}] ({})", localExtension.getId(),
                            namespace, ExceptionUtils.getRootCauseMessage(e));
                }

                addInstalledExtension(localExtension, namespace, false);
            }
        }
    }
}

From source file:org.xwiki.extension.xar.internal.job.diff.AbstractUnifiedDiffBuilder.java

private List<UnifiedDiffBlock<String, Character>> createUnifiedDiff(String previous, String next) {
    try {//from  w w  w .  j  av  a2s  .c om
        DiffResult<String> diffResult = this.diffManager.diff(this.lineSplitter.split(previous),
                this.lineSplitter.split(next), null);
        UnifiedDiffConfiguration<String, Character> config = this.unifiedDiffDisplayer
                .getDefaultConfiguration();
        config.setSplitter(this.charSplitter);
        return this.unifiedDiffDisplayer.display(diffResult, config);
    } catch (DiffException e) {
        this.logger.warn("Failed to compute the differences. Root cause: {}",
                ExceptionUtils.getRootCauseMessage(e));
        return Collections.emptyList();
    }
}

From source file:org.xwiki.extension.xar.internal.job.diff.AttachmentUnifiedDiffBuilder.java

private boolean contentEquals(XWikiAttachment previousAttachment, XWikiAttachment nextAttachment) {
    if (previousAttachment == null || nextAttachment == null) {
        return previousAttachment == nextAttachment;
    } else {/* w  ww .  ja v a 2s. c  o  m*/
        XWikiContext xcontext = this.xcontextProvider.get();
        InputStream previousContent = null;
        InputStream nextContent = null;
        try {
            previousContent = previousAttachment.getContentInputStream(xcontext);
            nextContent = nextAttachment.getContentInputStream(xcontext);
            return IOUtils.contentEquals(previousContent, nextContent);
        } catch (Exception e) {
            this.logger.warn("Failed to compare the content of attachment [{}]. Root cause: {}",
                    previousAttachment.getFilename(), ExceptionUtils.getRootCauseMessage(e));
            return false;
        } finally {
            try {
                if (previousContent != null) {
                    previousContent.close();
                }
                if (nextContent != null) {
                    nextContent.close();
                }
            } catch (IOException e) {
                // Ignore.
            }
        }
    }
}

From source file:org.xwiki.extension.xar.internal.job.diff.AttachmentUnifiedDiffBuilder.java

private String getContentAsString(XWikiAttachment attachment) {
    try {/*w  w  w. j  av a 2 s  .  com*/
        return attachment == null ? null
                : IOUtils.toString(attachment.getContentInputStream(this.xcontextProvider.get()));
    } catch (Exception e) {
        this.logger.warn("Failed to read the content of attachment [{}]. Root cause: {}",
                attachment.getFilename(), ExceptionUtils.getRootCauseMessage(e));
        return null;
    }
}

From source file:org.xwiki.filter.xar.internal.input.WikiReader.java

public void read(InputStream stream, Object filter, XARInputFilter proxyFilter) throws IOException {
    ZipArchiveInputStream zis = new ZipArchiveInputStream(stream, "UTF-8", false);

    for (ZipArchiveEntry entry = zis.getNextZipEntry(); entry != null; entry = zis.getNextZipEntry()) {
        if (entry.isDirectory() || entry.getName().startsWith("META-INF")) {
            // The entry is either a directory or is something inside of the META-INF dir.
            // (we use that directory to put meta data such as LICENSE/NOTICE files.)
            continue;
        } else if (entry.getName().equals(XarModel.PATH_PACKAGE)) {
            // The entry is the manifest (package.xml). Read this differently.
            try {
                this.xarPackage.readDescriptor(zis);
            } catch (Exception e) {
                if (this.properties.isVerbose()) {
                    this.logger.warn(LOG_DESCRIPTOR_FAILREAD,
                            "Failed to read XAR descriptor from entry [{}]: {}", entry.getName(),
                            ExceptionUtils.getRootCauseMessage(e));
                }/*w  ww .j  a  v  a  2s  .  c o m*/
            }
        } else {
            try {
                this.documentReader.read(zis, filter, proxyFilter);
            } catch (SkipEntityException skip) {
                if (this.properties.isVerbose()) {
                    this.logger.info(LOG_DOCUMENT_SKIPPED, "Skipped document [{}]", skip.getEntityReference());
                }
            } catch (Exception e) {
                if (this.properties.isVerbose()) {
                    this.logger.warn(LOG_DOCUMENT_FAILREAD,
                            "Failed to read XAR XML document from entry [{}]: {}", entry.getName(),
                            ExceptionUtils.getRootCauseMessage(e), e);
                }
            }
        }
    }
}

From source file:org.xwiki.index.tree.internal.nestedpages.AbstractDocumentTreeNode.java

@Override
public List<String> getChildren(String nodeId, int offset, int limit) {
    EntityReference documentReference = resolve(nodeId);
    if (documentReference != null && documentReference.getType() == EntityType.DOCUMENT) {
        try {//from  w ww.  j av  a2  s .  c  om
            return getChildren(new DocumentReference(documentReference), offset, limit);
        } catch (Exception e) {
            this.logger.warn("Failed to retrieve the children of [{}]. Root cause [{}].", nodeId,
                    ExceptionUtils.getRootCauseMessage(e));
        }
    }
    return Collections.emptyList();
}

From source file:org.xwiki.index.tree.internal.nestedpages.AbstractDocumentTreeNode.java

@Override
public int getChildCount(String nodeId) {
    EntityReference documentReference = resolve(nodeId);
    if (documentReference != null && documentReference.getType() == EntityType.DOCUMENT) {
        try {//from   w w w  . j  a va2s  .  c om
            return getChildCount(new DocumentReference(documentReference));
        } catch (Exception e) {
            this.logger.warn("Failed to count the children of [{}]. Root cause [{}].", nodeId,
                    ExceptionUtils.getRootCauseMessage(e));
        }
    }
    return 0;
}

From source file:org.xwiki.index.tree.internal.nestedpages.AbstractDocumentTreeNode.java

@Override
public String getParent(String nodeId) {
    EntityReference documentReference = resolve(nodeId);
    if (documentReference != null && documentReference.getType() == EntityType.DOCUMENT) {
        try {//from ww w .  j a  va  2s .  co  m
            return serialize(getParent(new DocumentReference(documentReference)));
        } catch (Exception e) {
            this.logger.warn("Failed to retrieve the parent of [{}]. Root cause [{}].", nodeId,
                    ExceptionUtils.getRootCauseMessage(e));
        }
    }
    return null;
}