List of usage examples for org.apache.commons.lang3.exception ExceptionUtils getRootCauseStackTrace
public static String[] getRootCauseStackTrace(final Throwable throwable)
Creates a compact stack trace for the root cause of the supplied Throwable
.
The output of this method is consistent across JDK versions.
From source file:io.stallion.monitoring.ExceptionInfo.java
public static ExceptionInfo newForException(Throwable e) { ExceptionInfo info = new ExceptionInfo(); info.thrownAt = utcNow();//from w w w .ja va 2s. c om info.stackTraces = ExceptionUtils.getRootCauseStackTrace(e); if (e instanceof InvocationTargetException) { e = ((InvocationTargetException) e).getTargetException(); } info.className = e.getClass().getSimpleName(); info.message = e.getMessage(); info.requestUrl = request().getRequestUrl(); info.requestUrlWithQuery = request().getRequestUrlWithQuery(); info.requestMethod = request().getMethod(); info.remoteAddr = request().getRemoteAddr(); info.actualIp = request().getActualIp(); info.requestHeaders = map(); for (String name : Collections.list(request().getHeaderNames())) { info.requestHeaders.put(name, request().getHeader(name)); } try { info.setRequestBody(request().getContent()); } catch (RuntimeException e2) { Log.info("Error logging the exception - could not get the request body: {0}", e2); } if (!Context.getUser().isAnon()) { info.setEmail(Context.getUser().getEmail()); info.setUsername(Context.getUser().getUsername()); info.setUserId(Context.getUser().getId()); info.setValetId(Context.getValetUserId()); } return info; }
From source file:de.systemoutprintln.util.logging.spring.LoggingInterceptor.java
/** * Method for logging throwables.//from ww w .j a v a 2s.c o m * * @param method * the method that was invoked. * @param args * the arguments, the method was invoked with. * @param target * the object, on which the method was invoked. * @param throwable * the throwable that was thrown during method invocation. * * @see {@link org.springframework.aop.ThrowsAdvice} */ public void afterThrowing(Method method, Object[] args, Object target, Throwable throwable) { fLog = LoggerFactory.getLogger(target.getClass()); fLog.info("Method invocation resulted in exepction! Method: {} parameters: {} stack trace: {}", ArrayUtils.toArray(method.getName(), args, ExceptionUtils.getRootCauseStackTrace(throwable))); }
From source file:com.cd.reddit.RedditTest.java
private void logRedditException(final Exception e) { final String[] stackMessages = ExceptionUtils.getRootCauseStackTrace(e); if (stackMessages.length == 0) { return;/*from w w w . j ava 2s . co m*/ } for (String message : stackMessages) { Reporter.log(message); } }
From source file:org.eclipse.ebr.maven.BundleMojo.java
private void publishP2Metadata() throws MojoExecutionException { // copy into output directory getLog().debug("Publishing p2 metadata..."); try {/* ww w . ja v a 2 s . c o m*/ // @formatter:off executeMojo( plugin(groupId("org.eclipse.tycho"), artifactId("tycho-p2-plugin"), version(detectPluginVersion( "org.eclipse.tycho", "tycho-p2-plugin", tychoPluginVersionFallback))), goal("p2-metadata"), configuration(element("supportedProjectTypes", element("supportedProjectType", "eclipse-bundle-recipe"))), executionEnvironment(project, session, pluginManager)); // @formatter:on } catch (final MojoExecutionException e) { // check for http://eclip.se/428950 final Throwable rootCause = ExceptionUtils.getRootCause(e); if ((rootCause instanceof IllegalArgumentException) && StringUtils.isBlank(rootCause.getMessage())) { final String[] trace = ExceptionUtils.getRootCauseStackTrace(e); if ((trace.length > 1) && (trace[1].indexOf("P2GeneratorImpl.getCanonicalArtifact") > 0)) { getLog().debug(e); throw new MojoExecutionException( "The generated bundle manifest is broken. Unfortunately, the error is hard to discover (see http://eclip.se/428950). Try running Maven with '-Dosgi.logfile=/tmp/tycho-eclipse.log' to get a log file of the embedded Equinox OSGi framework."); } } throw new MojoExecutionException(format( "Unable to generate p2 metadata. Please check the generated bundle manifest and any bnd instructions. Try running Maven with '-Dosgi.logfile=/tmp/tycho-eclipse.log' to get a log file of the embedded Equinox OSGi framework. %s", e.getMessage()), e); } }
From source file:org.wisdom.monitor.extensions.jcr.script.JcrScriptExecutorExtension.java
private Result executeDirectly(String script) { long migrationTimestamp = System.currentTimeMillis(); Timestamp timestamp = new Timestamp(migrationTimestamp); String workspace = JCR_MIGRATION_PREFIX + new SimpleDateFormat("yyyyMMddHHmmss").format(timestamp); Session originalSession = jcrRepository.getSession(); final ClassLoader original = Thread.currentThread().getContextClassLoader(); try {//from w ww.j av a 2s .com Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); EventJournal journal = originalSession.getWorkspace().getObservationManager().getEventJournal(); ImportCustomizer importCustomizer = new ImportCustomizer(); importCustomizer.addStarImports("javax.jcr"); importCustomizer.addStarImports("javax.jcr.query"); CompilerConfiguration compilerConfiguration = new CompilerConfiguration(); compilerConfiguration.addCompilationCustomizers(importCustomizer); Binding binding = new Binding(); binding.setProperty("session", originalSession); GroovyShell shell = new GroovyShell(binding, compilerConfiguration); long startMigrationTimeMillis = System.currentTimeMillis(); shell.evaluate(script); originalSession = (Session) binding.getProperty("session"); originalSession.save(); List<Event> events = new ArrayList<>(); if (journal != null) { journal.skipTo(startMigrationTimeMillis); journal.forEachRemaining(event -> events.add((Event) event)); } Node systemNode = originalSession.getRootNode(); Node migrationsNode = null; if (systemNode.hasNode("jcr:migrations")) { migrationsNode = systemNode.getNode("jcr:migrations"); } else { migrationsNode = systemNode.addNode("jcr:migrations"); } Node migration = migrationsNode.addNode(workspace); migration.setProperty("executeDate", migrationTimestamp); migration.setProperty("script", script); migration.setProperty("events", listToJsonString(events)); originalSession.save(); if (events.isEmpty()) { throw new Exception("Your script doesn't affect any node."); } return ok(render(scriptTemplate, "workspace", "", "events", new ArrayList<>(), "script", "", "info", "Executed successfully!")); } catch (Exception e) { String[] ss = ExceptionUtils.getRootCauseStackTrace(e); return internalServerError(render(scriptTemplate, "exception", e, "stackTrace", StringUtils.join(ss, "\n"), "workspace", "", "events", new ArrayList(), "script", script)); } finally { Thread.currentThread().setContextClassLoader(original); } }
From source file:org.wisdom.monitor.extensions.jcr.script.JcrScriptExecutorExtension.java
private Result executeScript(String script, String workspace) throws RepositoryException { final ClassLoader original = Thread.currentThread().getContextClassLoader(); Session originalSession = jcrRepository.getSession(); try {// www.j a va2s . c o m Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); originalSession.save(); Session migrationSession = jcrRepository.getRepository().login(workspace); Node migrationNode = migrationSession.getRootNode().getNode("jcr:migrations").getNode(workspace); migrationNode.setProperty("applied", true); originalSession.getWorkspace().clone(workspace, "/", "/", true); originalSession.getWorkspace().deleteWorkspace(workspace); return ok(render(scriptTemplate, "workspace", "", "events", new ArrayList(), "script", "", "info", "Executed successfully!")); } catch (Exception e) { originalSession.getWorkspace().deleteWorkspace(workspace); return internalServerError(render(scriptTemplate, "exception", e, "stackTrace", StringUtils.join(ExceptionUtils.getRootCauseStackTrace(e), "\n"), "workspace", workspace, "events", new ArrayList(), "script", script)); } finally { Thread.currentThread().setContextClassLoader(original); } }
From source file:org.wisdom.monitor.extensions.jcr.script.JcrScriptExecutorExtension.java
private Result preExecuteScript(String script) throws RepositoryException { long migrationTimestamp = System.currentTimeMillis(); Timestamp timestamp = new Timestamp(migrationTimestamp); String workspace = JCR_MIGRATION_PREFIX + new SimpleDateFormat("yyyyMMddHHmmss").format(timestamp); Session originalSession = jcrRepository.getSession(); final ClassLoader original = Thread.currentThread().getContextClassLoader(); try {/*from w ww .ja v a2 s. c om*/ Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); originalSession.getWorkspace().createWorkspace(workspace, originalSession.getWorkspace().getName()); Session session = jcrRepository.getRepository().login(workspace); EventJournal journal = session.getWorkspace().getObservationManager().getEventJournal(); ImportCustomizer importCustomizer = new ImportCustomizer(); importCustomizer.addStarImports("javax.jcr"); importCustomizer.addStarImports("javax.jcr.query"); CompilerConfiguration compilerConfiguration = new CompilerConfiguration(); compilerConfiguration.addCompilationCustomizers(importCustomizer); Binding binding = new Binding(); binding.setProperty("session", session); GroovyShell shell = new GroovyShell(binding, compilerConfiguration); long startMigrationTimeMillis = System.currentTimeMillis(); shell.evaluate(script); session = (Session) binding.getProperty("session"); session.save(); List<Event> events = new ArrayList<>(); if (journal != null) { journal.skipTo(startMigrationTimeMillis); journal.forEachRemaining(event -> events.add((Event) event)); } Node systemNode = session.getRootNode(); Node migrationsNode = null; if (systemNode.hasNode("jcr:migrations")) { migrationsNode = systemNode.getNode("jcr:migrations"); } else { migrationsNode = systemNode.addNode("jcr:migrations"); } Node migration = migrationsNode.addNode(workspace); migration.setProperty("executeDate", migrationTimestamp); migration.setProperty("script", script); migration.setProperty("events", listToJsonString(events)); session.save(); if (events.isEmpty()) { throw new Exception("Your script doesn't affect any node."); } return ok(render(scriptTemplate, "events", events, "workspace", workspace, "eventFormatter", EVENT_FORMATTER, "script", script)); } catch (Exception e) { originalSession.getWorkspace().deleteWorkspace(workspace); String[] ss = ExceptionUtils.getRootCauseStackTrace(e); return internalServerError(render(scriptTemplate, "exception", e, "stackTrace", StringUtils.join(ss, "\n"), "workspace", "", "events", new ArrayList(), "script", script)); } finally { Thread.currentThread().setContextClassLoader(original); } }