Java Code Examples for org.apache.commons.lang.exception.ExceptionUtils#getRootCause()
The following examples show how to use
org.apache.commons.lang.exception.ExceptionUtils#getRootCause() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NettyClientBase.java From tajo with Apache License 2.0 | 6 votes |
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { Throwable rootCause = ExceptionUtils.getRootCause(cause); LOG.error(getErrorMessage(ExceptionUtils.getMessage(rootCause)), rootCause); if (cause instanceof RecoverableException) { sendException((RecoverableException) cause); } else { /* unrecoverable fatal error*/ sendExceptions(ExceptionUtils.getMessage(rootCause)); if (ctx.channel().isOpen()) { ctx.close(); } } }
Example 2
Source File: PoseidonJMXInvoker.java From Poseidon with Apache License 2.0 | 6 votes |
public static void main(String[] args) { if (args.length < 3) { System.err.println(PoseidonJMXInvoker.class.getSimpleName() + " <host> <port> <operation>"); System.exit(-1); } 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); }
Example 3
Source File: MarvelGraphFactory.java From dynamodb-janusgraph-storage-backend with Apache License 2.0 | 6 votes |
@Override public void run() { try { final long start = System.currentTimeMillis(); process(graph, appeared); final long end = System.currentTimeMillis(); final long time = end - start; REGISTRY.timer(TIMER_LINE).update(time, TimeUnit.MILLISECONDS); } catch (Throwable e) { final Throwable rootCause = ExceptionUtils.getRootCause(e); final String rootCauseMessage = Optional.ofNullable(rootCause.getMessage()).orElse(""); log.error("Error processing line {} {}", e.getMessage(), rootCauseMessage, e); } finally { COMPLETED_TASK_COUNT.incrementAndGet(); } }
Example 4
Source File: RollbackTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Test public void testTransactedRollback() throws InterruptedException { String message = "this message will explode"; assertEquals(0, auditLogDao.getAuditCount(message)); MockEndpoint mockCompleted = getMockEndpoint("mock:out"); mockCompleted.setExpectedMessageCount(0); try { template.sendBody("direct:transacted", message); fail(); } catch (CamelExecutionException cee) { Throwable rootCause = ExceptionUtils.getRootCause(cee); assertTrue(rootCause instanceof org.apache.camel.RollbackExchangeException); assertTrue(rootCause.getMessage().startsWith("Message contained word 'explode'")); } assertMockEndpointsSatisfied(); assertEquals(0, auditLogDao.getAuditCount(message)); // the insert was rolled back }
Example 5
Source File: KSBClientProxy.java From rice with Educational Community License v2.0 | 6 votes |
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { //using DCL idiom //see effective java 2nd ed. pg. 71 Object s = service; if (s == null) { synchronized (this) { s = service; if (s == null) { service = s = GlobalResourceLoader.getService(serviceName); } } } if (s != null) { try { return method.invoke(s, args); } catch (InvocationTargetException e) { throw ExceptionUtils.getRootCause(e); } } LOG.warn("serviceName: " + serviceName + " was not found"); return null; }
Example 6
Source File: NoRetryInvokeStrategy.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
public GenericResponse invoke(GenericRequest genericRequest) throws TechnicalConnectorException { try { return super.call(genericRequest); } catch (RetryNextEndpointException var4) { Throwable reason = ExceptionUtils.getRootCause(var4); LOG.error("Cannot send SOAP message. Reason [" + reason + "]", var4); throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_WS, var4, new Object[]{reason}); } }
Example 7
Source File: AbstractWsSender.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
private static TechnicalConnectorException translate(Exception e) { if (e instanceof SOAPException) { return new RetryNextEndpointException(e); } else { Throwable reason = ExceptionUtils.getRootCause(e); LOG.error("Cannot send SOAP message. Reason [" + reason + "]", e); return new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_WS, e, new Object[]{reason}); } }
Example 8
Source File: RetryingSolrServer.java From kite with Apache License 2.0 | 5 votes |
private Throwable getRootCause(Throwable throwable) { Throwable rootCause = ExceptionUtils.getRootCause(throwable); if (rootCause != null) { return rootCause; } else { return throwable; } }
Example 9
Source File: NoRetryInvokeStrategy.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
public boolean invoke(InvokeStrategyContext ctx) { try { ctx.setResponse(super.call(ctx.getRequest())); return true; } catch (TechnicalConnectorException var4) { Throwable reason = ExceptionUtils.getRootCause(var4); LOG.error("Cannot send SOAP message. Reason [" + reason + "]", var4); ctx.setException(new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_WS, ExceptionUtils.getRootCause(var4), new Object[]{ExceptionUtils.getRootCauseMessage(var4)})); return false; } }
Example 10
Source File: GlobalTask.java From canal-elasticsearch with Apache License 2.0 | 5 votes |
protected boolean isInterrupt(Throwable e) { if (!running) { return true; } if (ExceptionUtils.getRootCause(e) instanceof InterruptedException) { return true; } return false; }
Example 11
Source File: SwarmDeploymentExceptionTransformer.java From thorntail with Apache License 2.0 | 5 votes |
public Throwable transform(Throwable throwable) { // Arquillian sometimes returns InvocationException with nested // exception and sometimes exception itself @SuppressWarnings("unchecked") List<Throwable> throwableList = ExceptionUtils.getThrowableList(throwable); if (throwableList.isEmpty()) return throwable; Throwable root = null; if (throwableList.size() == 1) { root = throwable; } else { root = ExceptionUtils.getRootCause(throwable); } if (root instanceof DeploymentException || root instanceof DefinitionException) { return root; } if (isFragmentFound(DEPLOYMENT_EXCEPTION_FRAGMENTS, root)) { return new DeploymentException(root.getMessage()); } if (isFragmentFound(DEFINITION_EXCEPTION_FRAGMENTS, root)) { return new DefinitionException(root.getMessage()); } return throwable; }
Example 12
Source File: NoRetryInvokeStrategy.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
public boolean invoke(InvokeStrategyContext ctx) { try { ctx.setResponse(super.call(ctx.getRequest())); return true; } catch (TechnicalConnectorException var4) { Throwable reason = ExceptionUtils.getRootCause(var4); LOG.error("Cannot send SOAP message. Reason [" + reason + "]", var4); ctx.setException(new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_WS, ExceptionUtils.getRootCause(var4), new Object[]{ExceptionUtils.getRootCauseMessage(var4)})); return false; } }
Example 13
Source File: CleanupServiceImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
protected Long deleteByPolicy(final Repository repository, final CleanupPolicy policy, final BooleanSupplier cancelledCheck) { log.info("Deleting components in repository {} using policy {}", repository.getName(), policy.getName()); DeletionProgress deletionProgress = new DeletionProgress(cleanupRetryLimit); if (!policy.getCriteria().isEmpty()) { do { try { Iterable<EntityId> componentsToDelete = browseService.browse(policy, repository); DeletionProgress currentProgress = cleanupMethod.run(repository, componentsToDelete, cancelledCheck); deletionProgress.update(currentProgress); } catch (Exception e) { deletionProgress.setFailed(true); if (ExceptionUtils.getRootCause(e) instanceof SearchContextMissingException) { log.warn("Search scroll timed out, continuing with new scrollId.", log.isDebugEnabled() ? e : null); deletionProgress.setAttempts(0); } else { log.error("Failed to delete components.", e); } } } while (!deletionProgress.isFinished()); if (deletionProgress.isFailed()) { log.warn("Deletion attempts exceeded for repository {}", repository.getName()); } return deletionProgress.getCount(); } else { log.info("Policy {} has no criteria and will therefore be ignored (i.e. no components will be deleted)", policy.getName()); return 0L; } }
Example 14
Source File: AbstractWsSender.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
private static TechnicalConnectorException translate(Exception e) { if (e instanceof SOAPException) { return new RetryNextEndpointException(e); } else if (e instanceof TechnicalConnectorException) { return (TechnicalConnectorException)e; } else { Throwable reason = ExceptionUtils.getRootCause(e); LOG.error("Cannot send SOAP message. Reason [" + reason + "]", e); return new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_WS, reason, new Object[]{"Cannot send SOAP message"}); } }
Example 15
Source File: AbstractElasticsearchBackend.java From heroic with Apache License 2.0 | 5 votes |
protected <T> Transform<Throwable, T> handleVersionConflict( Provider<T> emptyProvider, Runnable reportWriteDroppedByDuplicate ) { return throwable -> { if (ExceptionUtils.getRootCause(throwable) instanceof VersionConflictEngineException) { // Index request rejected, document already exists. That's ok, return success. reportWriteDroppedByDuplicate.run(); return emptyProvider.get(); } throw new RuntimeException(throwable); }; }
Example 16
Source File: NoRetryInvokeStrategy.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
public boolean invoke(InvokeStrategyContext ctx) { try { ctx.setResponse(super.call(ctx.getRequest())); return true; } catch (TechnicalConnectorException var4) { Throwable reason = ExceptionUtils.getRootCause(var4); LOG.error("Cannot send SOAP message. Reason [" + reason + "]", var4); ctx.setException(new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_WS, ExceptionUtils.getRootCause(var4), new Object[]{ExceptionUtils.getRootCauseMessage(var4)})); return false; } }
Example 17
Source File: RetryStrategy.java From freehealth-connector with GNU Affero General Public License v3.0 | 4 votes |
public GenericResponse invoke(GenericRequest genericRequest) throws TechnicalConnectorException { RetryStrategy.RetryContext ctx = new RetryStrategy.RetryContext(this.getCurrentEndpoint(genericRequest)); int alternatives = distributor.getAmountOfAlternatives(ctx.endpoint); for(int i = 0; i < alternatives; ++i) { String activeEndpoint = distributor.getActiveEndpoint(ctx.endpoint); if (!ctx.invokedEndpoints.contains(activeEndpoint)) { ctx.invokedEndpoints.add(activeEndpoint); genericRequest.setEndpoint(activeEndpoint); try { GenericResponse resp = super.call(genericRequest); if (ctx.alternativeActivated) { LOG.debug("Activating status page polling!"); distributor.activatePolling(); } return resp; } catch (RetryNextEndpointException var9) { LOG.error("Unable to invoke endpoint [{}], activating next one.", activeEndpoint, var9); try { distributor.activateNextEndPoint(activeEndpoint); ctx.alternativeActivated = true; } catch (NoNextEndpointException var8) { LOG.error("Unable to activate alternative", var8); } ctx.lastException = var9; } } else { LOG.debug("Endpoint [{}] already invoked, skipping it.", activeEndpoint); } } if (EndpointDistributor.update()) { return this.invoke(genericRequest); } else { throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_WS, ExceptionUtils.getRootCause(ctx.lastException), new Object[]{ExceptionUtils.getRootCauseMessage(ctx.lastException)}); } }
Example 18
Source File: RetryStrategy.java From freehealth-connector with GNU Affero General Public License v3.0 | 4 votes |
public GenericResponse invoke(GenericRequest genericRequest) throws TechnicalConnectorException { RetryStrategy.RetryContext ctx = new RetryStrategy.RetryContext(this.getCurrentEndpoint(genericRequest)); int alternatives = distributor.getAmountOfAlternatives(ctx.endpoint); for(int i = 0; i < alternatives; ++i) { String activeEndpoint = distributor.getActiveEndpoint(ctx.endpoint); if (!ctx.invokedEndpoints.contains(activeEndpoint)) { ctx.invokedEndpoints.add(activeEndpoint); genericRequest.setEndpoint(activeEndpoint); try { GenericResponse resp = super.call(genericRequest); if (ctx.alternativeActivated) { LOG.debug("Activating status page polling!"); distributor.activatePolling(); } return resp; } catch (RetryNextEndpointException var9) { LOG.error("Unable to invoke endpoint [{}], activating next one.", activeEndpoint, var9); try { distributor.activateNextEndPoint(activeEndpoint); ctx.alternativeActivated = true; } catch (NoNextEndpointException var8) { LOG.error("Unable to activate alternative", var8); } ctx.lastException = var9; } } else { LOG.debug("Endpoint [{}] already invoked, skipping it.", activeEndpoint); } } if (EndpointDistributor.update()) { return this.invoke(genericRequest); } else { throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_WS, ExceptionUtils.getRootCause(ctx.lastException), new Object[]{ExceptionUtils.getRootCauseMessage(ctx.lastException)}); } }
Example 19
Source File: ExceptionUtils.java From astor with GNU General Public License v2.0 | 2 votes |
/** * Gets a short message summarising the root cause exception. * <p> * The message returned is of the form * {ClassNameWithoutPackage}: {ThrowableMessage} * * @param th the throwable to get a message for, null returns empty string * @return the message, non-null * @since Commons Lang 2.2 */ public static String getRootCauseMessage(Throwable th) { Throwable root = ExceptionUtils.getRootCause(th); root = (root == null ? th : root); return getMessage(root); }
Example 20
Source File: ExceptionUtils.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Gets a short message summarising the root cause exception. * <p> * The message returned is of the form * {ClassNameWithoutPackage}: {ThrowableMessage} * * @param th the throwable to get a message for, null returns empty string * @return the message, non-null * @since Commons Lang 2.2 */ public static String getRootCauseMessage(Throwable th) { Throwable root = ExceptionUtils.getRootCause(th); root = (root == null ? th : root); return getMessage(root); }