You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Alan Chaney <al...@compulsivecreative.com> on 2007/12/18 01:44:14 UTC

Problem with locating Datasource using servlet as ROOT in tomcat 6

Hi

I am using Eclipse 3.3, tomcat 6.0.14, linux and Java 1.5

I have a web app which uses a JNDI data source. I wrote a very simple 
test servlet to access the data source and display some values from the 
database. First time around I used a local application context in 
/META-INF/context.xml. This worked fine. I then moved the Resource 
definition to a GlobalNamingResource in server.xml and that worked fine 
with a ResourceRef in context.xml.

All well and good. I then renamed the app to ROOT with a path '/'.

The servlet still responds and renders text correctly at 
http://localhost:8080/ but I get a javax.naming.NameNotFoundException 
regardless of whether the resource definition in context.xml or 
GlobalNamingResource in server.xml and referenced in context.xml. 
Needless to say the database content is no longer displayed.

As a further test I exported the the war files as ROOT.war and deployed 
the war to a tomcat instance. It deployed OK but I still got the naming 
exception. I then deployed the original (non-ROOT) test app to the same 
server and that worked.

It seems that for some reason a ROOT app cannot access a JNDI 
DataSource. Has anyone seen anything like this or has any explanation

The exception report starts;


> Failed to create datasource
> javax.naming.NameNotFoundException: Name wrshowdbLink is not bound in this Context
> 	at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
> 	at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
> 	at org.apache.naming.NamingContext.lookup(NamingContext.java:781)



The context.xml is displayed below:

> <?xml version="1.0" encoding="UTF-8"?>
> <Context >
> 	<ResourceLink name="wrshowdbLink" 
> 		global="jdbc/wrshowdb"
> 		type="javax.sql.DataSource"
> 		
> 		/>
> </Context>

The web.xml for the ROOT app is:

> <?xml version="1.0" encoding="UTF-8"?>
> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
>   <display-name>ROOT</display-name>
>   <welcome-file-list>
>     <welcome-file>index.html</welcome-file>
>     <welcome-file>index.htm</welcome-file>
>     <welcome-file>index.jsp</welcome-file>
>     <welcome-file>default.html</welcome-file>
>     <welcome-file>default.htm</welcome-file>
>     <welcome-file>default.jsp</welcome-file>
>   </welcome-file-list>
>   <servlet>
>     <description>Test of using root jndi</description>
>     <display-name>RootJndi</display-name>
>     <servlet-name>RootJndi</servlet-name>
>     <servlet-class>com.writingshow.test.RootJndi</servlet-class>
>   </servlet>
>   <servlet-mapping>
>     <servlet-name>RootJndi</servlet-name>
>     <url-pattern>/</url-pattern>
>   </servlet-mapping>
> </web-app>

and the GlobalResourceDef is:

> 	<Resource auth="Container" 
> 			driverClassName="org.postgresql.Driver" 
> 			maxActive="20" 
> 			maxIdle="10" 
> 			maxWait="3000" 
> 			name="jdbc/wrshowdb" 
> 			password="xxxxxxx" 
> 			removeAbandoned="true" 
> 			type="javax.sql.DataSource" 
> 			url="jdbc:postgresql://127.0.0.1:5432/wrshowdb" 
> 			username="wrshow"/>


Regards

Alan Chaney


---------------------------------------------------------------------
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


Re: Problem with locating Datasource using servlet as ROOT in tomcat 6

Posted by Alan Chaney <al...@compulsivecreative.com>.
Thanks Gabe,

That seemed to solve the problem in the 'real' deployment. 
Specifically, it seems that you must delete the old ROOT app. I did a rm 
-Rf ROOT in webapps and then my jar deployed properly and created the 
ROOT.xml file in conf/Catalina/localhost as required. Now seems to work 
perfectly. I probably need to understand the deploy/undeploy process in 
more detail.

Still doesn't work properly in Eclipse in that a project with a ROOT 
context throws the naming exception. I suspect that is because of some 
issue with Eclipse and project deployment. I may experiment further but
as long as it works in the proper deployment I don't really care.

Thanks again

Alan Chaney


