Search in sources :

Example 6 with NoSuchBeanException

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

the class CompositeRegistry method lookupByNameAndType.

public <T> T lookupByNameAndType(String name, Class<T> type) {
    T answer = null;
    RuntimeCamelException ex = null;
    for (Registry registry : registryList) {
        try {
            answer = registry.lookupByNameAndType(name, type);
        } catch (Throwable e) {
            // do not double wrap the exception
            if (e instanceof NoSuchBeanException) {
                ex = (NoSuchBeanException) e;
            } else {
                ex = new NoSuchBeanException(name, "Cannot lookup: " + name + " from registry: " + registry + " with expected type: " + type + " due: " + e.getMessage(), e);
            }
        }
        if (answer != null) {
            return answer;
        }
    }
    if (ex != null) {
        throw ex;
    } else {
        return answer;
    }
}
Also used : NoSuchBeanException(org.apache.camel.NoSuchBeanException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) Registry(org.apache.camel.spi.Registry)

Example 7 with NoSuchBeanException

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

the class MethodCallBeanRefNotFoundTest method testMethodCallBeanRefNotFound.

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

        @Override
        public void configure() throws Exception {
            from("direct:a").routeId("a").split().method("foo", "hello").to("mock:a");
            from("direct:b").routeId("b").split().method("bar", "hello").to("mock:b");
        }
    });
    try {
        context.start();
        fail("Should have thrown exception");
    } catch (FailedToCreateRouteException e) {
        assertEquals("b", e.getRouteId());
        NoSuchBeanException cause = assertIsInstanceOf(NoSuchBeanException.class, e.getCause());
        assertEquals("bar", cause.getName());
    }
}
Also used : FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) RouteBuilder(org.apache.camel.builder.RouteBuilder) NoSuchBeanException(org.apache.camel.NoSuchBeanException) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) NoSuchBeanException(org.apache.camel.NoSuchBeanException)

Example 8 with NoSuchBeanException

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

the class BeanRefNotFoundTest method testBeanRefNotFound.

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

        @Override
        public void configure() throws Exception {
            from("direct:a").routeId("a").bean("foo").to("mock:a");
            from("direct:b").routeId("b").bean("bar").to("mock:b");
        }
    });
    try {
        context.start();
        fail("Should have thrown exception");
    } catch (FailedToCreateRouteException e) {
        assertEquals("b", e.getRouteId());
        NoSuchBeanException cause = assertIsInstanceOf(NoSuchBeanException.class, e.getCause());
        assertEquals("bar", cause.getName());
    }
}
Also used : FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) RouteBuilder(org.apache.camel.builder.RouteBuilder) NoSuchBeanException(org.apache.camel.NoSuchBeanException) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) NoSuchBeanException(org.apache.camel.NoSuchBeanException)

Example 9 with NoSuchBeanException

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

the class JavaDslTransactedNoTXManagerTest method testTransactedNoTXManager.

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

        @Override
        public void configure() throws Exception {
            from("direct:start").transacted().to("mock:result");
        }
    });
    try {
        context.start();
        fail("Should have thrown an exception");
    } catch (FailedToCreateRouteException e) {
        NoSuchBeanException cause = assertIsInstanceOf(NoSuchBeanException.class, e.getCause());
        assertEquals("No bean could be found in the registry of type: PlatformTransactionManager", cause.getMessage());
    }
}
Also used : FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) RouteBuilder(org.apache.camel.builder.RouteBuilder) NoSuchBeanException(org.apache.camel.NoSuchBeanException) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) NoSuchBeanException(org.apache.camel.NoSuchBeanException)

Example 10 with NoSuchBeanException

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

the class RegistryLookupTypeClassCastExceptionTest method testCamelContextLookupClassCast.

public void testCamelContextLookupClassCast() throws Exception {
    SimpleRegistry simple = new SimpleRegistry();
    CamelContext context = new DefaultCamelContext(simple);
    MyClass my = new MyClass();
    simple.put("my", my);
    try {
        context.getRegistry().lookupByNameAndType("my", String.class);
        fail("Should have thrown exception");
    } catch (NoSuchBeanException e) {
        assertEquals("my", e.getName());
        assertTrue(e.getMessage().endsWith("expected type was: class java.lang.String"));
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) NoSuchBeanException(org.apache.camel.NoSuchBeanException)

Aggregations

NoSuchBeanException (org.apache.camel.NoSuchBeanException)13 Component (org.apache.camel.Component)3 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)3 RouteBuilder (org.apache.camel.builder.RouteBuilder)3 RestConfiguration (org.apache.camel.spi.RestConfiguration)3 Field (java.lang.reflect.Field)2 Consumer (org.apache.camel.Consumer)2 RuntimeCamelException (org.apache.camel.RuntimeCamelException)2 SessionClient (com.orbitz.consul.SessionClient)1 SessionCreatedResponse (com.orbitz.consul.model.session.SessionCreatedResponse)1 Method (java.lang.reflect.Method)1 CamelContext (org.apache.camel.CamelContext)1 EndpointInject (org.apache.camel.EndpointInject)1 NoFactoryAvailableException (org.apache.camel.NoFactoryAvailableException)1 Producer (org.apache.camel.Producer)1 DefaultEndpoint (org.apache.camel.impl.DefaultEndpoint)1 SimpleLanguage (org.apache.camel.language.simple.SimpleLanguage)1 FactoryFinder (org.apache.camel.spi.FactoryFinder)1 Language (org.apache.camel.spi.Language)1 Policy (org.apache.camel.spi.Policy)1