2
votes

I am new to camel and blueprint.

I am trying to make a simple programme to put data in a queue. Not sure whats going wrong in here.

Camel Context file ==>

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/blueprint"
    xsi:schemaLocation="
       http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
       http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

    <bean id="helloBean" class="com.camelSampleBundle.HelloBean">
        <property name="say" value="Hi from Camel" />
    </bean>
    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="brokerURL" value="tcp://localhost:61616" />
    </bean>
    <camelContext id="blueprintContext" trace="false"
        xmlns="http://camel.apache.org/schema/blueprint">
        <route id="timerToLog">
            <from uri="timer:foo?period=5000" />
            <setBody>
                <constant>Hello World!</constant>
            </setBody>
            <to uri="activemq:camel.q.timer" />
            <log message="The message contains ${body}" />

        </route>
        <!-- <route id="anotherRoute">
            <from uri="activemq:camel.q.timer" />
            <log message="The message contains ${body}" />
            <to uri="mock:result" />
        </route> -->
    </camelContext>

</blueprint>

POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.camelSampleBundle</groupId>
    <artifactId>camel-sampleBundle</artifactId>
    <packaging>bundle</packaging>
    <version>1.0.0-SNAPSHOT</version>

    <name>Sample Bundle</name>
    <url>http://www.myorganization.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <fuse.version>2.12.0.redhat-610379</fuse.version>
    </properties>

    <repositories>
        <repository>
            <id>release.fusesource.org</id>
            <name>FuseSource Release Repository</name>
            <url>http://repo.fusesource.com/nexus/content/repositories/releases</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
        <repository>
            <id>snapshot.fusesource.org</id>
            <name>FuseSource Snapshot Repository</name>
            <url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>release.fusesource.org</id>
            <name>FuseSource Release Repository</name>
            <url>http://repo.fusesource.com/nexus/content/repositories/releases</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </pluginRepository>
        <pluginRepository>
            <id>snapshot.fusesource.org</id>
            <name>FuseSource Snapshot Repository</name>
            <url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>false</enabled>
            </releases>
        </pluginRepository>
    </pluginRepositories>

    <dependencies>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>2.10.0.redhat-60024</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-blueprint</artifactId>
            <version>2.10.0.redhat-60024</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jms</artifactId>
            <version>2.10.0.redhat-60024</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-camel</artifactId>
            <version>5.13.2</version>
        </dependency>



        <!-- logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.6</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.6</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.6.6</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <!-- testing -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-test-blueprint</artifactId>
            <version>2.10.0.redhat-60024</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <defaultGoal>install</defaultGoal>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.4.3</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>

            <!-- to generate the MANIFEST-FILE of the bundle -->
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.7</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>camel-sampleBundle</Bundle-SymbolicName>
                        <Import-Package>*</Import-Package>
                        <Export-Package />
                    </instructions>
                </configuration>
            </plugin>

            <!-- to run the example using mvn camel:run -->
            <plugin>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-maven-plugin</artifactId>
                <version>2.10.0.redhat-60024</version>
                <configuration>
                    <useBlueprint>true</useBlueprint>
                </configuration>
            </plugin>

        </plugins>
    </build>

</project>

ERROR Stacktrace ==>

org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to instantiate components at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:671) at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:370) at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:261) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at org.apache.aries.blueprint.container.ExecutorServiceWrapper.run(ExecutorServiceWrapper.java:106) at org.apache.aries.blueprint.utils.threading.impl.DiscardableRunnable.run(DiscardableRunnable.java:48) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.NoClassDefFoundError: org/apache/camel/spi/EndpointCompleter at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) at java.net.URLClassLoader.access$100(URLClassLoader.java:71) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at de.kalpatec.pojosr.framework.PojoSRBundle.loadClass(PojoSRBundle.java:431) at org.apache.aries.blueprint.container.BlueprintContainerImpl.loadClass(BlueprintContainerImpl.java:419) at org.apache.aries.blueprint.container.BlueprintRepository.loadClass(BlueprintRepository.java:410) at org.apache.aries.blueprint.container.GenericType.parse(GenericType.java:113) at org.apache.aries.blueprint.di.AbstractRecipe.doLoadType(AbstractRecipe.java:168) at org.apache.aries.blueprint.di.AbstractRecipe.loadType(AbstractRecipe.java:161) at org.apache.aries.blueprint.container.BeanRecipe.loadClass(BeanRecipe.java:249) at org.apache.aries.blueprint.container.BeanRecipe.getType(BeanRecipe.java:895) at org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:323) at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:806) at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787) at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88) at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:245) at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:183) at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:667) ... 13 more Caused by: java.lang.ClassNotFoundException: org.apache.camel.spi.EndpointCompleter at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 42 more

3

3 Answers

2
votes

The problem was with the version of camel. I changed the camel version in my pom.xml and it worked fine

<dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-core</artifactId>
        <version>2.12.0.redhat-610379</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-blueprint</artifactId>
        <version>2.12.0.redhat-610379</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jms</artifactId>
        <version>2.12.0.redhat-610379</version>
    </dependency>
1
votes

Do you have camel-core installed in your OSGI env ? If you are in karaf (2.x.x), type

features:list | grep camel

If nothing shows, you can do a :

features:chooseurl camel

To add the repository, and then :

features:install camel-core

I highly recommend you to read "OSGi in Action". A ClassNotFoundException often indicates that your context doesn't have visibility on a class another bundle would export. Since "org/apache/camel/spi/EndpointCompleter" is camel-core, you have to install it in your osgi environment.

To check if the package is exported :

jschoreels@lab> exports | grep camel.spi
   100 org.apache.camel.spi; version="2.14.3"  
jschoreels@lab> list | grep 100
START LEVEL 100 , List Threshold: 50
[ 100] [Active     ] [            ] [       ] [   50] camel-core (2.14.3)

However, your bundle has to import this package too. You can do a :

imports <bundleidOfYourImportingBundle>

and check if the package is there.

If not, you have to check if you build the bundle correctly. A correct bundle should declare some OSGi header in the MANIFEST.MF. You can have an example here.

To generate it with maven, you should consider use the maven bundle plugin which rely on bnd.

Here is an example to use it :

<build>
     <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>${maven-bundle-pulgin.version}</version>
                <configuration>
                    <instructions>
                        <Import-Package>*</Import-Package>
                        <Export-Package />
                    </instructions>
                </configuration>
            </plugin>
    </plugins
</build>

If you want to learn OSGi, I really recommend you OSGi in action and read at least the three layers (Modularity, Lifecycle and Service) chapters to understand how the discovery work. It explains at the end what is bnd and how to use it.

0
votes

The stacktrace hints that you seem to run your camel context in a simulated OSGi environment.

de.kalpatec.pojosr.framework.PojoSRBundle.loadClass(PojoSRBundle.java:431)

Try to run it in a real OSGi environment like karaf.