Search in sources :

Example 66 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project camel by apache.

the class BeanLanguageMethodMissingParenthesisTest method testFooMissingParenthesis.

public void testFooMissingParenthesis() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").filter(method(BeanLanguageMethodMissingParenthesisTest.class, "couldThisBeFoo(${body}, ${header.foo}")).to("mock:foo").end().to("mock:result");
        }
    });
    context.start();
    try {
        template.sendBodyAndHeader("direct:start", "Hello World", "foo", "yes");
        fail("Should throw exception");
    } catch (CamelExecutionException e) {
        IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause());
        assertEquals("Method should end with parenthesis, was couldThisBeFoo(${body}, ${header.foo}", iae.getMessage());
    }
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) RouteBuilder(org.apache.camel.builder.RouteBuilder) CamelExecutionException(org.apache.camel.CamelExecutionException)

Example 67 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project wildfly-camel by wildfly-extras.

the class AuthorizationPolicyTestCase method testInvalidCredentials.

@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"));
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) CamelExecutionException(org.apache.camel.CamelExecutionException) ProducerTemplate(org.apache.camel.ProducerTemplate) CamelAuthorizationException(org.apache.camel.CamelAuthorizationException) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 68 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project wildfly-camel by wildfly-extras.

the class AuthorizationPolicyTestCase method testInsufficientRoles.

@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]"));
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) CamelExecutionException(org.apache.camel.CamelExecutionException) ProducerTemplate(org.apache.camel.ProducerTemplate) CamelAuthorizationException(org.apache.camel.CamelAuthorizationException) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 69 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project wildfly-camel by wildfly-extras.

the class SecuredSpringRouteTestCase method testInvalidCredentials.

@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"));
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) CamelExecutionException(org.apache.camel.CamelExecutionException) ProducerTemplate(org.apache.camel.ProducerTemplate) FailedLoginException(javax.security.auth.login.FailedLoginException) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 70 with CamelExecutionException

use of org.apache.camel.CamelExecutionException in project wildfly-camel by wildfly-extras.

the class SecuredRouteTestCase method testNoAuthenticationHeader.

@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.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelExecutionException(org.apache.camel.CamelExecutionException) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) DomainAuthorizationPolicy(org.wildfly.extension.camel.security.DomainAuthorizationPolicy) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) LoginException(javax.security.auth.login.LoginException) CamelExecutionException(org.apache.camel.CamelExecutionException) FailedLoginException(javax.security.auth.login.FailedLoginException) Test(org.junit.Test)

Aggregations

CamelExecutionException (org.apache.camel.CamelExecutionException)156 RouteBuilder (org.apache.camel.builder.RouteBuilder)69 Test (org.junit.Test)64 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)59 Exchange (org.apache.camel.Exchange)23 CamelContext (org.apache.camel.CamelContext)20 Processor (org.apache.camel.Processor)17 ProducerTemplate (org.apache.camel.ProducerTemplate)17 CamelExchangeException (org.apache.camel.CamelExchangeException)13 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)13 IOException (java.io.IOException)12 Date (java.util.Date)11 StopWatch (org.apache.camel.util.StopWatch)10 ExchangeTimedOutException (org.apache.camel.ExchangeTimedOutException)7 Set (java.util.Set)6 Subject (javax.security.auth.Subject)6 ConstraintViolation (javax.validation.ConstraintViolation)6 FailedLoginException (javax.security.auth.login.FailedLoginException)5 QuartzComponent (org.apache.camel.component.quartz.QuartzComponent)5 File (java.io.File)4