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.lesscss.LessCompilerScriptService.java

/**
 * Compile a LESS file located in the "less" directory of the current skin directory.
 * Velocity will also be parsed on the file, but not on the files included via the @import directive.
 * The result is cached by XWiki until the skin or the color theme is changed.
 *
 * @param fileName name of the file to compile
 * @param force force the computation, even if the output is already in the cache (not recommended)
 * @return the generated CSS, or an error message if some problem occurs
 */// w ww.java2s.  c  om
public String compileSkinFile(String fileName, boolean force) {
    try {
        return lessCompiler.compile(lessResourceReferenceFactory.createReferenceForSkinFile(fileName), false,
                true, force);
    } catch (LESSCompilerException e) {
        return ExceptionUtils.getRootCauseMessage(e);
    }
}

From source file:org.xwiki.lesscss.LessCompilerScriptService.java

/**
 * Compile a LESS file located in the "less" directory of the specified skin directory.
 * Velocity will also be parsed on the file, but not on the files included via the @import directive.
 * The result is cached by XWiki until the skin or the color theme is changed.
 *
 * @param fileName name of the file to compile
 * @param skin name of the skin where the LESS file is located
 * @param force force the computation, even if the output is already in the cache (not recommended)
 * @return the generated CSS, or an error message if some problem occurs
 *//*w w  w .  ja va  2 s .c  o  m*/
public String compileSkinFile(String fileName, String skin, boolean force) {
    try {
        return lessCompiler.compile(lessResourceReferenceFactory.createReferenceForSkinFile(fileName), false,
                true, skin, force);
    } catch (LESSCompilerException e) {
        return ExceptionUtils.getRootCauseMessage(e);
    }
}

From source file:org.xwiki.mail.internal.AbstractMailStatusResult.java

@Override
public void waitTillProcessed(long timeout) {
    long startTime = System.currentTimeMillis();
    while (!isProcessed() && System.currentTimeMillis() - startTime < timeout) {
        try {//from  ww w.j ava  2 s .c  o  m
            Thread.sleep(100L);
        } catch (InterruptedException e) {
            // Ignore but consider that the mail was sent
            LOGGER.warn("Interrupted while waiting for mails to be sent. Reason [{}]",
                    ExceptionUtils.getRootCauseMessage(e));
            break;
        }
    }
}

From source file:org.xwiki.mail.internal.AttachmentMimeBodyPartFactory.java

private DataSource createTemporaryAttachmentDataSource(Attachment attachment) throws MessagingException {
    File temporaryAttachmentFile;
    FileOutputStream fos = null;/*from   w ww .java2s  .  co  m*/
    try {
        temporaryAttachmentFile = File.createTempFile("attachment", ".tmp", this.temporaryDirectory);
        temporaryAttachmentFile.deleteOnExit();
        fos = new FileOutputStream(temporaryAttachmentFile);
        fos.write(attachment.getContent());
    } catch (Exception e) {
        throw new MessagingException(
                String.format("Failed to save attachment [%s] to the file system", attachment.getFilename()),
                e);
    } finally {
        try {
            if (fos != null) {
                fos.close();
            }
        } catch (IOException e) {
            // Only an error at closing, we continue
            this.logger.warn("Failed to close the temporary file attachment when sending an email. "
                    + "Root reason: [{}]", ExceptionUtils.getRootCauseMessage(e));
        }
    }
    return new FileDataSource(temporaryAttachmentFile);
}

From source file:org.xwiki.mail.internal.DatabaseMailListener.java

private void deleteMailContent(MailStatus currentStatus) {
    if (currentStatus != null) {
        try {//from  ww  w.j  a va 2  s . c  o  m
            mailContentStore.delete(currentStatus.getBatchId(), currentStatus.getMessageId());
        } catch (MailStoreException e) {
            // Failed to delete saved mail, raise a warning but continue since it's not critical
            this.logger.warn(
                    "Failed to remove previously failing message [{}] (batch id [{}]) from the file "
                            + "system. Reason [{}].",
                    currentStatus.getMessageId(), currentStatus.getBatchId(),
                    ExceptionUtils.getRootCauseMessage(e));
        }
    }
}

