Hi, 
I am new in karaf and OSGI technologies. I have created a simple OSGI bundle
with Camel and Spring and deployed the same in Karaf 4.2.0. The bundle has
started successfully but I cant see the log which my came route is supposed
to print. My code is using logger and sysout both. 

Here is the bean class.
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;

/**
 * @version $Revision: 640450 $
 */
public class MyTransform  {

    private static final transient Logger LOG =
LoggerFactory.getLogger(MyTransform.class);

    private boolean verbose = true;
    private String prefix = "MyTransform";

    public Object transform(Object body) {
        String answer = prefix + " set body:  " + new Date();
        if (verbose) {
            System.out.println(">>>> " + answer);
        }
        LOG.info(">>>> " + answer);
        return answer;
    }

    public boolean isVerbose() {
        return verbose;
    }

    public void setVerbose(boolean verbose) {
        this.verbose = verbose;
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }
}

The context xml file
<?xml version="1.0" encoding="UTF-8"?>


<beans xmlns="http://www.springframework.org/schema/beans";
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
       xmlns:ctx="http://www.springframework.org/schema/context";
       xmlns:camel="http://camel.apache.org/schema/spring";
       xmlns:osgix="http://www.springframework.org/schema/osgi-compendium";
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
       http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
       http://www.springframework.org/schema/osgi-compendium
http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd";>

  <camel:camelContext xmlns="http://camel.apache.org/schema/spring";>
    
    <package>org.apache.servicemix.examples.camel</package>
    
    <route>
      <from uri="timer://springTimer?fixedRate=true&amp;period=9999"/>
      <bean ref="myTransform" method="transform"/>
      <to uri="log:ExampleRouter"/>
    </route>
  </camel:camelContext>

  <bean id="myTransform"
class="org.apache.servicemix.examples.camel.MyTransform">
    <property name="prefix" value="${prefix}"/>
  </bean>
   
    <osgix:cm-properties id="preProps"
persistent-id="org.apache.servicemix.examples">
        <prop key="prefix">MyTransform</prop>
    </osgix:cm-properties>

    <ctx:property-placeholder properties-ref="preProps" />

</beans>


The POM file
<?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>org.apache.servicemix.examples</groupId>
        <artifactId>camel-osgi</artifactId>
        <version>7.0.1</version>

        <packaging>bundle</packaging>
        <name>Apache ServiceMix :: Examples :: Camel OSGi</name>
        <description>Camel example using OSGi instead of JBI</description>

        <dependencies>
                <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-api</artifactId>
                        <version>1.7.25</version>
                        <scope>provided</scope>
                </dependency>
                <dependency>
                        <groupId>org.apache.camel</groupId>
                        <artifactId>camel-core</artifactId>
                        <version>2.18.4</version>
                </dependency>
                <dependency>
                        <groupId>org.apache.camel</groupId>
                        <artifactId>camel-spring</artifactId>
                        <version>2.18.4</version>
                </dependency>
        </dependencies>

        <build>
                <plugins>
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-compiler-plugin</artifactId>
                                <version>2.0.2</version>
                                <configuration>
                                        <source>1.8</source>
                                        <target>1.8</target>
                                </configuration>
                        </plugin>
                        <plugin>
                                <groupId>org.apache.felix</groupId>
                                <artifactId>maven-bundle-plugin</artifactId>
                                <version>3.3.0</version>
                                <extensions>true</extensions>
                                <configuration>
                                        <instructions>
                                                
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                                                
<Bundle-Description>${project.description}</Bundle-Description>
                                                
<Import-Package>*</Import-Package>
                                        
<Private-Package>org.apache.servicemix.examples.camel</Private-Package>
                                        </instructions>
                                </configuration>
                        </plugin>
                </plugins>
        </build>

</project>

The generated manifest.mf
Manifest-Version: 1.0
Bnd-LastModified: 1528632926405
Build-Jdk: 1.8.0_144
Built-By: egouguh
Bundle-Description: Camel example using OSGi instead of JBI
Bundle-ManifestVersion: 2
Bundle-Name: Apache ServiceMix :: Examples :: Camel OSGi
Bundle-SymbolicName: camel-osgi
Bundle-Version: 7.0.1
Created-By: Apache Maven Bundle Plugin
Export-Package: org.apache.servicemix.examples.camel;uses:="org.apache.c
 amel.builder";version="7.0.1"
Import-Package: org.apache.camel.builder;version="[2.21,3)",org.apache.c
 amel.model;version="[2.21,3)",org.apache.camel.spring;version="[2.21,3)
 ",org.slf4j;version="[1.7,2)"
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Tool: Bnd-3.3.0.201609221906

my context file is successfully placed under the spring folder META-INF

Please let me know if you need any additional input from me.  



--
Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html

Reply via email to