use of org.apache.camel.core.osgi.utils.BundleDelegatingClassLoader in project camel by apache.
the class AbstractCamelRunner method createCamelContext.
protected void createCamelContext(final BundleContext bundleContext, final Map<String, String> props) {
if (bundleContext != null) {
context = new OsgiDefaultCamelContext(bundleContext, createRegistry(bundleContext));
// Setup the application context classloader with the bundle classloader
context.setApplicationContextClassLoader(new BundleDelegatingClassLoader(bundleContext.getBundle()));
// and make sure the TCCL is our classloader
Thread.currentThread().setContextClassLoader(context.getApplicationContextClassLoader());
} else {
context = new DefaultCamelContext(createRegistry());
}
setupPropertiesComponent(context, props, log);
}
use of org.apache.camel.core.osgi.utils.BundleDelegatingClassLoader in project camel by apache.
the class CamelContextFactoryBean method findRouteBuildersByPackageScan.
@Override
protected void findRouteBuildersByPackageScan(String[] packages, PackageScanFilter filter, List<RoutesBuilder> builders) throws Exception {
// add filter to class resolver which then will filter
getContext().getPackageScanClassResolver().addFilter(filter);
ClassLoader classLoader = new BundleDelegatingClassLoader(bundleContext.getBundle());
PackageScanRouteBuilderFinder finder = new PackageScanRouteBuilderFinder(getContext(), packages, classLoader, getContext().getPackageScanClassResolver());
finder.appendBuilders(builders);
// and remove the filter
getContext().getPackageScanClassResolver().removeFilter(filter);
}
use of org.apache.camel.core.osgi.utils.BundleDelegatingClassLoader in project camel by apache.
the class CamelContextFactoryBean method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet();
// setup the application context classloader with the bundle delegating classloader
ClassLoader cl = new BundleDelegatingClassLoader(bundleContext.getBundle());
LOG.debug("Set the application context classloader to: {}", cl);
getContext().setApplicationContextClassLoader(cl);
osgiCamelContextPublisher = new OsgiCamelContextPublisher(bundleContext);
osgiCamelContextPublisher.start();
getContext().getManagementStrategy().addEventNotifier(osgiCamelContextPublisher);
try {
getClass().getClassLoader().loadClass("org.osgi.service.event.EventAdmin");
getContext().getManagementStrategy().addEventNotifier(new OsgiEventAdminNotifier(bundleContext));
} catch (Throwable t) {
// Ignore, if the EventAdmin package is not available, just don't use it
LOG.debug("EventAdmin package is not available, just don't use it");
}
// ensure routes is setup
setupRoutes();
}
Aggregations