use of org.apache.camel.RoutesBuilder in project camel by apache.
the class RoutesCollector method onApplicationEvent.
// Overridden
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
ApplicationContext applicationContext = event.getApplicationContext();
// only listen to context refresh of "my" applicationContext
if (this.applicationContext.equals(applicationContext)) {
CamelContext camelContext = event.getApplicationContext().getBean(CamelContext.class);
// only add and start Camel if its stopped (initial state)
if (camelContext.getStatus().isStopped()) {
LOG.debug("Post-processing CamelContext bean: {}", camelContext.getName());
for (RoutesBuilder routesBuilder : configuration.routes()) {
// filter out abstract classes
boolean abs = Modifier.isAbstract(routesBuilder.getClass().getModifiers());
if (!abs) {
try {
LOG.debug("Injecting following route into the CamelContext: {}", routesBuilder);
camelContext.addRoutes(routesBuilder);
} catch (Exception e) {
throw new CamelSpringJavaconfigInitializationException(e);
}
}
}
try {
boolean skip = "true".equalsIgnoreCase(System.getProperty("skipStartingCamelContext"));
if (skip) {
LOG.info("Skipping starting CamelContext(s) as system property skipStartingCamelContext is set to be true.");
} else {
// start camel
camelContext.start();
}
} catch (Exception e) {
throw new CamelSpringJavaconfigInitializationException(e);
}
}
} else {
LOG.debug("Ignore ContextRefreshedEvent: {}", event);
}
}
use of org.apache.camel.RoutesBuilder in project camel by apache.
the class CamelTestSupport method doSetUp.
private void doSetUp() throws Exception {
log.debug("setUp test");
if (!useJmx()) {
disableJMX();
} else {
enableJMX();
}
CamelContext c2 = createCamelContext();
if (c2 instanceof ModelCamelContext) {
context = (ModelCamelContext) c2;
} else {
throw new Exception("Context must be a ModelCamelContext");
}
threadCamelContext.set(context);
assertNotNull(context, "No context found!");
// reduce default shutdown timeout to avoid waiting for 300 seconds
context.getShutdownStrategy().setTimeout(getShutdownTimeout());
// set debugger if enabled
if (isUseDebugger()) {
context.setDebugger(new DefaultDebugger());
context.getDebugger().addBreakpoint(breakpoint);
// note: when stopping CamelContext it will automatic remove the breakpoint
}
template = context.createProducerTemplate();
template.start();
consumer = context.createConsumerTemplate();
consumer.start();
threadTemplate.set(template);
threadConsumer.set(consumer);
// enable auto mocking if enabled
String pattern = isMockEndpoints();
if (pattern != null) {
context.addRegisterEndpointCallback(new InterceptSendToMockEndpointStrategy(pattern));
}
pattern = isMockEndpointsAndSkip();
if (pattern != null) {
context.addRegisterEndpointCallback(new InterceptSendToMockEndpointStrategy(pattern, true));
}
// configure properties component (mandatory for testing)
context.getComponent("properties", PropertiesComponent.class);
postProcessTest();
if (isUseRouteBuilder()) {
RoutesBuilder[] builders = createRouteBuilders();
for (RoutesBuilder builder : builders) {
log.debug("Using created route builder: " + builder);
context.addRoutes(builder);
}
boolean skip = "true".equalsIgnoreCase(System.getProperty("skipStartingCamelContext"));
if (skip) {
log.info("Skipping starting CamelContext as system property skipStartingCamelContext is set to be true.");
} else if (isUseAdviceWith()) {
log.info("Skipping starting CamelContext as isUseAdviceWith is set to true.");
} else {
startCamelContext();
}
} else {
log.debug("Using route builder from the created context: " + context);
}
log.debug("Routing Rules are: " + context.getRoutes());
assertValidContext(context);
INIT.set(true);
}
use of org.apache.camel.RoutesBuilder in project camel by apache.
the class PackageScanRouteBuilderFinder method appendBuilders.
/**
* Appends all the {@link org.apache.camel.builder.RouteBuilder} instances that can be found on the classpath
*/
public void appendBuilders(List<RoutesBuilder> list) throws IllegalAccessException, InstantiationException {
Set<Class<?>> classes = resolver.findImplementations(RoutesBuilder.class, packages);
for (Class<?> aClass : classes) {
LOG.trace("Found RouteBuilder class: {}", aClass);
// certain beans should be ignored
if (shouldIgnoreBean(aClass)) {
LOG.debug("Ignoring RouteBuilder class: {}", aClass);
continue;
}
if (!isValidClass(aClass)) {
LOG.debug("Ignoring invalid RouteBuilder class: {}", aClass);
continue;
}
// type is valid so create and instantiate the builder
@SuppressWarnings("unchecked") RoutesBuilder builder = instantiateBuilder((Class<? extends RoutesBuilder>) aClass);
if (beanPostProcessor != null) {
// Inject the annotated resource
beanPostProcessor.postProcessBeforeInitialization(builder, builder.toString());
}
LOG.debug("Adding instantiated RouteBuilder: {}", builder);
list.add(builder);
}
}
use of org.apache.camel.RoutesBuilder in project camel by apache.
the class PackageScanRouteBuilderFinder method appendBuilders.
/**
* Appends all the {@link org.apache.camel.builder.RouteBuilder} instances that can be found on the classpath
*/
public void appendBuilders(List<RoutesBuilder> list) throws IllegalAccessException, InstantiationException {
Set<Class<?>> classes = resolver.findImplementations(RoutesBuilder.class, packages);
for (Class<?> aClass : classes) {
LOG.trace("Found RouteBuilder class: {}", aClass);
// certain beans should be ignored
if (shouldIgnoreBean(aClass)) {
LOG.debug("Ignoring RouteBuilder class: {}", aClass);
continue;
}
if (!isValidClass(aClass)) {
LOG.debug("Ignoring invalid RouteBuilder class: {}", aClass);
continue;
}
// type is valid so create and instantiate the builder
RoutesBuilder builder = instantiateBuilder(aClass);
LOG.debug("Adding instantiated RouteBuilder: {}", builder);
list.add(builder);
}
}
use of org.apache.camel.RoutesBuilder in project camel by apache.
the class PackageScanRouteBuilderFinder method appendBuilders.
/**
* Appends all the {@link org.apache.camel.builder.RouteBuilder} instances that can be found on the classpath
*/
void appendBuilders(List<RoutesBuilder> list) throws IllegalAccessException, InstantiationException {
Set<Class<?>> classes = resolver.findImplementations(RoutesBuilder.class, packages);
for (Class<?> aClass : classes) {
logger.trace("Found RouteBuilder class: {}", aClass);
// certain beans should be ignored
if (shouldIgnoreBean(aClass)) {
logger.debug("Ignoring RouteBuilder class: {}", aClass);
continue;
}
if (!isValidClass(aClass)) {
logger.debug("Ignoring invalid RouteBuilder class: {}", aClass);
continue;
}
// type is valid so create and instantiate the builder
@SuppressWarnings("unchecked") RoutesBuilder builder = instantiateBuilder((Class<? extends RoutesBuilder>) aClass);
logger.debug("Adding instantiated RouteBuilder: {}", builder);
list.add(builder);
}
}
Aggregations