public Throwable getException() { return exchange.getException(); }
protected void doInTransactionWithoutResult(TransactionStatus status) { // wrapper exception to throw if the exchange failed // IMPORTANT: Must be a runtime exception to let Spring regard it as to do "rollback" RuntimeException rce; // and now let process the exchange by the error handler processByErrorHandler(exchange); // after handling and still an exception or marked as rollback only then rollback if (exchange.getException() != null || exchange.isRollbackOnly()) { // wrap exception in transacted exception if (exchange.getException() != null) { rce = ObjectHelper.wrapRuntimeCamelException(exchange.getException()); } else { // create dummy exception to force spring transaction manager to rollback rce = new TransactionRollbackException(); } if (!status.isRollbackOnly()) { status.setRollbackOnly(); } // throw runtime exception to force rollback (which works best to rollback with Spring transaction manager) if (log.isTraceEnabled()) { log.trace("Throwing runtime exception to force transaction to rollback on {}", transactionTemplate.getName()); } throw rce; } } });
Exception cause = exchange.getException(); if (cause != null) { log.debug("Transaction rollback (" + transactionKey + ") redelivered(" + redelivered + ") for "
public void done(boolean doneSync) { if (exchange.getException() != null) { getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException()); } } });
public void done(boolean doneSync) { if (exchange.getException() != null) { getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException()); } } });
@Override public void onFailure(Exchange exchange) { result.setException(exchange.getException(Exception.class)); super.onFailure(exchange); } };
public void done(boolean doneSync) { if (exchange.getException() != null) { getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException()); } } });
private static String failure(Exchange exchange) { if (exchange.isFailed()) { if (exchange.getException() != null) { return getStackTrace(exchange.getException()); } return FORMATTER.format(exchange); } return null; }
private static String failure(Exchange exchange) { if( exchange.isFailed() ) { if( exchange.getException()!=null ) { return toString(exchange.getException()); } return FORMATTER.format(exchange); } return null; }
@Override public void done(boolean doneSync) { if (doneSync) { // verify exchange only if processing is done if (CamelExchange.isFault(exchange) && exchange.getException() != null) { handle(exchange.getException(), exchange); exchange.setException(null); } } callback.done(doneSync); } });
public void notify(EventObject eventObject) throws Exception { if (eventObject instanceof ExchangeFailedEvent) { ExchangeFailedEvent event = (ExchangeFailedEvent) eventObject; String id = event.getExchange().getExchangeId(); Exception cause = event.getExchange().getException(); Date now = new Date(); publisher.publish(appId, id, now, cause.getMessage()); } }
private static void setFailureHandled(Exchange exchange) { exchange.setProperty(Exchange.EXCEPTION_CAUGHT, exchange.getException()); exchange.setProperty(Exchange.ERRORHANDLER_HANDLED, Boolean.TRUE); exchange.setException(null); }
public static Map<?, ?> getItem(CamelContext camelctx) { HashMap<String, AttributeValue> key = new HashMap<>(); key.put("Id", new AttributeValue().withN("103")); Exchange exchange = new ExchangeBuilder(camelctx) .withHeader(DdbConstants.OPERATION, DdbOperations.GetItem) .withHeader(DdbConstants.KEY, key).build(); ProducerTemplate producer = camelctx.createProducerTemplate(); producer.send("direct:start", exchange); Assert.assertNull(exchange.getException()); return exchange.getIn().getHeader(DdbConstants.ATTRIBUTES, Map.class); }
private void setInHeaders(final Exchange exchange) { final Message in = getInMessage(exchange); final String taskId = getExternalTaskId(in); final ExternalTask task = getExternalTask(taskId); final SetExternalTaskRetries annotation = findAnnotationByException(exchange.getException()); final int retries = retriesLeft(task.getRetries(), annotation); final int attemptsStarted = attemptsStarted(task.getRetries(), annotation); in.setHeader(EXCHANGE_HEADER_RETRIESLEFT, retries); in.setHeader(EXCHANGE_HEADER_ATTEMPTSSTARTED, attemptsStarted); }
@Test public void testValidator4() throws InterruptedException, IOException { final String xml = IOUtils.toString(getClass().getResourceAsStream("/xsd/invalidtest.xml"), Charset.defaultCharset()); error.expectedMessageCount(1); Exchange exchange = producerTemplate.send("direct:validator-xml-test", ExchangePattern.InOut, exchange1 -> exchange1.getIn().setBody(xml)); assertEquals(ValidationException.class, exchange.getException() .getClass()); ValidationException e = (ValidationException) exchange.getException(); assertEquals(5, e.getCauses().length); error.assertIsSatisfied(2000); }
public void testError(String endpoint) throws InterruptedException { mockOutput.expectedMessageCount(0); Exchange result = producerTemplate.request(endpoint, exchange -> exchange.getIn().setBody("blah")); assertEquals("failed", result.getException().getMessage()); mockOutput.assertIsSatisfied(); }
@Test public void testExceptionMessage() throws InterruptedException { mockOutput.expectedMessageCount(1); Exchange result = producerTemplate.request("direct:input2", exchange -> exchange.getIn().setBody("blah")); mockOutput.assertIsSatisfied(); Exchange received = mockOutput.getExchanges().get(0); assertEquals("message rejected", result.getException().getMessage()); assertEquals("message rejected", result.getOut().getBody()); assertNull(received.getException()); }
@Test public void testBooleanClosureOneParamInOutFailure() throws InterruptedException { mockOutput.expectedMessageCount(0); Exchange result = producerTemplate.request("direct:input1", exchange -> exchange.getIn().setBody("blub")); assertEquals("validation closure returned false", result.getException().getMessage()); mockOutput.assertIsSatisfied(); }
@Test public void testExceptionClosureOneParamInOutFailure() throws InterruptedException { mockOutput.expectedMessageCount(0); Exchange result = producerTemplate.request("direct:input2", exchange -> exchange.getIn().setBody("blub")); assertEquals("juhu", result.getException().getMessage()); mockOutput.assertIsSatisfied(); }
@Test public void testBooleanClosureOneParamSuccess() throws InterruptedException { mockOutput.expectedBodiesReceived("blah"); Exchange result = producerTemplate.request("direct:input1", exchange -> exchange.getIn().setBody("blah")); assertNull(result.getException()); mockOutput.assertIsSatisfied(); }