Bug 1043888 - OSGi: KieContainer cannot find KieModule defined in the same OSGi bundle
Summary: OSGi: KieContainer cannot find KieModule defined in the same OSGi bundle
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: JBoss BRMS Platform 6
Classification: Retired
Component: BRE
Version: 6.0.0
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: ER1
: 6.0.1
Assignee: Mario Fusco
QA Contact: Marek Winkler
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-12-17 12:08 UTC by Marek Winkler
Modified: 2014-08-06 19:58 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2014-08-06 19:58:45 UTC
Type: Bug


Attachments (Terms of Use)
Stacktrace from <jboss_esb>/data/log/fuse.log (3.91 KB, text/plain)
2013-12-17 12:08 UTC, Marek Winkler
no flags Details
Maven project with reproducer (8.79 KB, application/zip)
2013-12-17 12:08 UTC, Marek Winkler
no flags Details

Description Marek Winkler 2013-12-17 12:08:09 UTC
Created attachment 837642 [details]
Stacktrace from <jboss_esb>/data/log/fuse.log

Description of problem:

When an OSGi bundle defines some kmodule (by containing META-INF/kmodule.xml), and I try to create a KieClasspathContainer, it does not see the KieModule defined in kmodule.xml. 

It does not matter if I use KieServices.newKieClasspathContainer() or KieServices.newKieContainer(ReleaseId). It also does not matter if I use default KieBase, or attempt to get one by specifying its name.

See the attached maven project with reproducer for more details.

Version-Release number of selected component (if applicable):

BRMS 6.0.0 ER5
Drools 6.0.0-SNAPSHOT
JBoss Fuse 6.0.0

Steps to Reproduce:

1. Build attached maven project (mvn clean install) - you might want to adjust the drools.version property in the pom. If you want to build with product binaries, the build requires VPN. 

2. Run JBoss Fuse (<jboss_fuse_dir>/bin/fuse)

3. Execute the following commands:

   features:addurl mvn:org.kie.examples/kie-osgi-sample/1.0.0-SNAPSHOT/xml/features

   features:install my-kie-osgi-sample

Actual results:

Bundle activation fails with the message:

Error executing command: Could not start bundle mvn:org.kie.examples/kie-osgi-sample/1.0.0-SNAPSHOT in feature(s) my-kie-osgi-sample-6.0.0-redhat-6: Activator start error in bundle kie-osgi-sample [197].

The log file contains (see the attachment for the whole stacktrace):

java.lang.RuntimeException: Cannot find a defualt KieBase
	at org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieBase(KieContainerImpl.java:217)[168:org.drools.compiler:6.0.0.redhat-6]

Expected results:

Bundle activation succeeds and the message "KieSession created." is printed in the Fuse console.

(Use "features:uninstall my-kie-osgi-sample" to dispose of the created KieSession.)

Comment 1 Marek Winkler 2013-12-17 12:08:57 UTC
Created attachment 837643 [details]
Maven project with reproducer

Comment 2 Mario Fusco 2014-01-20 15:46:02 UTC
Fixed by https://github.com/droolsjbpm/droolsjbpm-integration/commit/d44b21b7b

Be aware that the pom.xml file of the attached test case is wrong since it doesn't add the resource folder to the jar when packaging the project. To fix this problem is enough to add the following to the pom.xml itself:

      <resource>
        <directory>${project.basedir}/src/main/resources</directory>
        <filtering>false</filtering>
      </resource>

Comment 3 Mario Fusco 2014-01-21 12:31:26 UTC
I tested that the provided solution works with fuse, but I also found that it doesn't with karaf. However to make it work also with karaf it is sufficient to add the following statement

Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

before creating the KieClasspathContainer in the project's code.

We are discussing if this is enough or we will need a more structural solution.

Comment 4 Mario Fusco 2014-01-21 18:08:38 UTC
We decided that relying on the Thread context ClassLoader was too fragile so I added the possibility to specify your custom ClassLoader when creating a new KieContainer from the classpath. This means that know it is possible to create the KieBase used in the attached example just doing:

KieBase kbase = ks.newKieClasspathContainer(getClass().getClassLoader()).getKieBase();

I implemented this feature here https://github.com/droolsjbpm/droolsjbpm-knowledge/commit/1cf6aa7ad and https://github.com/droolsjbpm/drools/commit/cc0cbd707

Comment 6 Marek Winkler 2014-02-26 16:39:13 UTC
Verified on BRMS 6.0.1 ER1.


Note You need to log in before you can comment on or make changes to this bug.