You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Rob Gregory <Ro...@ibsolutions.com> on 2010/11/17 12:08:35 UTC

Dynamic GlobalNamingResources / Shared JDBC connection pools

Tomcat Users,

 

We are trying to migrate a web application from a single context
containing multiple JDBC datasources to a web application deployed over
multiple contexts but without duplicating the shared datasources.
Reading the docs at
http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.h
tml states that we should be using the GlobalNamingResources but I do
not know how to create these dynamically as we do with the
per-web-application JNDI contexts. The docs explain how to declare them
within the xml files but I need to create them on the fly. Could anyone
point me at some documentation or some hints at what I should be
googling for. One approach I thought about was moving the datasource
code into the shared location of Tomcat but following some posts this
morning it doesn't sound like shared locations should be used by web
apps. Sorry if my question is not clear and thanks for any assistance.  

 

Tomcat 6.0.29 under Java 1.5+

 

Regards

Rob


Re: Dynamic GlobalNamingResources / Shared JDBC connection pools

Posted by Mark Thomas <ma...@apache.org>.
On 18/11/2010 17:02, Rob Gregory wrote:
> Awww... Is there going to be a replacement for the ServerFactory?

You need to get a reference to a Container (Context/Host/Engine) and
then navigate Context->Host->Engine->Service->Server

How you get the reference depends on where you start from.

> Also what sort out timescales are you looking at before a production release of Tomcat 7 is available?

http://markmail.org/message/7nwn6v22hcyikuob

So far, 7.0.4 has gone fairly well. There hasn't yet been anything that
has really worried me. If things go to plan, there should be a 7.0.5
fairly soon.

Mark

> 
> Thanks Again.
> Rob
> 
> 
>> -----Original Message-----
>> From: Mark Thomas [mailto:markt@apache.org]
>> Sent: 18 November 2010 16:59
>> To: Tomcat Users List
>> Subject: Re: Dynamic GlobalNamingResources / Shared JDBC connection pools
>>
>> On 18/11/2010 16:54, Rob Gregory wrote:
>>> Spot on Mark.
>>>
>>> I have been googling and playing around for over a day on this, Following
>> your suggestion it boils down to a couple of lines of code:-
>>>
>>> StandardServer server = (StandardServer) ServerFactory.getServer();
>>> Context context = server.getGlobalNamingContext();
>>> context.bind(dataSourceName, datasource);
>>>
>>> Thanks again for the push in the right direction.
>>
>> No problem. Just be aware ServerFactory is gone in 7.0.x.
>>
>> Mark
>>
>>>
>>> Rob
>>>
>>>
>>>> -----Original Message-----
>>>> From: Mark Thomas [mailto:markt@apache.org]
>>>> Sent: 18 November 2010 10:30
>>>> To: Tomcat Users List
>>>> Subject: Re: Dynamic GlobalNamingResources / Shared JDBC connection pools
>>>>
>>>> On 18/11/2010 09:34, Rob Gregory wrote:
>>>>> Thanks Chris,
>>>>>
>>>>> After messing around with JNDI yesterday I came to the same conclusion
>> that
>>>> Tomcat is doing some isolation
>>>>
>>>> Random thoughts that may or may not help.
>>>>
>>>> If you look in the DataSourceRealm you will see some code that lets a
>>>> web-app use a DataSource from either webapp JNDI or global JNDI. That
>>>> might give you some pointers.
>>>>
>>>> Also, I'm pretty sure there is some write protection applied to the
>>>> global JNDI somewhere. That might also get in your way.
>>>>
>>>> Mark
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
> 


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


RE: Dynamic GlobalNamingResources / Shared JDBC connection pools

Posted by Rob Gregory <Ro...@ibsolutions.com>.
Awww... Is there going to be a replacement for the ServerFactory? 

Also what sort out timescales are you looking at before a production release of Tomcat 7 is available?

Thanks Again.
Rob


> -----Original Message-----
> From: Mark Thomas [mailto:markt@apache.org]
> Sent: 18 November 2010 16:59
> To: Tomcat Users List
> Subject: Re: Dynamic GlobalNamingResources / Shared JDBC connection pools
> 
> On 18/11/2010 16:54, Rob Gregory wrote:
> > Spot on Mark.
> >
> > I have been googling and playing around for over a day on this, Following
> your suggestion it boils down to a couple of lines of code:-
> >
> > StandardServer server = (StandardServer) ServerFactory.getServer();
> > Context context = server.getGlobalNamingContext();
> > context.bind(dataSourceName, datasource);
> >
> > Thanks again for the push in the right direction.
> 
> No problem. Just be aware ServerFactory is gone in 7.0.x.
> 
> Mark
> 
> >
> > Rob
> >
> >
> >> -----Original Message-----
> >> From: Mark Thomas [mailto:markt@apache.org]
> >> Sent: 18 November 2010 10:30
> >> To: Tomcat Users List
> >> Subject: Re: Dynamic GlobalNamingResources / Shared JDBC connection pools
> >>
> >> On 18/11/2010 09:34, Rob Gregory wrote:
> >>> Thanks Chris,
> >>>
> >>> After messing around with JNDI yesterday I came to the same conclusion
> that
> >> Tomcat is doing some isolation
> >>
> >> Random thoughts that may or may not help.
> >>
> >> If you look in the DataSourceRealm you will see some code that lets a
> >> web-app use a DataSource from either webapp JNDI or global JNDI. That
> >> might give you some pointers.
> >>
> >> Also, I'm pretty sure there is some write protection applied to the
> >> global JNDI somewhere. That might also get in your way.
> >>
> >> Mark
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org


