Mark
Thank you. I looked at DataSourceRealm.open() took the following lines and put 
them into my custom Realm:
///////////////
if (localDataSource) {
        context = ContextBindings.getClassLoader();
        context = (Context) context.lookup("comp/env");
} else {
        context = getServer().getGlobalNamingContext();
}
DataSource dataSource = (DataSource)context.lookup(dataSourceName);
////////////////

I have the database resources configured in server.xml's <GlobalNamingResources>
so I configure localDataSource to be False.

This seems to be working OK and the Realm is working OK (so far).

Initially I had difficulty with getServer() giving me null. 
To fix it I stopped calling this method from within the Realm's constructor, 
instead I get the DataSource the first time it's needed.

Time will tell if this latest incarnation is more reliable that the other 
versions I've written of this Realm. The first extended JDBCRealm, another 
extends DataSourceRealm, they both work but not 100% of the time.



> -----Original Message-----
> From: Mark Thomas [mailto:ma...@apache.org]
> Sent: 26 November 2014 17:01
> To: Tomcat Users List
> Subject: Re: How can code in a Realm gain access to a Globally Named
> Resource
> 
> On 26/11/2014 16:23, Christopher Schultz wrote:
> 
> <snip/>
> 
> > I'm not sure, but I would guess you can't define a Realm in
> server.xml
> > and use a DataSource defined in context.xml. If the Realm is in
> > server.xml, then you should be able to grab the globally-accessible
> > DataSources by using their existing (global) names.
> 
> You guess wrong.
> 
> Look at the localDataSource attribute for the DataSourceRealm.
> 
> If you (or the OP) then look in the source code for where that
> attribute is used, you'll see how the Realm switches between global and
> local DataSources.
> 
> Mark
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to