/** * Will shut down the server displaying the cause and time of the shutdown * * @param e the exception that caused the shutdown */ public void shutdown(Throwable e) throws MuleException { I18nMessage msg = fatalErrorWhileRunning(); MuleException muleException = getRootMuleException(e); if (muleException != null) { logger.error(muleException.getDetailedMessage()); } else { logger.error(msg.toString() + " " + e.getMessage(), e); } List<String> msgs = new ArrayList<>(); msgs.add(msg.getMessage()); Throwable root = getRootException(e); msgs.add(root.getMessage() + " (" + root.getClass().getName() + ")"); msgs.add(" "); msgs.add(fatalErrorInShutdown().getMessage()); String shutdownMessage = getBoilerPlate(msgs, '*', 80); logger.error(shutdownMessage); doShutdown(); System.exit(1); }
@Test public void nestedExceptionRetrieval() throws Exception { Exception testException = getException(); Throwable t = getRootException(testException); assertNotNull(t); assertThat(t.getMessage(), is("blah")); assertThat(t.getCause(), nullValue()); t = getRootMuleException(testException); assertThat(t.getMessage(), is("bar")); assertThat(t.getCause(), not(nullValue())); List<Throwable> l = getExceptionsAsList(testException); assertThat(l, hasSize(3)); Map<String, Object> info = getExceptionInfo(testException); assertThat(info.entrySet(), hasSize(2)); assertThat(info, hasEntry("info_1", "Imma in!")); assertThat(info, hasEntry("info_2", "Imma out!")); }
/** * Will shut down the server displaying the cause and time of the shutdown * * @param e the exception that caused the shutdown */ public void shutdown(Throwable e) throws MuleException { I18nMessage msg = fatalErrorWhileRunning(); MuleException muleException = getRootMuleException(e); if (muleException != null) { logger.error(muleException.getDetailedMessage()); } else { logger.error(msg.toString() + " " + e.getMessage(), e); } List<String> msgs = new ArrayList<>(); msgs.add(msg.getMessage()); Throwable root = getRootException(e); msgs.add(root.getMessage() + " (" + root.getClass().getName() + ")"); msgs.add(" "); msgs.add(fatalErrorInShutdown().getMessage()); String shutdownMessage = getBoilerPlate(msgs, '*', 80); logger.error(shutdownMessage); doShutdown(); System.exit(1); }
/** * Constructor to create a new builder using the information of an exception for default error parametrization. * * @param e the exception to use from which the error will be created. */ private ErrorBuilder(Throwable e) { if (e instanceof ErrorMessageAwareException) { this.errorMessage = ((ErrorMessageAwareException) e).getErrorMessage(); } if (e instanceof ComposedErrorException) { this.errors = ((ComposedErrorException) e).getErrors(); } this.exception = e; String exceptionDescription = e.getMessage() != null ? e.getMessage() : "unknown description"; this.description = exceptionDescription; this.detailedDescription = exceptionDescription; MuleException muleRoot = getRootMuleException(this.exception); if (muleRoot != null && muleRoot.getMessage() != null) { this.description = muleRoot.getMessage(); } }
protected Pair<MuleException, String> resolveExceptionAndMessageToLog(Throwable t) { MuleException muleException = getRootMuleException(t); String logMessage = null; if (muleException != null) { if (!isVerboseExceptions() && t instanceof EventProcessingException && ((EventProcessingException) t).getEvent().getError() .map(e -> CORE_NAMESPACE_NAME.equals(e.getErrorType().getNamespace()) && UNKNOWN_ERROR_IDENTIFIER.equals(e.getErrorType().getIdentifier())) .orElse(false)) { logMessage = ((MuleException) sanitize(muleException)).getVerboseMessage(); } else { logMessage = muleException.getDetailedMessage(); } } return new Pair<>(muleException, logMessage); }
@Test public void nestedExceptionRetrieval() throws Exception { Exception testException = getException(); Throwable t = getRootException(testException); assertNotNull(t); assertThat(t.getMessage(), is("blah")); assertThat(t.getCause(), nullValue()); t = getRootMuleException(testException); assertThat(t.getMessage(), is("bar")); assertThat(t.getCause(), not(nullValue())); List<Throwable> l = getExceptionsAsList(testException); assertThat(l, hasSize(3)); Map<String, Object> info = getExceptionInfo(testException); assertThat(info.entrySet(), hasSize(2)); assertThat(info, hasEntry("info_1", "Imma in!")); assertThat(info, hasEntry("info_2", "Imma out!")); }