You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by gourabguha <go...@gmail.com> on 2018/06/13 15:52:57 UTC
log not generated in a active OSGI bundle in Karaf 4.2.0
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&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
Re: log not generated in a active OSGI bundle in Karaf 4.2.0
Posted by XiLai Dai <xl...@talend.com>.
Hi,
Looks like your bundle is in Active but the spring configuration is not loaded, you have to install the spring/camel-spring feature using feature:install command, before you install/deploy your bundle.
One problem I noticed is, the Karaff 4.2.0 includes the spring 5.x by default, but the camel-spring feature require [4.1,5) as spring version range in the latest Camel 2.21.1. you may have to include the spring-legacy feature xml into the Karaf container as it supports spring 4.x.
The other option is using blueprint insteadof spring in your bundle.
Regards
Xilai
________________________________
From: gourabguha <go...@gmail.com>
Sent: Wednesday, June 13, 2018 11:52:57 PM
To: user@karaf.apache.org
Subject: log not generated in a active OSGI bundle in Karaf 4.2.0
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="https://urldefense.proofpoint.com/v2/url?u=http-3A__www.springframework.org_schema_beans&d=DwICAg&c=2w5q_42kFG40MI2alLPgJw&r=vZK0eLZr-qe8l4WRO0-LTg&m=I6BPqGTzJgJQPPpM9EbsDn7urcm7keF7MXeXyztiQI8&s=xKNK8jj528SKH89c-XVDjB9ITzkh_6L9521YIUnsnX0&e="
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="
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.springframework.org_schema_beans&d=DwICAg&c=2w5q_42kFG40MI2alLPgJw&r=vZK0eLZr-qe8l4WRO0-LTg&m=I6BPqGTzJgJQPPpM9EbsDn7urcm7keF7MXeXyztiQI8&s=xKNK8jj528SKH89c-XVDjB9ITzkh_6L9521YIUnsnX0&e=
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.springframework.org_schema_beans_spring-2Dbeans-2D2.0.xsd&d=DwICAg&c=2w5q_42kFG40MI2alLPgJw&r=vZK0eLZr-qe8l4WRO0-LTg&m=I6BPqGTzJgJQPPpM9EbsDn7urcm7keF7MXeXyztiQI8&s=ncleIVV6KvTikEBLQoOMg_1lpdeAiKt2nfBtvYvKpgs&e=
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.springframework.org_schema_context&d=DwICAg&c=2w5q_42kFG40MI2alLPgJw&r=vZK0eLZr-qe8l4WRO0-LTg&m=I6BPqGTzJgJQPPpM9EbsDn7urcm7keF7MXeXyztiQI8&s=6rZ-oNQJlXIjYxpLFR5GZUmNCF7o3RP-nunBrdn8SVk&e=
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.springframework.org_schema_context_spring-2Dcontext.xsd&d=DwICAg&c=2w5q_42kFG40MI2alLPgJw&r=vZK0eLZr-qe8l4WRO0-LTg&m=I6BPqGTzJgJQPPpM9EbsDn7urcm7keF7MXeXyztiQI8&s=bg5sk7F66cGT0hmzpZ1fM_TD5SEmUckVmpuJpYVIvpY&e=
https://urldefense.proofpoint.com/v2/url?u=http-3A__camel.apache.org_schema_spring&d=DwICAg&c=2w5q_42kFG40MI2alLPgJw&r=vZK0eLZr-qe8l4WRO0-LTg&m=I6BPqGTzJgJQPPpM9EbsDn7urcm7keF7MXeXyztiQI8&s=qjAifmyfSW96VomK-asE_rnt3eFZyYX1GHTgDoOQNfI&e=
https://urldefense.proofpoint.com/v2/url?u=http-3A__camel.apache.org_schema_spring_camel-2Dspring.xsd&d=DwICAg&c=2w5q_42kFG40MI2alLPgJw&r=vZK0eLZr-qe8l4WRO0-LTg&m=I6BPqGTzJgJQPPpM9EbsDn7urcm7keF7MXeXyztiQI8&s=ybi-BSPEtwAvsJ2WUIcJDbL4NyQPvblbcabiZ_uF3Ts&e=
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.springframework.org_schema_osgi-2Dcompendium&d=DwICAg&c=2w5q_42kFG40MI2alLPgJw&r=vZK0eLZr-qe8l4WRO0-LTg&m=I6BPqGTzJgJQPPpM9EbsDn7urcm7keF7MXeXyztiQI8&s=9o-U2yHRB7sl81MjZ3wUZOuqPEB3V1nvaRiG-qNgQMI&e=
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.springframework.org_schema_osgi-2Dcompendium_spring-2Dosgi-2Dcompendium.xsd&d=DwICAg&c=2w5q_42kFG40MI2alLPgJw&r=vZK0eLZr-qe8l4WRO0-LTg&m=I6BPqGTzJgJQPPpM9EbsDn7urcm7keF7MXeXyztiQI8&s=KSb0CZ8faDubQp-HYBCVKmfdJAwP0k8W4BA1l822Cf8&e=">
<camel:camelContext xmlns="https://urldefense.proofpoint.com/v2/url?u=http-3A__camel.apache.org_schema_spring&d=DwICAg&c=2w5q_42kFG40MI2alLPgJw&r=vZK0eLZr-qe8l4WRO0-LTg&m=I6BPqGTzJgJQPPpM9EbsDn7urcm7keF7MXeXyztiQI8&s=qjAifmyfSW96VomK-asE_rnt3eFZyYX1GHTgDoOQNfI&e=">
<package>org.apache.servicemix.examples.camel</package>
<route>
<from uri="timer://springTimer?fixedRate=true&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="https://urldefense.proofpoint.com/v2/url?u=http-3A__maven.apache.org_POM_4.0.0&d=DwICAg&c=2w5q_42kFG40MI2alLPgJw&r=vZK0eLZr-qe8l4WRO0-LTg&m=I6BPqGTzJgJQPPpM9EbsDn7urcm7keF7MXeXyztiQI8&s=wmAHwxd9XMdZ104mq2ey1QiaprqnsHdl-qhIZQ-oOOQ&e="
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://urldefense.proofpoint.com/v2/url?u=http-3A__maven.apache.org_maven-2Dv4-5F0-5F0.xsd&d=DwICAg&c=2w5q_42kFG40MI2alLPgJw&r=vZK0eLZr-qe8l4WRO0-LTg&m=I6BPqGTzJgJQPPpM9EbsDn7urcm7keF7MXeXyztiQI8&s=IFoHEzPgy7QLM2Q8K5N5x6Okqbf2JZkd2tCGD8QDTo8&e=">
<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: https://urldefense.proofpoint.com/v2/url?u=http-3A__karaf.922171.n3.nabble.com_Karaf-2DUser-2Df930749.html&d=DwICAg&c=2w5q_42kFG40MI2alLPgJw&r=vZK0eLZr-qe8l4WRO0-LTg&m=I6BPqGTzJgJQPPpM9EbsDn7urcm7keF7MXeXyztiQI8&s=b5m3T5eZx79jFY8_hEf_9_LGNV3xhw4HJ7JD6f9QEE0&e=
As a recipient of an email from Talend, your contact personal data will be on our systems. Please see our contacts privacy notice at Talend, Inc. <https://www.talend.com/contacts-privacy-policy/>