tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Konstantin Kolinko <knst.koli...@gmail.com>
Subject Re: Access GlobalNamingResources using javax.naming
Date Thu, 17 Dec 2009 02:37:39 GMT
2009/12/17 Filip Hanik - Dev Lists <devlists@hanik.com>:
> Is there a way to get hold of the GlobalNamingResources JNDI tree directly
> using the InitialContext?
>
> I see that components like DataSourceRealm go to
> ServerFactory.getServer().getGlobalNamingResources(), but I would like a way
> to do it using standard JNDI APIs
>

I think, that in JNDI there is no such way, unless you have
<ResourceLink> in your context.xml file for the name that you are
trying to access.


Regarding <ResourceLink> implementation,
I do not know whether you would be interested how it works,
but as I've spent some time reviewing it, here is a quick summary

1. <ResourceLink> element -> ContextRuleSet rules create a
ContextResourceLink class instance from it
2. ContextRuleSet is placed into NamingResources class instance
3. NamingContextListener class is where JNDI context is created and
populated. It acts as a listener for the NamingContext. See
NamingContextListener#addResourceLink() -> ResourceLinkRef class
instance is created there and is bound to the JNDI context.

4. ResourceLinkRef is an instance of javax.naming.Reference,  so
o.a.naming.NamingContext.lookup()  uses
NamingManager.getObjectInstance() to resolve a NamingEntry.REFERENCE.

5. The ObjectFactory used to resolve the reference is actually the
o.a.naming.factory.ResourceLinkFactory.
(as ResourceLinkRef#getFactoryClassName() returns that name).

6. ResourceLinkFactory holds a static reference to the global context
and looks the name there.  The global context reference is passed
there by NamingContextListener when it initializes the global context.


> I see that components like DataSourceRealm go to
> ServerFactory.getServer().getGlobalNamingResources(), but I would like a way
> to do it using standard JNDI APIs

I think that ContextBindings.getClassLoader().lookup("comp/env") that
DataSourceRealm does is effectively the same as (new
InitialContext()).lookup("comp/env").

I see ServerFactory.getServer().getGlobalNamingContext() call there,
but do you need to be able to configure your component in the same way
as you do for DataSourceRealm?   I mean, using
DataSourceRealm.localDataSource=false is a bit of a trick.

I think that you can either require that <ResourceLink> be created by
a user, or use RealmBase#container to access the Server. The latter is
how TC 7 DataSourceRealm does it, as there is no ServerFactory in TC
7.


Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message