tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pid...@pidster.com>
Subject Re: Context.INITIAL_CONTEXT_FACTORY
Date Fri, 02 Feb 2007 18:32:06 GMT
Fran Varin wrote:
> Christopher & Pid-2: 
> 
> I actually have something working although I'm not entirely sure I have a
> complete understanding; there are still some gaps. I found this article -->
> http://wiki.apache.org/tomcat/UsingDataSources    and it helped a great
> deal. 
> 
> Here is what I have done: 
> 
> Step 1 - Using Tomcat's admin console I defined the data source which
> yielded
> the following server.xml
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <Server>
>   <Listener className="org.apache.catalina.core.AprLifecycleListener"/>
>   <Listener
> className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
>   <Listener
> className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
>   <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
>   <GlobalNamingResources>
>     <Environment
>       name="simpleValue"
>       type="java.lang.Integer"
>       value="30"/>
>     <Resource
>       auth="Container"
>       description="User database that can be updated and saved"
>       name="UserDatabase"
>       type="org.apache.catalina.UserDatabase"
>       pathname="conf/tomcat-users.xml"
>       factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
>     <Resource
>       name="jdbc/USER"
>       type="javax.sql.DataSource"
>       driverClassName="COM.ibm.db2.jdbc.app.DB2Driver"
>       password="ecomm1"
>       maxIdle="2"
>       maxWait="5000"
>       username="ecomm1"
>       url="jdbc:db2:USER"
>       maxActive="4"/>
>   </GlobalNamingResources>
>   <Service
>       name="Catalina">
>     <Connector
>         port="8080"
>         redirectPort="8443"
>         minSpareThreads="25"
>         connectionTimeout="20000"
>         maxThreads="150"
>         maxSpareThreads="75">
>     </Connector>
>     <Connector
>         port="8009"
>         redirectPort="8443"
>         protocol="AJP/1.3">
>     </Connector>
>     <Engine
>         defaultHost="localhost"
>         name="Catalina">
>       <Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
>       <Host
>           appBase="webapps"
>           name="localhost">
>       </Host>
>     </Engine>
>   </Service>
> </Server>
> 
> 
> 
> Step 2 - Defined the context.xml as part of the web application (described
> in the 
> tutorial mentioned above).
> 
> <?xml version="1.0" encoding="UTF-8"?>
> 
> <Context>
> 
>   <Resource name="jdbc/USER" auth="Container"
>             type="javax.sql.DataSource" username="xxx" password="xxx"
>             driverClassName="COM.ibm.db2.jdbc.app.DB2Driver" 
>             url="jdbc:db2:USER"
>             maxActive="8" 
>             />
> 
> </Context>

You're duplicating the Resource definition here.
If you define a Global resource, you only need to put a ResourceLink in 
the context xml file.

> Step 3 - Connect to the DB
> 
> I used the datasource name "java:comp/env/jdbc/USER" for the connection and
> this worked fine. 
> 
> 
> 
> 
> So, this process worked and what I'm looking to do next is to figure out a
> way where I can remove the dependency on the context.xml residing in the web
> application. According to what I understand from reading 
> the documentation this should be possible by placing the context.xml entries
> in the context.xml file that resides in Tomcat's "conf" directory. 

Yes.
If you want to make the ResourceLink available in all contexts, add the 
ResourceLink that refers to your global Resource into the conf/context.xml.

The other
> interesting point will be to see if I can remove the user id and password
> from the context.xml entry. We need to externalize those for security
> purposes. So, the best place is to configure them in DB2's configuration
> manager. 

Not sure about that.

Also, the pieces that I don't quite have a handle on is the actual
> look up references (linkages) between all of the moving parts. That is to
> say JNDI->datasource definition. 

Meaning?




> Fran
> 
> 
> 
> 
> 
> 
> 
> Fran Varin wrote:
>> Hi, 
>>
>> We are in the process of trying to use Tomcat 5.5.20 to access an existing
>> DB2 Database. Up until this point the application has been running under
>> WebSphere (We are trying to utilize Tomcat for testing purposes). In
>> WebSphere we can supply an IBM JNDI Factory Class named
>> "com.ibm.websphere.naming.WsnInitialContextFactory" as the
>> "Context.INITIAL_CONTEXT_FACTORY". We can then find our driver and all is
>> well. 
>>
>> Clearly, in Tomcat the above mentioned class does not exist. I've been all
>> over the place trying to find an equivalent class that is part of Tomcat.
>> It boils down to my attempt at using
>> "org.apache.naming.java.javaURLContextFactory". However, when I do I
>> receive "javax.naming.NameNotFoundException: Name jdbc is not bound in
>> this Context:". 
>>
>> I need to resolve this issue in order to move forward with using Tomcat
>> but, cannot seem to find a good example that explains how to do this. I've
>> seen the documents that loosely describe change server.xml and creating a
>> context.xml for the application. But, this seems like the wrong path given
>> the way that we have always proceeded with creating DB connections. So, it
>> has really just added to my confusion. 
>>
>> Any help would be greatly appreciated, 
>>
>> Fran 
>>
>>
> 


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


Mime
View raw message