Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 1186354

Summary: WLS: KIE-CDI fails to load kmodules bundled within the WAR
Product: [Retired] JBoss BRMS Platform 6 Reporter: Marek Winkler <mwinkler>
Component: BREAssignee: Maciej Swiderski <mswiders>
Status: CLOSED WONTFIX QA Contact: Marek Winkler <mwinkler>
Severity: high Docs Contact:
Priority: high    
Version: 6.1.0CC: kverlaen, mswiders, rrajasek
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-01-29 09:57:22 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:
Attachments:
Description Flags
Exception thrown during deployment
none
Reproducer maven project
none
server log part when using ClasspathKieContainer
none
Reproducer maven project - fixed
none
reproducer with class loader swap none

Description Marek Winkler 2015-01-27 13:54:16 UTC
Created attachment 984680 [details]
Exception thrown during deployment

Description of problem:

When attempting to inject a KieSession or KieBase through KIE-CDI on WebLogic, KIE-CDI is unable to locate any kmodules defined in jars located in WEB-INF/lib.

It does not work for KieContainers created both from the classpath, or by given ReleaseId. Please see the attached reproducer for details and the attached stacktrace for the exception thrown by Weld.

Please be aware, that if you have kie-ci jar bundled within the application, then kie-ci is able to download the kmodule jar from local maven repository (provided you had built the project using that local Maven repository). For that reason, kie-ci dependency is commented out in the reproducer. Also, this use-case (downloading artifacts using kie-ci) is not affected by this issue.

The same reproducer works on EAP 6.3.

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

How reproducible:
always

Steps to Reproduce:
1. build attached maven reproducer project (mvn clean install)
2. start WLS
3. deploy web-app/target/kie-cdi-war-web-app-1.0.0-SNAPSHOT.war to WLS
   -- I have also tried to deploy the WAR as exploded, but it did not help - as expected
4. watch the errors in server log/ console

Actual results:

Server log contains errors "Cannot find KieModule: org.kie.examples:kie-cdi-war-kie-module:1.0.0-SNAPSHOT"

Expected results:

The application deploys fine and server log contains messages "KieSession from classpath injected." and "KieSession from kJar injected.".

Comment 1 Marek Winkler 2015-01-27 13:55:54 UTC
Created attachment 984681 [details]
Reproducer maven project

Comment 2 Marek Winkler 2015-01-27 14:13:12 UTC
I have verified using debugger that the Drools CDI extension gets activated: 

- in case that you are trying to inject a KieModule with @KReleaseId, the KieContainer created at line [1] is null,

- in case that you are trying to inject a KieSession without using @KReleaseId (i.e. using ClasspathKieContainer, I assume), the kSessionModel is null on line [2]. It seems that in this case ClasspathKieContainer is created but does not define any KieBases or KieSessions.

[1] https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/main/java/org/drools/compiler/cdi/KieCDIExtension.java#L273

[2] https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/main/java/org/drools/compiler/cdi/KieCDIExtension.java#L414

Comment 3 Marek Winkler 2015-01-27 14:18:54 UTC
Created attachment 984684 [details]
server log part when using ClasspathKieContainer

Attaching a server log part displaying the error in case when ClasspathKieContainer is used. In this case WELD complains about unsatisfied dependency:

WELD-001408 Unsatisfied dependencies for type [KieSession] with qualifiers [@KSession] at injection point [[field] @Inject @KSession private org.kie.examples.cdi.webapp.SimpleBean.basicKieSession]

You can see the following KieCDIExtension error in the log indicating that no appropriate KieSession has been found in any kmodule.xml - which probably means that the kmodule.xml has not been accessible (due to WLS classloading) to KIE-CDI:

Jan 27, 2015 2:05:15 PM org.drools.compiler.cdi.KieCDIExtension addKSessionBean
SEVERE: Annotation @KSession(basicKSession) found, but no KieSessioneModel exist.
Either the required kproject.xml does not exist, was corrupted, or mising the KieBase entry

Comment 5 Marek Winkler 2015-01-27 14:34:04 UTC
Created attachment 984686 [details]
Reproducer maven project - fixed

Attaching fixed reproducer (runnable without an error on EAP as well).

Comment 6 Maciej Swiderski 2015-01-28 16:53:13 UTC
Marek,

the issue is with weblogic class loader that is given on application start - it does not provide access to the application jars and thus it cannot find the kjars on class path. Same issue we have in business and the solution was to include CDI extension that will swap class loader temporarly to load the application with correct class loader.

While this is fine to have in business central as we provide complete set of classes not sure if we can apply that here. Though in case we cannot find anything better that should be documented. See attached enhanced reproducer that works fine on Weblogic. 

for reference here is the class we use in business central [1] not it must be enabled via javax.enterprise.inject.spi.Extension file (META-INF/services) [2]

[1]https://github.com/droolsjbpm/kie-wb-distributions/blob/master/kie-wb/kie-wb-webapp/src/main/java/org/kie/workbench/backend/weblogic/SwapClassloaderExtension.java
[2] https://github.com/droolsjbpm/kie-wb-distributions/blob/master/kie-wb/kie-wb-distribution-wars/src/main/assembly/weblogic12/WEB-INF/classes/META-INF/services/javax.enterprise.inject.spi.Extension#L2

Comment 7 Maciej Swiderski 2015-01-28 16:54:18 UTC
Created attachment 985230 [details]
reproducer with class loader swap

Comment 9 Marek Winkler 2015-01-29 09:09:40 UTC
Maciej, thanks for explaining this! I'll try the workaround.

I agree that we should document this, I'll open a new doc BZ for that.

Comment 11 Marek Winkler 2015-01-29 09:57:22 UTC
Created documentation BZ 1187049 and verified Maciej's workaround.

Comment 12 Marek Winkler 2015-01-29 11:27:33 UTC
Maciej,

I have come across a document describing WLS classloading configuration in a xml descriptor [1], see an excerpt:

...

  3. You can create custom classloader hierarchies for an application allowing for better control over class visibility and reloadability. You achieve this by defining a classloader-structure element in the weblogic-application.xml deployment descriptor file. See details [2].

...

You are probably aware of this, just in case you were not - do you think such a configuration could replace the SwapClassloaderExtension? I do not think it is necessary, it could just be a bit cleaner solution in my opinion. What do you think?

[1] http://xmlandmore.blogspot.cz/2011/01/weblogics-classloading-framework.html

[2] http://docs.oracle.com/cd/E12839_01/web.1111/e13706/classloading.htm#WLPRG282

Comment 13 Maciej Swiderski 2015-02-02 18:14:44 UTC
Marek,

not sure that this will actually help as the problem is only during startup and not while application is running. Though I haven't verified that so cannot be sure. Maybe we could get some info from Oracle as support ticket as this is rather internal thing to web logic and I don't feel confident in digging so much in that :)