[GLASSFISH-17266] custom resource factory cannot access webmodule during lifecycle events Created: 01/Sep/11  Updated: 21/Oct/11

Status: Open
Project: glassfish
Component/s: jca
Affects Version/s: v2.1
Fix Version/s: None

Type: Bug Priority: Major
Reporter: mangrove Assignee: skgaju
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

jdk6,winxp


Attachments: Zip Archive NetBeansProjects.zip    
Tags: 3_1_x-exclude

 Description   

When one has a custom factory class deployed under domain/lib and a resource is created which uses this factory to create an injectable class located in a webapp, then the following (or similar) exception is thrown during appserver startup:

javax.naming.CommunicationException: serial context communication ex [Root exception is java.lang.ClassNotFoundException: a.Config]
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:438)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.sun.enterprise.naming.NamingManagerImpl.bindObjects(NamingManagerImpl.java:391)
at com.sun.enterprise.web.WebModuleContextConfig.configureResource(WebModuleContextConfig.java:227)
at com.sun.enterprise.web.WebModuleContextConfig.lifecycleEvent(WebModuleContextConfig.java:167)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:159)
at org.apache.catalina.core.StandardContext.init(StandardContext.java:6476)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4977)
at com.sun.enterprise.web.WebModule.start(WebModule.java:353)
at com.sun.enterprise.web.LifecycleStarter.doRun(LifecycleStarter.java:58)
at com.sun.appserv.management.util.misc.RunnableBase.runSync(RunnableBase.java:304)
at com.sun.appserv.management.util.misc.RunnableBase.run(RunnableBase.java:341)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ClassNotFoundException: a.Config
at com.sun.enterprise.util.ConnectorClassLoader.loadClass(ConnectorClassLoader.java:222)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at a.ConfigFactory.getObjectInstance(ConfigFactory.java:21)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:414)
... 17 more

The cause is that when the LifecycleStarter task is created in VirtualServer then the current thread's contextClassLoader is the ConnectorClassLoader and so that's the one which gets inherited by the RunnableBase.

I think if an injectable resource class is allowed to be local to a webapp then the appropriate classLoader should be utilized when doing any kind of work with the factories.

Proposed solution: VirtualServer might set the current thread's contextClassLoader to the webapp's loader every time it creates a runnable task for a WebModule and then set it back to the old value.

Couldn't reproduce it in v3.1. Attached are the factory jar under domain/lib and the webapp and here's the resource entry in domain.xml:

<custom-resource enabled="true" factory-class="a.ConfigFactory" jndi-name="testconfig" object-type="user" res-type="a.Config"/>



 Comments   
Comment by Sanjeeb Sahoo [ 20/Oct/11 ]

This bug is not applicable for 3.1 from what I understand from submitter's note.

Comment by Jagadish [ 21/Oct/11 ]

https://svn.java.net/svn/glassfish~svn/trunk/v2/appserv-tests/devtests/connector/v3/built-in-custom-resources
Above test-case that has a custom resource's factory which loads the JavaBean class copied in domain/lib directory, works fine in GlassFish 3.0 and above.

Marking as not applicable for 3.x and above.

Comment by Jagadish [ 21/Oct/11 ]

Transferring to Gajanan for evaluation in GlassFish 2.x.
Gajanan: Please transfer to appropriate team member.

Generated at Tue Jul 07 12:18:45 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.