Re: Dynamic GlobalNamingResources / Shared JDBC connection pools

Posted by Mark Thomas <ma...@apache.org>.
On 18/11/2010 16:54, Rob Gregory wrote:
> Spot on Mark. 
> 
> I have been googling and playing around for over a day on this, Following your suggestion it boils down to a couple of lines of code:-
> 
> StandardServer server = (StandardServer) ServerFactory.getServer();
> Context context = server.getGlobalNamingContext();
> context.bind(dataSourceName, datasource);
> 
> Thanks again for the push in the right direction.

No problem. Just be aware ServerFactory is gone in 7.0.x.

Mark

> 
> Rob
> 
> 
>> -----Original Message-----
>> From: Mark Thomas [mailto:markt@apache.org]
>> Sent: 18 November 2010 10:30
>> To: Tomcat Users List
>> Subject: Re: Dynamic GlobalNamingResources / Shared JDBC connection pools
>>
>> On 18/11/2010 09:34, Rob Gregory wrote:
>>> Thanks Chris,
>>>
>>> After messing around with JNDI yesterday I came to the same conclusion that
>> Tomcat is doing some isolation
>>
>> Random thoughts that may or may not help.
>>
>> If you look in the DataSourceRealm you will see some code that lets a
>> web-app use a DataSource from either webapp JNDI or global JNDI. That
>> might give you some pointers.
>>
>> Also, I'm pretty sure there is some write protection applied to the
>> global JNDI somewhere. That might also get in your way.
>>
>> Mark
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
> 


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


RE: Dynamic GlobalNamingResources / Shared JDBC connection pools

Posted by Rob Gregory <Ro...@ibsolutions.com>.
Spot on Mark. 

I have been googling and playing around for over a day on this, Following your suggestion it boils down to a couple of lines of code:-

StandardServer server = (StandardServer) ServerFactory.getServer();
Context context = server.getGlobalNamingContext();
context.bind(dataSourceName, datasource);

Thanks again for the push in the right direction. 

Rob


> -----Original Message-----
> From: Mark Thomas [mailto:markt@apache.org]
> Sent: 18 November 2010 10:30
> To: Tomcat Users List
> Subject: Re: Dynamic GlobalNamingResources / Shared JDBC connection pools
> 
> On 18/11/2010 09:34, Rob Gregory wrote:
> > Thanks Chris,
> >
> > After messing around with JNDI yesterday I came to the same conclusion that
> Tomcat is doing some isolation
> 
> Random thoughts that may or may not help.
> 
> If you look in the DataSourceRealm you will see some code that lets a
> web-app use a DataSource from either webapp JNDI or global JNDI. That
> might give you some pointers.
> 
> Also, I'm pretty sure there is some write protection applied to the
> global JNDI somewhere. That might also get in your way.
> 
> Mark
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org


RE: Dynamic GlobalNamingResources / Shared JDBC connection pools

Posted by Rob Gregory <Ro...@ibsolutions.com>.
Thanks Mark.

I'm spoilt for choice now and have some serious reading to do. Between the three suggestions I must be able to come up with a solution to my problem. Thanks to all for the pointers, most helpful.

Rob 

> -----Original Message-----
> From: Mark Thomas [mailto:markt@apache.org]
> Sent: 18 November 2010 10:30
> To: Tomcat Users List
> Subject: Re: Dynamic GlobalNamingResources / Shared JDBC connection pools
> 
> On 18/11/2010 09:34, Rob Gregory wrote:
> > Thanks Chris,
> >
> > After messing around with JNDI yesterday I came to the same conclusion that
> Tomcat is doing some isolation
> 
> Random thoughts that may or may not help.
> 
> If you look in the DataSourceRealm you will see some code that lets a
> web-app use a DataSource from either webapp JNDI or global JNDI. That
> might give you some pointers.
> 
> Also, I'm pretty sure there is some write protection applied to the
> global JNDI somewhere. That might also get in your way.
> 
> Mark
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org


Re: Dynamic GlobalNamingResources / Shared JDBC connection pools

