List of usage examples for org.apache.commons.lang.exception ExceptionUtils getRootCause
public static Throwable getRootCause(Throwable throwable)
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.
From source file:com.flipkart.poseidon.jmx.PoseidonJMXInvoker.java
public static void main(String[] args) { if (args.length < 3) { System.err.println(PoseidonJMXInvoker.class.getSimpleName() + " <host> <port> <operation>"); System.exit(-1);//from www .j av a 2s .co m } final String CONNECT_STRING = args[0] + ":" + args[1]; final String OPERATION = args[2]; try { System.out.println("Running " + OPERATION + " over JMX on " + CONNECT_STRING); JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + CONNECT_STRING + "/jmxrmi"); MBeanServerConnection connection = JMXConnectorFactory.connect(url).getMBeanServerConnection(); connection.invoke(ObjectName.getInstance(MBEAN_NAME), OPERATION, null, null); } catch (Exception e) { if (!(ExceptionUtils.getRootCause(e) instanceof EOFException && "destroy".equals(OPERATION))) { e.printStackTrace(); System.exit(-1); } } System.out.println(OPERATION + " successful over JMX on " + CONNECT_STRING); }
From source file:com.github.bfour.fpliteraturecollector.application.Application.java
public static void main(String[] args) { try {/*from www .ja v a 2 s . c o m*/ // https://vvirlan.wordpress.com/2014/12/10/solved-caused-by-java-awt-headlessexception-when-trying-to-create-a-swingawt-frame-from-spring-boot/ SpringApplicationBuilder builder = new SpringApplicationBuilder(Application.class); builder.headless(false); ConfigurableApplicationContext context = builder.run(args); // Neo4jResource myBean = context.getBean(Neo4jResource.class); // myBean.functionThatUsesTheRepo(); // ServiceManager servMan = ServiceManager // .getInstance(ServiceManagerMode.TEST); ServiceManager servMan = context.getBean(ServiceManager.class); context.getAutowireCapableBeanFactory().autowireBeanProperties(servMan, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); FPJGUIManager.getInstance().initialize(); MainWindow.getInstance(servMan).setVisible(true); } catch (BeanCreationException e) { e.printStackTrace(); if (ExceptionUtils.getRootCause(e) instanceof IOException) ApplicationErrorDialogue.showMessage("Sorry, could not access the database.\n" + "This might be because it is currently in use or because there are insufficient access rights.\n" + "Try closing all running instances of this application and restart."); else ApplicationErrorDialogue.showDefaultMessage(e, BUG_REPORT_URL); } catch (Exception e) { e.printStackTrace(); ApplicationErrorDialogue.showDefaultMessage(e, BUG_REPORT_URL); } }
From source file:io.jwt.primer.util.PrimerExceptionUtil.java
static void handleException(Exception e) throws PrimerException { if (e instanceof PrimerException) { throw (PrimerException) e; }//from w ww . j av a 2 s .c o m if (ExceptionUtils.getRootCause(e) instanceof PrimerException) { throw (PrimerException) ExceptionUtils.getRootCause(e); } }
From source file:mitm.application.djigzo.ws.WSExceptionUtils.java
public static String getExceptionMessage(Throwable t) { Throwable cause = ExceptionUtils.getRootCause(t); if (cause == null) { cause = t;/* w w w.ja v a2s . c o m*/ } return ExceptionUtils.getRootCauseMessage(t) + ", Class: " + cause.getClass(); }
From source file:fi.ilmoeuro.membertrack.db.DataIntegrityException.java
public static @Nullable DataIntegrityException fromThrowable(Throwable throwable) { Throwable rootCause = ExceptionUtils.getRootCause(throwable); if (rootCause instanceof SQLException) { SQLException sqle = (SQLException) rootCause; String constraint = ""; String message = sqle.getMessage(); if (message != null) { Matcher matcher = CONSTRAINT_REGEX.matcher(message); if (matcher.find()) { String group = matcher.group(1); if (group != null) { constraint = group;/*ww w . j a va 2 s . c om*/ } } } for (IntegrityViolation errorType : IntegrityViolation.values()) { if (errorType.errorCodes.contains(sqle.getSQLState())) { return new DataIntegrityException(errorType, constraint, throwable); } } } return null; }
From source file:com.asual.summer.core.spring.ExtendedBindingErrorProcessor.java
public void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult) { super.processPropertyAccessException(ex, bindingResult); Object[] arguments = bindingResult.getAllErrors().get(bindingResult.getErrorCount() - 1).getArguments(); arguments[1] = ExceptionUtils.getRootCause(ex).getMessage(); }
From source file:mitm.application.djigzo.tools.CertManager.java
public static void main(String[] args) throws Exception { CertManager monitor = new CertManager(); try {/*from w w w. j ava 2s.c om*/ monitor.handleCommandline(args); } catch (CLIRuntimeException e) { System.err.println(e.getMessage()); System.exit(2); } catch (MissingArgumentException e) { System.err.println("Not all required parameters are specified. " + e); System.exit(3); } catch (ParseException e) { System.err.println("Command line parsing error. " + e); System.exit(4); } catch (WebServiceException e) { Throwable cause = ExceptionUtils.getRootCause(e); if (cause instanceof ConnectException) { System.err.println("Unable to connect to backend. Cause: " + cause.getMessage()); } else { e.printStackTrace(); } System.exit(5); } catch (WSProxyFactoryException e) { e.printStackTrace(); System.exit(6); } catch (WebServiceCheckedException e) { e.printStackTrace(); System.exit(7); } catch (Exception e) { e.printStackTrace(); System.exit(8); } }
From source file:com.github.dbourdette.glass.log.joblog.JobLog.java
public static JobLog exception(JobExecution execution, JobLogLevel level, String message, Throwable e) { JobLog jobLog = message(execution, level, message); jobLog.stackTrace = ExceptionUtils.getFullStackTrace(e); jobLog.rootCause = ExceptionUtils.getMessage(ExceptionUtils.getRootCause(e)); if (StringUtils.isEmpty(jobLog.rootCause)) { jobLog.rootCause = ExceptionUtils.getMessage(e); }// w w w . ja v a2 s .co m if (StringUtils.isEmpty(jobLog.rootCause)) { jobLog.rootCause = "no message"; } return jobLog; }
From source file:com.haulmont.cuba.web.exception.DefaultExceptionHandler.java
@Override public boolean handle(ErrorEvent event, App app) { // Copied from com.vaadin.server.DefaultErrorHandler.doDefault() //noinspection ThrowableResultOfMethodCallIgnored Throwable t = event.getThrowable(); //noinspection ThrowableResultOfMethodCallIgnored if (t instanceof SocketException || ExceptionUtils.getRootCause(t) instanceof SocketException) { // Most likely client browser closed socket return true; }/*from www . j ava2 s .c om*/ // Support Tomcat 8 ClientAbortException if (StringUtils.contains(ExceptionUtils.getMessage(t), "ClientAbortException")) { // Most likely client browser closed socket return true; } AppUI ui = AppUI.getCurrent(); if (ui == null) { // there is no UI, just add error to log return true; } if (t != null) { if (app.getConnection().getSession() != null) { showDialog(app, t); } else { showNotification(app, t); } } return true; }
From source file:com.thinkbiganalytics.rest.exception.AccessDeniedExceptionMapper.java
@Override public Response toResponse(MetadataRepositoryException e) { Throwable cause = ExceptionUtils.getRootCause(e); if (cause instanceof AccessDeniedException) { log.debug("Access denied violation", e); RestResponseStatus.ResponseStatusBuilder builder = new RestResponseStatus.ResponseStatusBuilder(); builder.url(req.getRequestURI()); builder.message(cause.getMessage()); return Response.accepted(builder.buildError()).status(Response.Status.FORBIDDEN).build(); } else {/*www . ja v a 2 s.c o m*/ return new ThrowableMapper().toResponse(cause); } }