Gabe Wong wrote:
> Alan Chaney wrote:
>> Hi
>>
>> I am using Eclipse 3.3, tomcat 6.0.14, linux and Java 1.5
>>
>> I have a web app which uses a JNDI data source. I wrote a very simple 
>> test servlet to access the data source and display some values from 
>> the database. First time around I used a local application context in 
>> /META-INF/context.xml. This worked fine. I then moved the Resource 
>> definition to a GlobalNamingResource in server.xml and that worked 
>> fine with a ResourceRef in context.xml.
>>
>> All well and good. I then renamed the app to ROOT with a path '/'.
>>
>> The servlet still responds and renders text correctly at 
>> http://localhost:8080/ but I get a javax.naming.NameNotFoundException 
>> regardless of whether the resource definition in context.xml or 
>> GlobalNamingResource in server.xml and referenced in context.xml. 
>> Needless to say the database content is no longer displayed.
>>
>> As a further test I exported the the war files as ROOT.war and 
>> deployed the war to a tomcat instance. It deployed OK but I still got 
>> the naming exception. I then deployed the original (non-ROOT) test app 
>> to the same server and that worked.
>>
>> It seems that for some reason a ROOT app cannot access a JNDI 
>> DataSource. Has anyone seen anything like this or has any explanation
>>
>> The exception report starts;
>>
>>
>>> Failed to create datasource
>>> javax.naming.NameNotFoundException: Name wrshowdbLink is not bound in 
>>> this Context
>>>     at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
>>>     at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
>>>     at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
>>
>>
>>
>> The context.xml is displayed below:
>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <Context >
>>>     <ResourceLink name="wrshowdbLink"         global="jdbc/wrshowdb"
>>>         type="javax.sql.DataSource"
>>>                />
>>> </Context>
>>
>> The web.xml for the ROOT app is:
>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
>>> xmlns="http://java.sun.com/xml/ns/javaee" 
>>> xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
>>> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
>>> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" 
>>> version="2.5">
>>>   <display-name>ROOT</display-name>
>>>   <welcome-file-list>
>>>     <welcome-file>index.html</welcome-file>
>>>     <welcome-file>index.htm</welcome-file>
>>>     <welcome-file>index.jsp</welcome-file>
>>>     <welcome-file>default.html</welcome-file>
>>>     <welcome-file>default.htm</welcome-file>
>>>     <welcome-file>default.jsp</welcome-file>
>>>   </welcome-file-list>
>>>   <servlet>
>>>     <description>Test of using root jndi</description>
>>>     <display-name>RootJndi</display-name>
>>>     <servlet-name>RootJndi</servlet-name>
>>>     <servlet-class>com.writingshow.test.RootJndi</servlet-class>
>>>   </servlet>
>>>   <servlet-mapping>
>>>     <servlet-name>RootJndi</servlet-name>
>>>     <url-pattern>/</url-pattern>
>>>   </servlet-mapping>
>>> </web-app>
>>
>> and the GlobalResourceDef is:
>>
>>>     <Resource auth="Container"             
>>> driverClassName="org.postgresql.Driver"             maxActive="20" 
>>>             maxIdle="10"             maxWait="3000"             
>>> name="jdbc/wrshowdb"             password="xxxxxxx"             
>>> removeAbandoned="true"             type="javax.sql.DataSource" 
>>>             url="jdbc:postgresql://127.0.0.1:5432/wrshowdb" 
>>>             username="wrshow"/>
>>
> 
> Hi Alan,
> 
> Is there a ./conf/Catalina/host/ROOT.xml?
> 

---------------------------------------------------------------------
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


Re: Problem with locating Datasource using servlet as ROOT in tomcat 6

Posted by Gabe Wong <ga...@ngasi.com>.
Alan Chaney wrote:
> Hi
>
> I am using Eclipse 3.3, tomcat 6.0.14, linux and Java 1.5
>
> I have a web app which uses a JNDI data source. I wrote a very simple 
> test servlet to access the data source and display some values from 
> the database. First time around I used a local application context in 
> /META-INF/context.xml. This worked fine. I then moved the Resource 
> definition to a GlobalNamingResource in server.xml and that worked 
> fine with a ResourceRef in context.xml.
>
> All well and good. I then renamed the app to ROOT with a path '/'.
>
> The servlet still responds and renders text correctly at 
> http://localhost:8080/ but I get a javax.naming.NameNotFoundException 
> regardless of whether the resource definition in context.xml or 
> GlobalNamingResource in server.xml and referenced in context.xml. 
> Needless to say the database content is no longer displayed.
>
> As a further test I exported the the war files as ROOT.war and 
> deployed the war to a tomcat instance. It deployed OK but I still got 
> the naming exception. I then deployed the original (non-ROOT) test app 
> to the same server and that worked.
>
> It seems that for some reason a ROOT app cannot access a JNDI 
> DataSource. Has anyone seen anything like this or has any explanation
>
> The exception report starts;
>
>
>> Failed to create datasource
>> javax.naming.NameNotFoundException: Name wrshowdbLink is not bound in 
>> this Context
>>     at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
>>     at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
>>     at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
>
>
>
> The context.xml is displayed below:
>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <Context >
>>     <ResourceLink name="wrshowdbLink"         global="jdbc/wrshowdb"
>>         type="javax.sql.DataSource"
>>        
>>         />
>> </Context>
>
> The web.xml for the ROOT app is:
>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
>> xmlns="http://java.sun.com/xml/ns/javaee" 
>> xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
>> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
>> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" 
>> version="2.5">
>>   <display-name>ROOT</display-name>
>>   <welcome-file-list>
>>     <welcome-file>index.html</welcome-file>
>>     <welcome-file>index.htm</welcome-file>
>>     <welcome-file>index.jsp</welcome-file>
>>     <welcome-file>default.html</welcome-file>
>>     <welcome-file>default.htm</welcome-file>
>>     <welcome-file>default.jsp</welcome-file>
>>   </welcome-file-list>
>>   <servlet>
>>     <description>Test of using root jndi</description>
>>     <display-name>RootJndi</display-name>
>>     <servlet-name>RootJndi</servlet-name>
>>     <servlet-class>com.writingshow.test.RootJndi</servlet-class>
>>   </servlet>
>>   <servlet-mapping>
>>     <servlet-name>RootJndi</servlet-name>
>>     <url-pattern>/</url-pattern>
>>   </servlet-mapping>
>> </web-app>
>
> and the GlobalResourceDef is:
>
>>     <Resource auth="Container"             
>> driverClassName="org.postgresql.Driver"             maxActive="20" 
>>             maxIdle="10"             maxWait="3000"             
>> name="jdbc/wrshowdb"             password="xxxxxxx"             
>> removeAbandoned="true"             type="javax.sql.DataSource" 
>>             url="jdbc:postgresql://127.0.0.1:5432/wrshowdb" 
>>             username="wrshow"/>
>

Hi Alan,

Is there a ./conf/Catalina/host/ROOT.xml?

-- 
Regards

Gabe Wong
NGASI AppServer Manager
Application server installation and configuration AUTOMATION
http://www.ngasi.com


---------------------------------------------------------------------
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