Search in sources :

Example 1 with BundleDelegatingClassLoader

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);
}
Also used : OsgiDefaultCamelContext(org.apache.camel.core.osgi.OsgiDefaultCamelContext) BundleDelegatingClassLoader(org.apache.camel.core.osgi.utils.BundleDelegatingClassLoader) OsgiDefaultCamelContext(org.apache.camel.core.osgi.OsgiDefaultCamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 2 with BundleDelegatingClassLoader

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);
}
Also used : BundleDelegatingClassLoader(org.apache.camel.core.osgi.utils.BundleDelegatingClassLoader) BundleDelegatingClassLoader(org.apache.camel.core.osgi.utils.BundleDelegatingClassLoader)

Example 3 with BundleDelegatingClassLoader

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();
}
Also used : OsgiEventAdminNotifier(org.apache.camel.core.osgi.OsgiEventAdminNotifier) OsgiCamelContextPublisher(org.apache.camel.core.osgi.OsgiCamelContextPublisher) BundleDelegatingClassLoader(org.apache.camel.core.osgi.utils.BundleDelegatingClassLoader) BundleDelegatingClassLoader(org.apache.camel.core.osgi.utils.BundleDelegatingClassLoader)

Aggregations

BundleDelegatingClassLoader (org.apache.camel.core.osgi.utils.BundleDelegatingClassLoader)3 OsgiCamelContextPublisher (org.apache.camel.core.osgi.OsgiCamelContextPublisher)1 OsgiDefaultCamelContext (org.apache.camel.core.osgi.OsgiDefaultCamelContext)1 OsgiEventAdminNotifier (org.apache.camel.core.osgi.OsgiEventAdminNotifier)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1