From source file:org.xwiki.mail.internal.DefaultMailSender.java

@Override
public void waitTillSent(long timeout) {
    long startTime = System.currentTimeMillis();
    while (hasMailQueueItemForCurrentThread() && System.currentTimeMillis() - startTime < timeout) {
        try {/*ww  w. ja  v a 2  s .co  m*/
            Thread.sleep(100L);
        } catch (InterruptedException e) {
            // Ignore but consider that the mail was sent
            this.logger.warn("Interrupted while waiting for mail to be sent. Reason [{}]",
                    ExceptionUtils.getRootCauseMessage(e));
            break;
        }
    }
}

From source file:org.xwiki.mail.internal.MailResenderListener.java

private void resendAllMatching(MailResender resender, Map<String, Object> filterMap) {
    try {// w  w w  .j  av  a2  s . c  o  m
        resender.resendAsynchronously(filterMap, 0, 0);
    } catch (MailStoreException e) {
        // There's an important problem in the mail subsystem but don't stop XWiki since it's important but not
        // vital.
        this.logger.warn("Failed to resend unsent mails at startup for filter [{}]. Root error: [{}]",
                filterMap, ExceptionUtils.getRootCauseMessage(e));
    }
}

From source file:org.xwiki.mail.internal.thread.AbstractMailQueueManager.java

@Override
public void waitTillProcessed(String batchId, long timeout) {
    long startTime = System.currentTimeMillis();
    while (!isProcessed(batchId) && System.currentTimeMillis() - startTime < timeout) {
        try {/*from   www  .  ja  va2s .co  m*/
            Thread.sleep(100L);
        } catch (InterruptedException e) {
            // Ignore but consider that the mail was sent
            this.logger.warn("Interrupted while waiting for mails to be sent. Reason [{}]",
                    ExceptionUtils.getRootCauseMessage(e));
            break;
        }
    }
}

From source file:org.xwiki.mail.MailStatus.java

/**
 * @param exception the exception that was encountered during sending mail
 *///  ww  w  .ja  v a 2 s .  c o m
public void setError(Exception exception) {
    this.errorSummary = ExceptionUtils.getRootCauseMessage(exception);
    this.errorDescription = ExceptionUtils.getStackTrace(exception);
}

From source file:org.xwiki.notifications.filters.internal.DefaultNotificationFilterManager.java

@Override
public void saveFilterPreferences(Set<NotificationFilterPreference> filterPreferences) {
    Map<String, Set<NotificationFilterPreference>> preferencesMapping = new HashMap<>();

    for (NotificationFilterPreference filterPreference : filterPreferences) {
        // Try to get the corresponding provider, if no provider can be found, discard the save of the preference
        String providerHint = filterPreference.getProviderHint();
        if (componentManager.hasComponent(NotificationFilterPreferenceProvider.class, providerHint)) {
            if (!preferencesMapping.containsKey(providerHint)) {
                preferencesMapping.put(providerHint, new HashSet<>());
            }/* w  ww  . j av a 2s  .  c om*/

            preferencesMapping.get(providerHint).add(filterPreference);
        }
    }

    // Once we have created the mapping, save all the preferences using their correct providers
    for (String providerHint : preferencesMapping.keySet()) {
        try {
            NotificationFilterPreferenceProvider provider = componentManager
                    .getInstance(NotificationFilterPreferenceProvider.class, providerHint);

            provider.saveFilterPreferences(preferencesMapping.get(providerHint));

        } catch (ComponentLookupException e) {
            logger.error("Unable to retrieve the notification filter preference provider for hint [{}]: [{}]",
                    providerHint, e);
        } catch (NotificationException e) {
            logger.warn("Unable save the filter preferences [{}] against the provider [{}]: [{}]",
                    preferencesMapping.get(providerHint), providerHint, ExceptionUtils.getRootCauseMessage(e));
        }
    }
}