You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by David Calavera <da...@gmail.com> on 2010/03/24 19:39:07 UTC

Configuring a database connection pool by source

Hi,

I'm working in an application that uses an embedded tomcat and I'd like to
add a feature to add a connection pool by source but when I run the server
I'm getting this error:

 javax.naming.NoInitialContextException: Need to specify class name in
> environment or system property, or as an applet parameter, or in an
> application resource file:  java.naming.factory.initial


I'm using the tomcat jars for the version 6.0.18, and this is how I'm trying
to do it:

tomcat = new org.apache.catalina.startup.Tomcat() //creates the new server

... // configures the server

StandardContext application = tomcat.addWebapp(); //creates the web
> application

... // configures the web application

resource = org.apache.catalina.deploy.ContextResource() // creates the new
> JNDI resource

... // configures the JNDI resource with the name, type and properties

application.getNamingResources().addResource(resource) // adds the resource
> to the application context


> tomcat.start() //start tomcat


This is more or less the code, seems I'm not configuring anything because
without the resource it works fine.

Can anyone help me?

Thank you

Re: Configuring a database connection pool by source

Posted by David Calavera <da...@gmail.com>.
Thank you guys, I don't know why this thread skipped my inbox.

I already solved the problem, I loaded the contextFactory but I also had to
add the context to the server. This is the source code working:

http://github.com/calavera/trinidad-dbpool/blob/master/lib/trinidad_dbpool/webapp_extension.rb

On Fri, Mar 26, 2010 at 7:39 PM, Muralidhar Yaragalla <
yaragallamurali@gmail.com> wrote:

> Hi basically this happens when you don't provide InitialContexFactory to
> the
> Initialcontext when creating an InitialContext object. If your code resides
> inside tomcat you don't need to do this because it knows where its
> directory
> service is located. But if you want to connect to directory service from
> outside tomcat I am not sure whether you can do it or not? If you want to
> do
> it there is only one way? Find where the implementation of the factory
> interface is. It is responsibility of the service provider to provide its
> implementation. Once you find it create env properties accordingly and pass
> it to InitialContext constructor while creating object for that.
>
> -----Original Message-----
> From: Pid [mailto:pid@pidster.com]
> Sent: Friday, March 26, 2010 6:42 PM
> To: Tomcat Users List
> Cc: David Calavera
> Subject: Re: Configuring a database connection pool by source
>
> On 24/03/2010 18:39, David Calavera wrote:
> > Hi,
> >
> > I'm working in an application that uses an embedded tomcat and I'd like
> to
> > add a feature to add a connection pool by source but when I run the
> server
> > I'm getting this error:
> >
> >   javax.naming.NoInitialContextException: Need to specify class name in
> >> environment or system property, or as an applet parameter, or in an
> >> application resource file:  java.naming.factory.initial
>
> That sounds like you haven't configued the InitialContext via a suitable
> Factory.  I don't think Tomcat embedded does that automatically*, so you
> would need to provide it yourself.
>
>
> p
>
>
> * someone will correct me if I'm wrong.
>
>
>
> > I'm using the tomcat jars for the version 6.0.18, and this is how I'm
> trying
> > to do it:
> >
> > tomcat = new org.apache.catalina.startup.Tomcat() //creates the new
> server
> >
> > ... // configures the server
> >
> > StandardContext application = tomcat.addWebapp(); //creates the web
> >> application
> >
> > ... // configures the web application
> >
> > resource = org.apache.catalina.deploy.ContextResource() // creates the
> new
> >> JNDI resource
> >
> > ... // configures the JNDI resource with the name, type and properties
> >
> > application.getNamingResources().addResource(resource) // adds the
> resource
> >> to the application context
> >
> >
> >> tomcat.start() //start tomcat
> >
> >
> > This is more or less the code, seems I'm not configuring anything because
> > without the resource it works fine.
> >
> > Can anyone help me?
> >
> > Thank you
> >
>
>
> ---------------------------------------------------------------------
> 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
>
>


-- 
David Calavera
http://www.thinkincode.net

RE: Configuring a database connection pool by source

Posted by Muralidhar Yaragalla <ya...@gmail.com>.
Hi basically this happens when you don't provide InitialContexFactory to the
Initialcontext when creating an InitialContext object. If your code resides
inside tomcat you don't need to do this because it knows where its directory
service is located. But if you want to connect to directory service from
outside tomcat I am not sure whether you can do it or not? If you want to do
it there is only one way? Find where the implementation of the factory
interface is. It is responsibility of the service provider to provide its
implementation. Once you find it create env properties accordingly and pass
it to InitialContext constructor while creating object for that.

-----Original Message-----
From: Pid [mailto:pid@pidster.com] 
Sent: Friday, March 26, 2010 6:42 PM
To: Tomcat Users List
Cc: David Calavera
Subject: Re: Configuring a database connection pool by source

On 24/03/2010 18:39, David Calavera wrote:
> Hi,
>
> I'm working in an application that uses an embedded tomcat and I'd like to
> add a feature to add a connection pool by source but when I run the server
> I'm getting this error:
>
>   javax.naming.NoInitialContextException: Need to specify class name in
>> environment or system property, or as an applet parameter, or in an
>> application resource file:  java.naming.factory.initial

That sounds like you haven't configued the InitialContext via a suitable 
Factory.  I don't think Tomcat embedded does that automatically*, so you 
would need to provide it yourself.


p


* someone will correct me if I'm wrong.



> I'm using the tomcat jars for the version 6.0.18, and this is how I'm
trying
> to do it:
>
> tomcat = new org.apache.catalina.startup.Tomcat() //creates the new server
>
> ... // configures the server
>
> StandardContext application = tomcat.addWebapp(); //creates the web
>> application
>
> ... // configures the web application
>
> resource = org.apache.catalina.deploy.ContextResource() // creates the new
>> JNDI resource
>
> ... // configures the JNDI resource with the name, type and properties
>
> application.getNamingResources().addResource(resource) // adds the
resource
>> to the application context
>
>
>> tomcat.start() //start tomcat
>
>
> This is more or less the code, seems I'm not configuring anything because
> without the resource it works fine.
>
> Can anyone help me?
>
> Thank you
>


---------------------------------------------------------------------
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: Configuring a database connection pool by source

Posted by Pid <pi...@pidster.com>.
On 24/03/2010 18:39, David Calavera wrote:
> Hi,
>
> I'm working in an application that uses an embedded tomcat and I'd like to
> add a feature to add a connection pool by source but when I run the server
> I'm getting this error:
>
>   javax.naming.NoInitialContextException: Need to specify class name in
>> environment or system property, or as an applet parameter, or in an
>> application resource file:  java.naming.factory.initial

That sounds like you haven't configued the InitialContext via a suitable 
Factory.  I don't think Tomcat embedded does that automatically*, so you 
would need to provide it yourself.


p


* someone will correct me if I'm wrong.



> I'm using the tomcat jars for the version 6.0.18, and this is how I'm trying
> to do it:
>
> tomcat = new org.apache.catalina.startup.Tomcat() //creates the new server
>
> ... // configures the server
>
> StandardContext application = tomcat.addWebapp(); //creates the web
>> application
>
> ... // configures the web application
>
> resource = org.apache.catalina.deploy.ContextResource() // creates the new
>> JNDI resource
>
> ... // configures the JNDI resource with the name, type and properties
>
> application.getNamingResources().addResource(resource) // adds the resource
>> to the application context
>
>
>> tomcat.start() //start tomcat
>
>
> This is more or less the code, seems I'm not configuring anything because
> without the resource it works fine.
>
> Can anyone help me?
>
> Thank you
>


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