Author: ningjiang
Date: Mon Aug 1 10:53:44 2011
New Revision: 1152733
URL: http://svn.apache.org/viewvc?rev=1152733&view=rev
Log:
CAMEL-4286 BlueprintCamelContextFactoryBean should set the
ApplicationContextClassLoader for the CamelContext
Modified:
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprint4Test.java
Modified:
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java?rev=1152733&r1=1152732&r2=1152733&view=diff
==============================================================================
---
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
(original)
+++
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
Mon Aug 1 10:53:44 2011
@@ -261,6 +261,10 @@ public class CamelContextFactoryBean ext
@Override
public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet();
+ // setup the application context classloader with the bundle
delegating classloader
+ ClassLoader cl = new
BundleDelegatingClassLoader(((ExtendedBlueprintContainer)
blueprintContainer).getBundleContext().getBundle());
+ LOG.debug("Set the application context classloader to: {}", cl);
+ getContext().setApplicationContextClassLoader(cl);
getContext().getManagementStrategy().addEventNotifier(new
OsgiCamelContextPublisher(bundleContext));
try {
getClass().getClassLoader().loadClass("org.osgi.service.event.EventAdmin");
Modified:
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprint4Test.java
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprint4Test.java?rev=1152733&r1=1152732&r2=1152733&view=diff
==============================================================================
---
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprint4Test.java
(original)
+++
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprint4Test.java
Mon Aug 1 10:53:44 2011
@@ -31,6 +31,7 @@ import org.osgi.service.blueprint.contai
import static org.ops4j.pax.exam.OptionUtils.combine;
import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.newBundle;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.withBnd;
/**
* @version
@@ -89,6 +90,20 @@ public class CamelBlueprint4Test extends
template.stop();
}
+ @Test
+ public void testGetApplicationContextClassloader() throws Exception {
+ getInstalledBundle("CamelBlueprintTestBundle22").start();
+ BlueprintContainer ctn = getOsgiService(BlueprintContainer.class,
"(osgi.blueprint.container.symbolicname=CamelBlueprintTestBundle22)", 10000);
+ CamelContext ctx = getOsgiService(CamelContext.class,
"(camel.context.symbolicname=CamelBlueprintTestBundle22)", 10000);
+
+ // test the application context classloader
+ assertNotNull("The application context classloader should not be
null", ctx.getApplicationContextClassLoader());
+ ClassLoader cl = ctx.getApplicationContextClassLoader();
+ assertNotNull("It should load the TestRouteBuilder class",
cl.getResource("OSGI-INF/blueprint/test.xml"));
+ assertNotNull("It should load the TestRouteBuilder class",
cl.loadClass("org.apache.camel.itest.osgi.blueprint.TestRouteBuilder"));
+
+ }
+
@Configuration
public static Option[] configure() throws Exception {
@@ -112,6 +127,12 @@ public class CamelBlueprint4Test extends
.set(Constants.BUNDLE_SYMBOLICNAME,
"CamelBlueprintTestBundle21")
.build()).noStart(),
+ bundle(newBundle()
+ .add("OSGI-INF/blueprint/test.xml",
OSGiBlueprintTestSupport.class.getResource("blueprint-13.xml"))
+ .set(Constants.BUNDLE_SYMBOLICNAME,
"CamelBlueprintTestBundle22")
+ .add(TestRouteBuilder.class)
+ .build(withBnd())).noStart(),
+
// using the features to install the camel components
scanFeatures(getCamelKarafFeatureUrl(),
"camel-blueprint", "camel-velocity"));