Posted by Mark Thomas <ma...@apache.org>.
On 18/11/2010 09:34, Rob Gregory wrote:
> Thanks Chris,
> 
> After messing around with JNDI yesterday I came to the same conclusion that Tomcat is doing some isolation

Random thoughts that may or may not help.

If you look in the DataSourceRealm you will see some code that lets a
web-app use a DataSource from either webapp JNDI or global JNDI. That
might give you some pointers.

Also, I'm pretty sure there is some write protection applied to the
global JNDI somewhere. That might also get in your way.

Mark

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


RE: Dynamic GlobalNamingResources / Shared JDBC connection pools

Posted by Rob Gregory <Ro...@ibsolutions.com>.
Thanks Pid,

That’s two suggestions for me to try. Many thanks for your assistance.

Rob

> -----Original Message-----
> From: Pid [mailto:pid@pidster.com]
> Sent: 18 November 2010 10:26
> To: Tomcat Users List
> Subject: Re: Dynamic GlobalNamingResources / Shared JDBC connection pools
> 
> On 18/11/2010 09:34, Rob Gregory wrote:
> > Thanks Chris,
> >
> > After messing around with JNDI yesterday I came to the same conclusion that
> Tomcat is doing some isolation and I can understand why. I will look into the
> JMX approach you suggest as I am running out of options. If That doesn't
> provide a solution I think I will have to deploy our connection pool logic to
> the shared 'tomcat/lib' directory where static collections will be available
> to all contexts. Do you see any issues with deploying code within the lib
> directory?
> 
> I'm not sure about static, but maybe you can use a LifecycleListener to
> configure the pool globally.  Check out the Listeners defined at the start of
> server.xml for examples.
> 
> 
> p
> 
> > Many thanks for your help
> > Rob
> >
> >
> >> -----Original Message-----
> >> From: Christopher Schultz [mailto:chris@christopherschultz.net]
> >> Sent: 17 November 2010 16:44
> >> To: Tomcat Users List
> >> Subject: Re: Dynamic GlobalNamingResources / Shared JDBC connection
> >> pools
> >>
> > Rob,
> >
> > On 11/17/2010 7:07 AM, Rob Gregory wrote:
> >>>> Is it possible to just store my existing collection of datasources
> >>>> in some global context?
> >>>>
> >>>> I.e.
> >>>> initCtx = new InitialContext();
> >>>> Context envCtx  = (Context)initCtx.lookup("java:/comp/env");
> >>>> envCtx.bind("datasource_live", objLiveDatasource);
> >>>> envCtx.bind("datasource_test", objTestDatasource);
> >>>>
> >>>> or something along those lines?
> >
> > The above isn't going to work because Tomcat provides webapp isolation
> > in the JNDI space.
> >
> > You should look into the documentation for Tomcat's JMX beans: I'm
> > sure there is a way to use those to create on-the-fly DataSources
> > (really DataSourceFactories I think) using the mbeans that Tomcat exposes.
> > Running under a SecurityManager may complicate that effort.
> >
> > -chris
> >>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org


Re: Dynamic GlobalNamingResources / Shared JDBC connection pools

Posted by Pid <pi...@pidster.com>.
On 18/11/2010 09:34, Rob Gregory wrote:
> Thanks Chris,
> 
> After messing around with JNDI yesterday I came to the same conclusion that Tomcat is doing some isolation and I can understand why. I will look into the JMX approach you suggest as I am running out of options. If That doesn't provide a solution I think I will have to deploy our connection pool logic to the shared 'tomcat/lib' directory where static collections will be available to all contexts. Do you see any issues with deploying code within the lib directory? 

I'm not sure about static, but maybe you can use a LifecycleListener to
configure the pool globally.  Check out the Listeners defined at the
start of server.xml for examples.


p

> Many thanks for your help
> Rob
> 
> 
>> -----Original Message-----
>> From: Christopher Schultz [mailto:chris@christopherschultz.net]
>> Sent: 17 November 2010 16:44
>> To: Tomcat Users List
>> Subject: Re: Dynamic GlobalNamingResources / Shared JDBC connection pools
>>
> Rob,
> 
> On 11/17/2010 7:07 AM, Rob Gregory wrote:
>>>> Is it possible to just store my existing collection of datasources in
>>>> some global context?
>>>>
>>>> I.e.
>>>> initCtx = new InitialContext();
>>>> Context envCtx  = (Context)initCtx.lookup("java:/comp/env");
>>>> envCtx.bind("datasource_live", objLiveDatasource);
>>>> envCtx.bind("datasource_test", objTestDatasource);
>>>>
>>>> or something along those lines?
> 
> The above isn't going to work because Tomcat provides webapp isolation
> in the JNDI space.
> 
> You should look into the documentation for Tomcat's JMX beans: I'm sure
> there is a way to use those to create on-the-fly DataSources (really
> DataSourceFactories I think) using the mbeans that Tomcat exposes.
> Running under a SecurityManager may complicate that effort.
> 
> -chris
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Dynamic GlobalNamingResources / Shared JDBC connection pools

