org.apache.camel.CamelExecutionException Java Examples
The following examples show how to use
org.apache.camel.CamelExecutionException.
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: SplitterStopOnExceptionABCTest.java From camelinaction2 with Apache License 2.0 | 7 votes |
@Test public void testSplitStopOnException() throws Exception { MockEndpoint split = getMockEndpoint("mock:split"); // we expect 1 messages to be split since the 2nd message should fail split.expectedBodiesReceived("Camel rocks"); // and no combined aggregated message since we stop on exception MockEndpoint result = getMockEndpoint("mock:result"); result.expectedMessageCount(0); // now send a message with an unknown letter (F) which forces an exception to occur try { template.sendBody("direct:start", "A,F,C"); fail("Should have thrown an exception"); } catch (CamelExecutionException e) { CamelExchangeException cause = assertIsInstanceOf(CamelExchangeException.class, e.getCause()); IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, cause.getCause()); assertEquals("Key not a known word F", iae.getMessage()); } assertMockEndpointsSatisfied(); }
Example #2
Source File: SplitterStopOnExceptionABCTest.java From camelinaction with Apache License 2.0 | 7 votes |
@Test public void testSplitStopOnException() throws Exception { MockEndpoint split = getMockEndpoint("mock:split"); // we expect 1 messages to be split since the 2nd message should fail split.expectedBodiesReceived("Camel rocks"); // and no combined aggregated message since we stop on exception MockEndpoint result = getMockEndpoint("mock:result"); result.expectedMessageCount(0); // now send a message with an unknown letter (F) which forces an exception to occur try { template.sendBody("direct:start", "A,F,C"); fail("Should have thrown an exception"); } catch (CamelExecutionException e) { CamelExchangeException cause = assertIsInstanceOf(CamelExchangeException.class, e.getCause()); IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, cause.getCause()); assertEquals("Key not a known word F", iae.getMessage()); } assertMockEndpointsSatisfied(); }
Example #3
Source File: SpringSplitterStopOnExceptionABCTest.java From camelinaction with Apache License 2.0 | 7 votes |
@Test public void testSplitStopOnException() throws Exception { MockEndpoint split = getMockEndpoint("mock:split"); // we expect 1 messages to be split since the 2nd message should fail split.expectedBodiesReceived("Camel rocks"); // and no combined aggregated message since we stop on exception MockEndpoint result = getMockEndpoint("mock:result"); result.expectedMessageCount(0); // now send a message with an unknown letter (F) which forces an exception to occur try { template.sendBody("direct:start", "A,F,C"); fail("Should have thrown an exception"); } catch (CamelExecutionException e) { CamelExchangeException cause = assertIsInstanceOf(CamelExchangeException.class, e.getCause()); IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, cause.getCause()); assertEquals("Key not a known word F", iae.getMessage()); } assertMockEndpointsSatisfied(); }
Example #4
Source File: SplitExceptionHandlingStopOnExceptionSpringTest.java From camel-cookbook-examples with Apache License 2.0 | 7 votes |
@Test public void testNoElementsProcessedAfterException() throws Exception { String[] array = new String[]{"one", "two", "three"}; MockEndpoint mockSplit = getMockEndpoint("mock:split"); mockSplit.expectedMessageCount(1); mockSplit.expectedBodiesReceived("one"); MockEndpoint mockOut = getMockEndpoint("mock:out"); mockOut.expectedMessageCount(0); try { template.sendBody("direct:in", array); fail("Exception not thrown"); } catch (CamelExecutionException ex) { assertTrue(ex.getCause() instanceof CamelExchangeException); log.info(ex.getMessage()); assertMockEndpointsSatisfied(); } }
Example #5
Source File: GoogleMailResource.java From camel-quarkus with Apache License 2.0 | 7 votes |
@Path("/read") @GET @Produces(MediaType.TEXT_PLAIN) public Response readMail(@QueryParam("messageId") String messageId) { Map<String, Object> headers = new HashMap<>(); headers.put("CamelGoogleMail.userId", USER_ID); headers.put("CamelGoogleMail.id", messageId); try { Message response = producerTemplate.requestBodyAndHeaders("google-mail://messages/get", null, headers, Message.class); if (response != null && response.getPayload() != null) { String body = new String(response.getPayload().getBody().decodeData(), StandardCharsets.UTF_8); return Response.ok(body).build(); } else { return Response.status(Response.Status.NOT_FOUND).build(); } } catch (CamelExecutionException e) { Exception exchangeException = e.getExchange().getException(); if (exchangeException != null && exchangeException.getCause() instanceof GoogleJsonResponseException) { GoogleJsonResponseException originalException = (GoogleJsonResponseException) exchangeException.getCause(); return Response.status(originalException.getStatusCode()).build(); } throw e; } }
Example #6
Source File: CafeErrorSpringTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Test public void testInvalidJson() throws Exception { try { String out = fluentTemplate().to("undertow:http://localhost:" + port1 + "/cafe/menu/items/1") .withHeader(Exchange.HTTP_METHOD, "PUT") .withBody("This is not JSON format") .request(String.class); fail("Expected exception to be thrown"); } catch (CamelExecutionException e) { HttpOperationFailedException httpException = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause()); assertEquals(400, httpException.getStatusCode()); assertEquals("text/plain", httpException.getResponseHeaders().get(Exchange.CONTENT_TYPE)); assertEquals("Invalid json data", httpException.getResponseBody()); } }
Example #7
Source File: DatabaseTransactionTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Test public void testTransactedExceptionThrown() throws InterruptedException { String message = "this message will explode"; assertEquals(0, auditLogDao.getAuditCount(message)); MockEndpoint mockCompleted = getMockEndpoint("mock:out"); mockCompleted.setExpectedMessageCount(1); mockCompleted.whenAnyExchangeReceived(new ExceptionThrowingProcessor()); try { template.sendBody("direct:transacted", message); fail(); } catch (CamelExecutionException cee) { assertEquals("boom!", ExceptionUtils.getRootCause(cee).getMessage()); } assertMockEndpointsSatisfied(); assertEquals(0, auditLogDao.getAuditCount(message)); // the insert was rolled back }
Example #8
Source File: IdempotentConsumerInTransactionTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Test public void testWebserviceExceptionRollsBackTransactionAndIdempotentRepository() throws InterruptedException { String message = "this message will be OK"; assertEquals(0, auditLogDao.getAuditCount(message)); MockEndpoint mockCompleted = getMockEndpoint("mock:out"); mockCompleted.setExpectedMessageCount(0); MockEndpoint mockWs = getMockEndpoint("mock:ws"); mockWs.whenAnyExchangeReceived(new ExceptionThrowingProcessor("ws is down")); try { template.sendBodyAndHeader("direct:transacted", message, "messageId", "foo"); fail(); } catch (CamelExecutionException cee) { assertEquals("ws is down", ExceptionUtils.getRootCause(cee).getMessage()); } assertMockEndpointsSatisfied(); assertEquals(0, auditLogDao.getAuditCount(message)); // the insert was successful // the repository has not seen this messageId assertTrue(!idempotentRepository.contains("foo")); }
Example #9
Source File: IdempotentConsumerInTransactionTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Test public void testTransactedExceptionThrown() throws InterruptedException { String message = "this message will explode"; assertEquals(0, auditLogDao.getAuditCount(message)); MockEndpoint mockCompleted = getMockEndpoint("mock:out"); mockCompleted.setExpectedMessageCount(1); mockCompleted.whenAnyExchangeReceived(new ExceptionThrowingProcessor()); try { template.sendBodyAndHeader("direct:transacted", message, "messageId", "foo"); fail(); } catch (CamelExecutionException cee) { assertEquals("boom!", ExceptionUtils.getRootCause(cee).getMessage()); } assertMockEndpointsSatisfied(); assertEquals(0, auditLogDao.getAuditCount(message)); // the insert was rolled back // even though the transaction rolled back, the repository should still contain an entry for this messageId assertTrue(idempotentRepository.contains("foo")); }
Example #10
Source File: IdempotentConsumerInTransactionSpringTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Test public void testTransactedExceptionThrown() throws InterruptedException { AuditLogDao auditLogDao = getMandatoryBean(AuditLogDao.class, "auditLogDao"); String message = "this message will explode"; assertEquals(0, auditLogDao.getAuditCount(message)); MockEndpoint mockCompleted = getMockEndpoint("mock:out"); mockCompleted.setExpectedMessageCount(1); mockCompleted.whenAnyExchangeReceived(new ExceptionThrowingProcessor()); try { template.sendBodyAndHeader("direct:transacted", message, "messageId", "foo"); fail(); } catch (CamelExecutionException cee) { assertEquals("boom!", ExceptionUtils.getRootCause(cee).getMessage()); } assertMockEndpointsSatisfied(); assertEquals(0, auditLogDao.getAuditCount(message)); // the insert was rolled back @SuppressWarnings("unchecked") IdempotentRepository<String> idempotentRepository = getMandatoryBean(IdempotentRepository.class, "jdbcIdempotentRepository"); // even though the transaction rolled back, the repository should still contain an entry for this messageId assertTrue(idempotentRepository.contains("foo")); }
Example #11
Source File: IdempotentConsumerMultipleEndpointsTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Test public void testErrorAfterBlockWillMeanBlockNotReentered() throws InterruptedException { MockEndpoint mockWs = getMockEndpoint("mock:ws"); // the web service should be invoked once only mockWs.setExpectedMessageCount(1); MockEndpoint mockOut = getMockEndpoint("mock:out"); mockOut.whenExchangeReceived(1, new Processor() { @Override public void process(Exchange exchange) throws Exception { throw new IllegalStateException("Out system is down"); } }); mockOut.setExpectedMessageCount(2); try { template.sendBodyAndHeader("direct:in", "Insert", "messageId", 1); fail("No exception thrown"); } catch (CamelExecutionException cee) { assertEquals("Out system is down", cee.getCause().getMessage()); } template.sendBodyAndHeader("direct:in", "Insert", "messageId", 1); // again assertMockEndpointsSatisfied(); }
Example #12
Source File: IdempotentConsumerMultipleEndpointsSpringTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Test public void testErrorAfterBlockWillMeanBlockNotReentered() throws InterruptedException { MockEndpoint mockWs = getMockEndpoint("mock:ws"); // the web service should be invoked once only mockWs.setExpectedMessageCount(1); MockEndpoint mockOut = getMockEndpoint("mock:out"); mockOut.whenExchangeReceived(1, new Processor() { @Override public void process(Exchange exchange) throws Exception { throw new IllegalStateException("Out system is down"); } }); mockOut.setExpectedMessageCount(2); try { template.sendBodyAndHeader("direct:in", "Insert", "messageId", 1); fail("No exception thrown"); } catch (CamelExecutionException cee) { assertEquals("Out system is down", cee.getCause().getMessage()); } template.sendBodyAndHeader("direct:in", "Insert", "messageId", 1); // again assertMockEndpointsSatisfied(); }
Example #13
Source File: IdempotentConsumerMultipleEndpointsSpringTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Test public void testErrorWithinBlockWillEnableBlockReentry() throws InterruptedException { MockEndpoint mockWs = getMockEndpoint("mock:ws"); mockWs.whenExchangeReceived(1, new Processor() { @Override public void process(Exchange exchange) throws Exception { throw new IllegalStateException("System is down"); } }); // the web service should be invoked twice // the IdempotentRepository should remove the fact that it has seen this message before mockWs.setExpectedMessageCount(2); MockEndpoint mockOut = getMockEndpoint("mock:out"); mockOut.setExpectedMessageCount(1); try { template.sendBodyAndHeader("direct:in", "Insert", "messageId", 1); fail("No exception thrown"); } catch (CamelExecutionException cee) { assertEquals("System is down", cee.getCause().getMessage()); } template.sendBodyAndHeader("direct:in", "Insert", "messageId", 1); // again assertMockEndpointsSatisfied(); }
Example #14
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 #15
Source File: FaultSpringTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Test public void testFaultSpring() { TransferRequest request = new TransferRequest(); request.setBank("Bank of Camel"); request.setFrom("Jakub"); request.setTo("Scott"); request.setAmount("1"); TransferResponse response = template.requestBody(String.format("cxf:http://localhost:%d/paymentFaultService?serviceClass=org.camelcookbook.ws.payment_service.Payment", port1), request, TransferResponse.class); assertNotNull(response); assertEquals("OK", response.getReply()); request.setAmount("10000"); try { response = template.requestBody(String.format("cxf:http://localhost:%d/paymentFaultService?serviceClass=org.camelcookbook.ws.payment_service.Payment", port1), request, TransferResponse.class); fail("Request should have failed"); } catch (CamelExecutionException e) { FaultMessage fault = assertIsInstanceOf(FaultMessage.class, e.getCause()); log.info("reason = {}", fault.getMessage()); } }
Example #16
Source File: RollbackSpringTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Test public void testTransactedRollback() throws InterruptedException { AuditLogDao auditLogDao = getMandatoryBean(AuditLogDao.class, "auditLogDao"); 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 #17
Source File: SplitExceptionHandlingTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Test public void testRemainderElementsProcessedOnException() throws Exception { String[] array = new String[]{"one", "two", "three"}; MockEndpoint mockSplit = getMockEndpoint("mock:split"); mockSplit.expectedMessageCount(2); mockSplit.expectedBodiesReceived("two", "three"); MockEndpoint mockOut = getMockEndpoint("mock:out"); mockOut.expectedMessageCount(0); try { template.sendBody("direct:in", array); fail("Exception not thrown"); } catch (CamelExecutionException ex) { assertTrue(ex.getCause() instanceof IllegalStateException); assertMockEndpointsSatisfied(); } }
Example #18
Source File: ProxyCxfSpringTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Test public void testProxyFaultSpring() throws Exception { TransferRequest request = new TransferRequest(); request.setBank("Bank of Camel"); request.setFrom("Jakub"); request.setTo("Scott"); request.setAmount("10000"); // should trigger backend to throw fault context.startRoute("wsBackend"); assertTrue(context.getRouteStatus("wsBackend").isStarted()); try { TransferResponse response = template.requestBody("cxf:http://localhost:" + port1 + "/paymentService?serviceClass=org.camelcookbook.ws.payment_service.Payment", request, TransferResponse.class); fail("Should have failed as backend should throw fault"); } catch (CamelExecutionException e) { FaultMessage fault = assertIsInstanceOf(FaultMessage.class, e.getCause()); log.info(fault.getLocalizedMessage()); } }
Example #19
Source File: ProxyCxfSpringTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Test public void testProxyRedeliverySpring() throws Exception { TransferRequest request = new TransferRequest(); request.setBank("Bank of Camel"); request.setFrom("Jakub"); request.setTo("Scott"); request.setAmount("1"); context.stopRoute("wsBackend"); assertTrue(context.getRouteStatus("wsBackend").isStopped()); try { TransferResponse response = template.requestBody("cxf:http://localhost:" + port1 + "/paymentService?serviceClass=org.camelcookbook.ws.payment_service.Payment", request, TransferResponse.class); fail("Should have failed as backend WS is down"); } catch (CamelExecutionException e) { SoapFault fault = assertIsInstanceOf(SoapFault.class, e.getCause()); log.info(fault.getReason()); } }
Example #20
Source File: ProxyCxfTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Test public void testProxyFault() throws Exception { TransferRequest request = new TransferRequest(); request.setBank("Bank of Camel"); request.setFrom("Jakub"); request.setTo("Scott"); request.setAmount("10000"); // should trigger backend to throw fault context.startRoute("wsBackend"); assertTrue(context.getRouteStatus("wsBackend").isStarted()); try { TransferResponse response = template.requestBody("cxf:http://localhost:" + port1 + "/paymentService?serviceClass=org.camelcookbook.ws.payment_service.Payment", request, TransferResponse.class); fail("Should have failed as backend should throw fault"); } catch (CamelExecutionException e) { FaultMessage fault = assertIsInstanceOf(FaultMessage.class, e.getCause()); log.info(fault.getLocalizedMessage()); } }
Example #21
Source File: ProxyCxfTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Test public void testProxyRedelivery() throws Exception { TransferRequest request = new TransferRequest(); request.setBank("Bank of Camel"); request.setFrom("Jakub"); request.setTo("Scott"); request.setAmount("1"); context.stopRoute("wsBackend"); assertTrue(context.getRouteStatus("wsBackend").isStopped()); try { TransferResponse response = template.requestBody("cxf:http://localhost:" + port1 + "/paymentService?serviceClass=org.camelcookbook.ws.payment_service.Payment", request, TransferResponse.class); fail("Should have failed as backend WS is down"); } catch (CamelExecutionException e) { SoapFault fault = assertIsInstanceOf(SoapFault.class, e.getCause()); log.info(fault.getReason()); } }
Example #22
Source File: SplitExceptionHandlingSpringTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Test public void testRemainderElementsProcessedOnException() throws Exception { String[] array = new String[]{"one", "two", "three"}; MockEndpoint mockSplit = getMockEndpoint("mock:split"); mockSplit.expectedMessageCount(2); mockSplit.expectedBodiesReceived("two", "three"); MockEndpoint mockOut = getMockEndpoint("mock:out"); mockOut.expectedMessageCount(0); try { template.sendBody("direct:in", array); fail("Exception not thrown"); } catch (CamelExecutionException ex) { assertTrue(ex.getCause() instanceof IllegalStateException); assertMockEndpointsSatisfied(); } }
Example #23
Source File: SignaturesSpringTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Test public void testMessageModificationAfterSigning() throws InterruptedException { MockEndpoint mockSigned = getMockEndpoint("mock:signed"); mockSigned.whenAnyExchangeReceived(new Processor() { @Override public void process(Exchange exchange) throws Exception { Message in = exchange.getIn(); in.setBody(in.getBody(String.class) + "modified"); } }); MockEndpoint mockVerified = getMockEndpoint("mock:verified"); mockVerified.setExpectedMessageCount(0); try { template.sendBody("direct:sign", "foo"); fail(); } catch (CamelExecutionException cex) { assertTrue(ExceptionUtils.getRootCause(cex) instanceof SignatureException); assertEquals("SignatureException: Cannot verify signature of exchange", ExceptionUtils.getRootCauseMessage(cex)); } assertMockEndpointsSatisfied(); }
Example #24
Source File: FileRollbackOnCompletionTest.java From camelinaction with Apache License 2.0 | 6 votes |
@Test public void testRollback() throws Exception { try { template.sendBodyAndHeader("direct:confirm", "bumper", "to", "FATAL"); fail("Should have thrown an exception"); } catch (CamelExecutionException e) { assertIsInstanceOf(IllegalArgumentException.class, e.getCause()); assertEquals("Simulated fatal error", e.getCause().getMessage()); } // give time for onCompletion to execute // as its being executed asynchronously in another thread Thread.sleep(1000); File file = new File("target/mail/backup/"); String[] files = file.list(); assertEquals("There should be no files", 0, files.length); }
Example #25
Source File: SpringFileRollbackTest.java From camelinaction with Apache License 2.0 | 6 votes |
@Test public void testRollback() throws Exception { try { template.sendBodyAndHeader("direct:confirm", "bumper", "to", "FATAL"); fail("Should have thrown an exception"); } catch (CamelExecutionException e) { assertIsInstanceOf(IllegalArgumentException.class, e.getCause()); assertEquals("Simulated fatal error", e.getCause().getMessage()); } // give time for onCompletion to execute // as its being executed asynchronously in another thread Thread.sleep(1000); File file = new File("target/mail/backup/"); String[] files = file.list(); assertEquals("There should be no files", 0, files.length); }
Example #26
Source File: FileRollbackTest.java From camelinaction with Apache License 2.0 | 6 votes |
@Test public void testRollback() throws Exception { // simulate a failure try { template.sendBodyAndHeader("direct:confirm", "bumper", "to", "FATAL"); fail("Should have thrown an exception"); } catch (CamelExecutionException e) { assertIsInstanceOf(IllegalArgumentException.class, e.getCause()); assertEquals("Simulated fatal error", e.getCause().getMessage()); } // which should cause no files to be written in the backup folder File file = new File("target/mail/backup/"); String[] files = file.list(); assertEquals("There should be no files", 0, files.length); }
Example #27
Source File: OnExceptionFallbackTest.java From camelinaction with Apache License 2.0 | 6 votes |
/** * This tests shows no match for onException and therefore fallback on the error handler * and by which there are no explicit configured. Therefore default error handler will be * used which by default does NO redelivery attempts. */ @Test public void testOnExceptionFallbackToErrorHandler() throws Exception { context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { context.setTracing(true); onException(IllegalArgumentException.class).maximumRedeliveries(3); from("direct:order") .bean(OrderServiceBean.class, "handleOrder") .bean(OrderServiceBean.class, "saveToDB"); } }); context.start(); try { template.requestBody("direct:order", "Camel in Action"); fail("Should throw an exception"); } catch (CamelExecutionException e) { assertIsInstanceOf(OrderFailedException.class, e.getCause()); assertIsInstanceOf(ConnectException.class, e.getCause().getCause()); } }
Example #28
Source File: OnExceptionTest.java From camelinaction with Apache License 2.0 | 6 votes |
/** * This test shows that a wrapped connection exception in OrderFailedException will still * be triggered by the onException. */ @Test public void testOnExceptionWrappedMatch() throws Exception { context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { context.setTracing(true); onException(OrderFailedException.class).maximumRedeliveries(3); from("direct:order") .bean(OrderServiceBean.class, "handleOrder") .bean(OrderServiceBean.class, "saveToDB"); } }); context.start(); try { template.requestBody("direct:order", "Camel in Action"); fail("Should throw an exception"); } catch (CamelExecutionException e) { assertIsInstanceOf(OrderFailedException.class, e.getCause()); assertIsInstanceOf(ConnectException.class, e.getCause().getCause()); } }
Example #29
Source File: OnExceptionTest.java From camelinaction with Apache License 2.0 | 6 votes |
/** * This test shows that a direct match will of course trigger the onException */ @Test public void testOnExceptionDirectMatch() throws Exception { context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { context.setTracing(true); onException(OrderFailedException.class).maximumRedeliveries(3); from("direct:order") .bean(OrderServiceBean.class, "handleOrder"); } }); context.start(); try { template.requestBody("direct:order", "ActiveMQ in Action"); fail("Should throw an exception"); } catch (CamelExecutionException e) { assertIsInstanceOf(OrderFailedException.class, e.getCause()); } }
Example #30
Source File: FaultTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Test public void testFault() { TransferRequest request = new TransferRequest(); request.setBank("Bank of Camel"); request.setFrom("Jakub"); request.setTo("Scott"); request.setAmount("1"); TransferResponse response = template.requestBody(String.format("cxf:http://localhost:%d/paymentFaultService?serviceClass=org.camelcookbook.ws.payment_service.Payment", port1), request, TransferResponse.class); assertNotNull(response); assertEquals("OK", response.getReply()); request.setAmount("10000"); try { response = template.requestBody(String.format("cxf:http://localhost:%d/paymentFaultService?serviceClass=org.camelcookbook.ws.payment_service.Payment", port1), request, TransferResponse.class); fail("Request should have failed"); } catch (CamelExecutionException e) { FaultMessage fault = assertIsInstanceOf(FaultMessage.class, e.getCause()); log.info("reason = {}", fault.getMessage()); } }