Java Code Examples for org.apache.camel.CamelExecutionException#getCause()
The following examples show how to use
org.apache.camel.CamelExecutionException#getCause() .
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: DnsIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testDnsProducer() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("dns:lookup"); } }); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); Record[] record = producer.requestBodyAndHeader("direct:start", null, DnsConstants.DNS_NAME, "redhat.com", Record[].class); Assert.assertEquals("redhat.com.", record[0].getName().toString()); Assert.assertEquals(Type.A, record[0].getType()); } catch (CamelExecutionException ex) { Throwable cause = ex.getCause(); Assert.assertEquals("network error", cause.getMessage()); } finally { camelctx.close(); } }
Example 2
Source File: HttpErrorDetailRule.java From syndesis with Apache License 2.0 | 6 votes |
@Override public Statement apply(final Statement base, final Description description) { return new Statement() { @Override public void evaluate() throws Throwable { try { base.evaluate(); } catch (final CamelExecutionException camelError) { final Throwable cause = camelError.getCause(); if (cause instanceof HttpOperationFailedException) { final HttpOperationFailedException httpError = (HttpOperationFailedException) cause; final List<ServeEvent> events = WireMock.getAllServeEvents(); final String message = "Received HTTP status: " + httpError.getStatusCode() + " " + httpError.getStatusText() + "\n\n" + httpError.getResponseBody() + "\nRequests received:\n" + Joiner.on('\n').join(events.stream().map(e -> e.getRequest()).iterator()); throw new AssertionError(message, httpError); } throw camelError; } } }; }
Example 3
Source File: AuthorizationPolicyTestCase.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testInvalidCredentials() throws Exception { CamelContext camelctx = contextRegistry.getCamelContext("contextA"); ProducerTemplate producer = camelctx.createProducerTemplate(); try { Subject subject = getAuthenticationToken("user-domain", AnnotatedSLSB.USERNAME, "bogus"); producer.requestBodyAndHeader("direct:start", "Kermit", Exchange.AUTHENTICATION, subject, String.class); Assert.fail("CamelExecutionException expected"); } catch (CamelExecutionException ex) { Throwable cause = ex.getCause(); Assert.assertEquals(CamelAuthorizationException.class, cause.getClass()); Assert.assertTrue(cause.getMessage(), cause.getMessage().contains("Password invalid/Password required")); } }
Example 4
Source File: SecuredRouteTestCase.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testInsufficientRoles() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .policy(new DomainAuthorizationPolicy().roles("Role3")) .transform(body().prepend("Hello ")); } }); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); try { Subject subject = getAuthenticationToken("user-domain", AnnotatedSLSB.USERNAME, AnnotatedSLSB.PASSWORD); producer.requestBodyAndHeader("direct:start", "Kermit", Exchange.AUTHENTICATION, subject, String.class); Assert.fail("CamelExecutionException expected"); } catch (CamelExecutionException ex) { Throwable cause = ex.getCause(); Assert.assertEquals(LoginException.class, cause.getClass()); Assert.assertTrue(cause.getMessage(), cause.getMessage().contains("User does not have required roles: [Role3]")); } } finally { camelctx.close(); } }
Example 5
Source File: SecuredRouteTestCase.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testInvalidCredentials() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .policy(new DomainAuthorizationPolicy()) .transform(body().prepend("Hello ")); } }); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); try { Subject subject = getAuthenticationToken("user-domain", AnnotatedSLSB.USERNAME, "bogus"); producer.requestBodyAndHeader("direct:start", "Kermit", Exchange.AUTHENTICATION, subject, String.class); Assert.fail("CamelExecutionException expected"); } catch (CamelExecutionException ex) { Throwable cause = ex.getCause(); Assert.assertEquals(FailedLoginException.class, cause.getClass()); Assert.assertTrue(cause.getMessage(), cause.getMessage().contains("Password invalid/Password required")); } } finally { camelctx.close(); } }
Example 6
Source File: SecuredRouteTestCase.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testNoAuthenticationHeader() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .policy(new DomainAuthorizationPolicy()) .transform(body().prepend("Hello ")); } }); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); try { producer.requestBody("direct:start", "Kermit", String.class); Assert.fail("CamelExecutionException expected"); } catch (CamelExecutionException ex) { Throwable cause = ex.getCause(); Assert.assertEquals(SecurityException.class, cause.getClass()); Assert.assertTrue(cause.getMessage(), cause.getMessage().startsWith("Cannot obtain authentication subject")); } } finally { camelctx.close(); } }
Example 7
Source File: SecuredSpringRouteTestCase.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testInsufficientRoles() throws Exception { CamelContext camelctx = contextRegistry.getCamelContext("contextC"); ProducerTemplate producer = camelctx.createProducerTemplate(); try { Subject subject = getAuthenticationToken("user-domain", AnnotatedSLSB.USERNAME, AnnotatedSLSB.PASSWORD); producer.requestBodyAndHeader("direct:start", "Kermit", Exchange.AUTHENTICATION, subject, String.class); Assert.fail("CamelExecutionException expected"); } catch (CamelExecutionException ex) { Throwable cause = ex.getCause(); Assert.assertEquals(LoginException.class, cause.getClass()); Assert.assertTrue(cause.getMessage(), cause.getMessage().contains("User does not have required roles: [Role3]")); } }
Example 8
Source File: SecuredSpringRouteTestCase.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testInvalidCredentials() throws Exception { CamelContext camelctx = contextRegistry.getCamelContext("contextA"); ProducerTemplate producer = camelctx.createProducerTemplate(); try { Subject subject = getAuthenticationToken("user-domain", AnnotatedSLSB.USERNAME, "bogus"); producer.requestBodyAndHeader("direct:start", "Kermit", Exchange.AUTHENTICATION, subject, String.class); Assert.fail("CamelExecutionException expected"); } catch (CamelExecutionException ex) { Throwable cause = ex.getCause(); Assert.assertEquals(FailedLoginException.class, cause.getClass()); Assert.assertTrue(cause.getMessage(), cause.getMessage().contains("Password invalid/Password required")); } }
Example 9
Source File: SecuredSpringRouteTestCase.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testNoAuthenticationHeader() throws Exception { CamelContext camelctx = contextRegistry.getCamelContext("contextA"); ProducerTemplate producer = camelctx.createProducerTemplate(); try { producer.requestBody("direct:start", "Kermit", String.class); Assert.fail("CamelExecutionException expected"); } catch (CamelExecutionException ex) { Throwable cause = ex.getCause(); Assert.assertEquals(SecurityException.class, cause.getClass()); Assert.assertTrue(cause.getMessage(), cause.getMessage().startsWith("Cannot obtain authentication subject")); } }
Example 10
Source File: AuthorizationPolicyTestCase.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testInsufficientRoles() throws Exception { CamelContext camelctx = contextRegistry.getCamelContext("contextC"); ProducerTemplate producer = camelctx.createProducerTemplate(); try { Subject subject = getAuthenticationToken("user-domain", AnnotatedSLSB.USERNAME, AnnotatedSLSB.PASSWORD); producer.requestBodyAndHeader("direct:start", "Kermit", Exchange.AUTHENTICATION, subject, String.class); Assert.fail("CamelExecutionException expected"); } catch (CamelExecutionException ex) { Throwable cause = ex.getCause(); Assert.assertEquals(CamelAuthorizationException.class, cause.getClass()); Assert.assertTrue(cause.getMessage(), cause.getMessage().contains("User does not have required roles: [Role3]")); } }
Example 11
Source File: CamelSpringBootShutdownTest.java From camel-spring-boot with Apache License 2.0 | 5 votes |
@Test public void test1() throws Exception { try { // Send a String body that need to be converted to an InputStream template.sendBody("direct:start", "42"); } catch (CamelExecutionException e) { // unwrap Exception throw (Exception) e.getCause(); } }
Example 12
Source File: AuthorizationPolicyTestCase.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testNoAuthenticationHeader() throws Exception { CamelContext camelctx = contextRegistry.getCamelContext("contextA"); ProducerTemplate producer = camelctx.createProducerTemplate(); try { producer.requestBody("direct:start", "Kermit", String.class); Assert.fail("CamelExecutionException expected"); } catch (CamelExecutionException ex) { Throwable cause = ex.getCause(); Assert.assertEquals(CamelAuthorizationException.class, cause.getClass()); Assert.assertTrue(cause.getMessage(), cause.getMessage().startsWith("Cannot find the Authentication instance")); } }
Example 13
Source File: SpringSecuritySpringTest.java From camel-cookbook-examples with Apache License 2.0 | 5 votes |
@Test public void testBadPassword() { Map<String, Object> headers = new HashMap<String, Object>(); headers.put("username", "jakub"); headers.put("password", "iforgotmypassword"); try { template.sendBodyAndHeaders("direct:in", "foo", headers); fail(); } catch (CamelExecutionException ex) { CamelAuthorizationException cax = (CamelAuthorizationException) ex.getCause(); assertTrue(ExceptionUtils.getRootCause(cax) instanceof BadCredentialsException); } }
Example 14
Source File: SpringSecurityHeadersSpringTest.java From camel-cookbook-examples with Apache License 2.0 | 5 votes |
@Test public void testBadPassword() { Map<String, Object> headers = new HashMap<String, Object>(); headers.put("username", "jakub"); headers.put("password", "iforgotmypassword"); try { template.sendBodyAndHeaders("direct:in", "foo", headers); fail(); } catch (CamelExecutionException ex) { CamelAuthorizationException cax = (CamelAuthorizationException) ex.getCause(); assertTrue(ExceptionUtils.getRootCause(cax) instanceof BadCredentialsException); } }
Example 15
Source File: DoTrySpringTest.java From camel-cookbook-examples with Apache License 2.0 | 5 votes |
@Test public void testDoTryUnHandled() throws Exception { final MockEndpoint mockBefore = getMockEndpoint("mock:before"); mockBefore.expectedBodiesReceived("Kaboom"); final MockEndpoint mockError = getMockEndpoint("mock:error"); mockError.expectedBodiesReceived("Kaboom"); final MockEndpoint mockFinally = getMockEndpoint("mock:finally"); mockFinally.expectedBodiesReceived("Something Bad Happened!"); final MockEndpoint mockAfter = getMockEndpoint("mock:after"); mockAfter.expectedMessageCount(0); String response = null; boolean threwException = false; try { response = template.requestBody("direct:unhandled", "Kaboom", String.class); } catch (Throwable e) { threwException = true; CamelExecutionException cee = assertIsInstanceOf(CamelExecutionException.class, e); Throwable cause = cee.getCause(); assertIsInstanceOf(FlakyException.class, cause); } assertTrue(threwException); assertNull(response); assertMockEndpointsSatisfied(); }
Example 16
Source File: DoTryTest.java From camel-cookbook-examples with Apache License 2.0 | 5 votes |
@Test public void testDoTryUnHandled() throws Exception { final MockEndpoint mockBefore = getMockEndpoint("mock:before"); mockBefore.expectedBodiesReceived("Kaboom"); final MockEndpoint mockError = getMockEndpoint("mock:error"); mockError.expectedBodiesReceived("Kaboom"); final MockEndpoint mockFinally = getMockEndpoint("mock:finally"); mockFinally.expectedBodiesReceived("Something Bad Happened!"); final MockEndpoint mockAfter = getMockEndpoint("mock:after"); mockAfter.expectedMessageCount(0); String response = null; boolean threwException = false; try { response = template.requestBody("direct:unhandled", "Kaboom", String.class); } catch (Throwable e) { threwException = true; CamelExecutionException cee = assertIsInstanceOf(CamelExecutionException.class, e); Throwable cause = cee.getCause(); assertIsInstanceOf(FlakyException.class, cause); } assertTrue(threwException); assertNull(response); assertMockEndpointsSatisfied(); }
Example 17
Source File: CamelSpringBootShutdownTest.java From camel-spring-boot with Apache License 2.0 | 5 votes |
@Test public void test2() throws Exception { try { // Starts a Thread to close the context in 500 ms new DelayedCloser(context, 500).start(); // Send the same body, and let the context be closed before the processing happens template.sendBody("direct:start", "42"); } catch (CamelExecutionException e) { // unwrap Exception throw (Exception) e.getCause(); } }