Posted by Rob Gregory <Ro...@ibsolutions.com>.
Thanks Chris,

After messing around with JNDI yesterday I came to the same conclusion that Tomcat is doing some isolation and I can understand why. I will look into the JMX approach you suggest as I am running out of options. If That doesn't provide a solution I think I will have to deploy our connection pool logic to the shared 'tomcat/lib' directory where static collections will be available to all contexts. Do you see any issues with deploying code within the lib directory? 

Many thanks for your help
Rob


> -----Original Message-----
> From: Christopher Schultz [mailto:chris@christopherschultz.net]
> Sent: 17 November 2010 16:44
> To: Tomcat Users List
> Subject: Re: Dynamic GlobalNamingResources / Shared JDBC connection pools
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Rob,
> 
> On 11/17/2010 7:07 AM, Rob Gregory wrote:
> > Is it possible to just store my existing collection of datasources in
> > some global context?
> >
> > I.e.
> > initCtx = new InitialContext();
> > Context envCtx  = (Context)initCtx.lookup("java:/comp/env");
> > envCtx.bind("datasource_live", objLiveDatasource);
> > envCtx.bind("datasource_test", objTestDatasource);
> >
> > or something along those lines?
> 
> The above isn't going to work because Tomcat provides webapp isolation
> in the JNDI space.
> 
> You should look into the documentation for Tomcat's JMX beans: I'm sure
> there is a way to use those to create on-the-fly DataSources (really
> DataSourceFactories I think) using the mbeans that Tomcat exposes.
> Running under a SecurityManager may complicate that effort.
> 
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iEYEARECAAYFAkzkBlwACgkQ9CaO5/Lv0PAh5wCeKQssMRezSzwagZ9AmCZuZf/5
> 5gwAoMPy5pYlKYgyYM6UNh/nnH3DAZiI
> =jH6U
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org


Re: Dynamic GlobalNamingResources / Shared JDBC connection pools

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Rob,

On 11/17/2010 7:07 AM, Rob Gregory wrote:
> Is it possible to just store my existing collection of datasources in
> some global context? 
> 
> I.e. 
> initCtx = new InitialContext();  
> Context envCtx  = (Context)initCtx.lookup("java:/comp/env");
> envCtx.bind("datasource_live", objLiveDatasource);
> envCtx.bind("datasource_test", objTestDatasource);
> 
> or something along those lines?

The above isn't going to work because Tomcat provides webapp isolation
in the JNDI space.

You should look into the documentation for Tomcat's JMX beans: I'm sure
there is a way to use those to create on-the-fly DataSources (really
DataSourceFactories I think) using the mbeans that Tomcat exposes.
Running under a SecurityManager may complicate that effort.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkzkBlwACgkQ9CaO5/Lv0PAh5wCeKQssMRezSzwagZ9AmCZuZf/5
5gwAoMPy5pYlKYgyYM6UNh/nnH3DAZiI
=jH6U
-----END PGP SIGNATURE-----

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


RE: Dynamic GlobalNamingResources / Shared JDBC connection pools

Posted by Rob Gregory <Ro...@ibsolutions.com>.
Is it possible to just store my existing collection of datasources in
some global context? 

I.e. 
initCtx = new InitialContext();  
Context envCtx  = (Context)initCtx.lookup("java:/comp/env");
envCtx.bind("datasource_live", objLiveDatasource);
envCtx.bind("datasource_test", objTestDatasource);

or something along those lines?

Thanks
Rob


> -----Original Message-----
> From: Rob Gregory [mailto:Rob.Gregory@ibsolutions.com]
> Sent: 17 November 2010 11:09
> To: Tomcat Users List
> Subject: Dynamic GlobalNamingResources / Shared JDBC connection pools
> 
> Tomcat Users,
> 
> 
> 
> We are trying to migrate a web application from a single context
> containing multiple JDBC datasources to a web application deployed
over
> multiple contexts but without duplicating the shared datasources.
> Reading the docs at
>
http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.h
> tml states that we should be using the GlobalNamingResources but I do
> not know how to create these dynamically as we do with the
> per-web-application JNDI contexts. The docs explain how to declare
them
> within the xml files but I need to create them on the fly. Could
anyone
> point me at some documentation or some hints at what I should be
> googling for. One approach I thought about was moving the datasource
> code into the shared location of Tomcat but following some posts this
> morning it doesn't sound like shared locations should be used by web
> apps. Sorry if my question is not clear and thanks for any assistance.
> 
> 
> 
> Tomcat 6.0.29 under Java 1.5+
> 
> 
> 
> Regards
> 
> Rob


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