Bug 996560

Summary: Cannot initialize kmodule in beans.xml during deployment
Product: [Retired] JBoss BPMS Platform 6 Reporter: Ivo Bek <ibek>
Component: jBPM CoreAssignee: Mario Fusco <mfusco>
Status: CLOSED CURRENTRELEASE QA Contact: Ivo Bek <ibek>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.0.0CC: rrajasek, rzhang
Target Milestone: ER3Keywords: TestBlocker
Target Release: 6.0.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-08-06 20:07:07 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Ivo Bek 2013-08-13 12:47:03 UTC
Description of problem:

I tried to create my own web application with kie-spring integration but during deployment it throws following exception:

Caused by: java.lang.IllegalArgumentException: Could not find a KModule (defaultClasspathKContainer is null). 
	at org.kie.spring.KieObjectsResolver.resolveKContainer(KieObjectsResolver.java:76) [kie-spring-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
	at org.kie.spring.KieObjectsResolver.resolveKBase(KieObjectsResolver.java:50) [kie-spring-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]

The reason is on line 46 here https://github.com/droolsjbpm/droolsjbpm-integration/blob/master/kie-spring/src/main/java/org/kie/spring/KieObjectsResolver.java#L46 , the defaultClasspathKContainer inicialization code is commented.

However this fix is not enough to deploy the app.

The next exception I receive is:

Caused by: java.lang.NullPointerException
	at org.drools.compiler.kie.builder.impl.KieContainerImpl.createKieBase(KieContainerImpl.java:199) [drools-compiler-6.0.0-SNAPSHOT.jar:6.0.0-SNAPSHOT]
	at org.drools.compiler.kie.builder.impl.KieContainerImpl.getKieBase(KieContainerImpl.java:167) [drools-compiler-6.0.0-SNAPSHOT.jar:6.0.0-SNAPSHOT]
	at org.kie.spring.KieObjectsResolver.resolveKBase(KieObjectsResolver.java:51) [kie-spring-6.0.0-SNAPSHOT.jar:6.0.0-SNAPSHOT]

I think that the kBaseModel is null on line 199 in the KieContainerImpl https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/main/java/org/drools/compiler/kie/builder/impl/KieContainerImpl.java#L199

The spring context is created by default in the web application by org.springframework.web.context.ContextLoaderListener, so there is no initialization of post processor beans such as KModuleBeanFactoryPostProcessor. So it uses the default container.

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


How reproducible:

Steps to Reproduce:
1. Clone https://github.com/ibek/droolsjbpm-integration/tree/6.0.x/
2. Build drools-camel-server-example
3. Run Tests
4. See following exception:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ksession1': Cannot resolve reference to bean 'kbase1' while setting bean property 'kBase'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kbase1': Invocation of init method failed; nested exception is java.lang.NullPointerException
	at org.drools.compiler.kie.builder.impl.KieContainerImpl.createKieBase(KieContainerImpl.java:199)

FYI tests in kie-spring works just because they use different way how to create spring context. So, you can try that it works when you uncomment lines in CxfRSClientServerTest like below:

//ReleaseId releaseId = new ReleaseIdImpl("sample-group","test-spring","001");
//URL configFileURL = CxfRsClientServerTest.class.getResource("/beans.xml");
//ApplicationContext springContext = InternalKieSpringUtils.getSpringContext(releaseId,configFileURL);

Actual results:


Expected results:


Additional info:

Comment 1 Mario Fusco 2013-08-19 10:35:54 UTC
I cloned your repo and tried what you did. The only missing bit in your migration attempt is the registration of the kiePostProcessor in the spring context, i.e. adding this: 

<bean id="kiePostProcessor" class="org.kie.spring.KModuleBeanFactoryPostProcessor"/>

to the beans.xml file should fix your problem.

If you can confirm it fixes your problem (or even if it doesn't and then requires further investigation) it would be great if you could send a proper pull request so I could merge the migration of drools-camel-server-example to the new kie-spring and kie-camel modules on the master branch.

Comment 2 Ivo Bek 2013-08-19 11:55:43 UTC
Hi Mario,

thank you, the added bean helped and the test passed. However I wasn't successful with the deployment. Now, I receive NPE when the KModuleFactory is trying to get POM properties file:

at org.drools.compiler.kie.builder.impl.ClasspathKieProject.getPomProperties(ClasspathKieProject.java:240) [drools-compiler-6.0.0-SNAPSHOT.jar:6.0.0-SNAPSHOT]
	at org.kie.spring.KModuleBeanFactoryPostProcessor.postProcessBeanFactory(KModuleBeanFactoryPostProcessor.java:84) [kie-spring-6.0.0-SNAPSHOT.jar:6.0.0-SNAPSHOT]

I think it's because it searches the pom.properties at wrong location. The root path is /content/drools-camel-server-example-6.0.0-SNAPSHOT.war/WEB-INF/classes/ but the pom.properties is in /content/drools-camel-server-example-6.0.0-SNAPSHOT.war/META-INF/maven/org.drools/drools-camel-server-example/pom.properties.

I read this information from the following warning in the server log:

12:58:01,639 WARN  [org.drools.compiler.kie.builder.impl.ClasspathKieProject] (ServerService Thread Pool -- 82) Unable to load pom.properties tried recursing down from/content/drools-camel-server-example-6.0.0-SNAPSHOT.war/WEB-INF/classes/
null

Of course, I will create the pull request but first I want to do some cleaning of source code because I use the example for experimenting now.

Comment 3 Ivo Bek 2013-08-19 13:30:40 UTC
In fact, the pom.xml cannot be found at the location. I tried to copy the pom.xml and pom.properties into classes just to check whether it will help and it really did, I successfully deployed the web app. So after all there is just the issue with pom files.

Comment 4 Mario Fusco 2013-08-20 12:55:29 UTC
Hi Ivo,

I believe this last issue is strictly related (if not the same) with this one found by Marek:

https://bugzilla.redhat.com/show_bug.cgi?id=996144

I'll try to fix that one first and hopefully this should also solve your problem. I'll keep you updated.

Comment 5 Ivo Bek 2013-08-21 09:21:15 UTC
Yep, it seems they are same. I noticed that the workaround works only when the war is deployed as a folder like business central. So I recommend to consider both options, the war archive and folder.

Comment 7 Ivo Bek 2013-09-23 12:54:09 UTC
Verified in BPMS 6.0.0.ER3