Java Code Examples for org.apache.camel.CamelContext#getApplicationContextClassLoader()

The following examples show how to use org.apache.camel.CamelContext#getApplicationContextClassLoader() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleCamelTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testCamelDependency() throws Exception {

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").transform(body().prepend("Hello "));
        }
    });

    camelctx.start();
    try {

        // Deployment is not camel enabled
        ClassLoader appcl = camelctx.getApplicationContextClassLoader();
        Assert.assertNull("ApplicationContextClassLoader is null", appcl);

        ProducerTemplate producer = camelctx.createProducerTemplate();
        String result = producer.requestBody("direct:start", "Kermit", String.class);
        Assert.assertEquals("Hello Kermit", result);
    } finally {
        camelctx.close();
    }
}
 
Example 2
Source File: ExplicitCamelDependencyTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testCamelDependency() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").transform(body().prepend("Hello "));
        }
    });

    camelctx.start();
    try {

        // Deployment is not camel enabled
        ClassLoader appcl = camelctx.getApplicationContextClassLoader();
        Assert.assertNull("ApplicationContextClassLoader is null", appcl);

        ProducerTemplate producer = camelctx.createProducerTemplate();
        String result = producer.requestBody("direct:start", "Kermit", String.class);
        Assert.assertEquals("Hello Kermit", result);
    } finally {
        camelctx.close();
    }
}
 
Example 3
Source File: RuntimeRecorder.java    From camel-k-runtime with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<CamelContextCustomizer> registerCompositeClassLoader() {
    return new RuntimeValue<>(new CamelContextCustomizer() {
        @Override
        public void customize(CamelContext context) {
            final ClassLoader oldLoader = context.getApplicationContextClassLoader();
            final ClassLoader newLoader = CompositeClassloader.wrap(oldLoader);

            context.setApplicationContextClassLoader(newLoader);
        }
    });
}
 
Example 4
Source File: ClassResolverAssociationHandler.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(CamelContext camelctx) {

    // Verify that the application context class loader is a ModuleClassLoader
    ClassLoader classLoader = camelctx.getApplicationContextClassLoader();
    IllegalStateAssertion.assertTrue(classLoader instanceof ModuleClassLoader, "Invalid class loader association: " + classLoader);

    ModuleClassLoader moduleClassLoader = (ModuleClassLoader) classLoader;
    camelctx.setClassResolver(new WildFlyClassResolver(moduleClassLoader));
}