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;
}
}
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());
}
}
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());
}
}
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());
}
}
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"));
}
}
Aggregations