You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Stanley Bradbury <St...@gmail.com> on 2005/10/20 03:06:33 UTC
Re: Trouble finding Datsource Resource with DataSourceRealm
GB Developer wrote:
>My Tomcat's having trouble finding the JNDI Datasource to use for a
>DataSourceRealm.
>
>Details:
>
>Tomcat 5.0.28
>Java 1.4.2_04-b05
>on Linux
>
>
>partial server.xml:
>
><Server port="xxxxx" shutdown="SHUTDOWN" debug="0">
>
> <GlobalNamingResources>
><!-- I removed this file-based resource -->
> </GlobalNamingResources>
>
> <Service name="Catalina">
> <Connector port="xxxxx"
> ....snip....
> />
>
> <Engine name="Catalina" defaultHost="localhost" debug="9999"
>jvmRoute="xpq">
>
> <!-- I removed the realm here that uses the global file-based resource
>-->
> <Logger className="org.apache.catalina.logger.FileLogger"
> prefix="engine_log." suffix=".txt"
> timestamp="true"/>
>
><Host name="localhost" debug="0" appBase="webapps" />
>
><Host name="foo.globallyboundless.com" debug="99">
>
>
><Context path=""
> docBase="/path/to/foo/"
> defaultSessionTimeOut="60"
> reloadable="true" debug="99">
>
>
><Realm className="org.apache.catalina.realm.DataSourceRealm" debug="99"
> dataSourceName="sql/DataSource"
> userTable="user_" userNameCol="_userName"
>userCredCol="_userPassword"
> userRoleTable="user_role" roleNameCol="roleName"/>
>
> <Resource name="sql/DataSource" auth="Container"
>type="javax.sql.DataSource"/>
> <ResourceParams name="sql/DataSource">
> <parameter>
> <name>factory</name>
> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
> </parameter>
> <parameter>
> <name>username</name>
> <value>username</value>
> </parameter>
> <parameter>
> <name>password</name>
> <value>secret</value>
> </parameter>
> <parameter>
> <name>driverClassName</name>
> <value>com.mysql.jdbc.Driver</value>
> </parameter>
> <parameter>
> <name>url</name>
> <value>jdbc:mysql://xxx.xxx.xxx.xxx:xxxx/yyyy?autoReconnect=true</value>
> </parameter>
>.... snip DBCP params....
> </ResourceParams>
>
>
> <Resource name="mail/Session" auth="Container" type="javax.mail.Session"/>
> <ResourceParams name="mail/Session">
> <parameter>
> <name>mail.smtp.host</name>
> <value>yyyy.globallyboundless.com</value>
> </parameter>
> </ResourceParams>
>
></Context>
>
></Host>
>
>
> </Engine>
>
> </Service>
>
></Server>
>
>
>
>
>web.xml is (I think) not useful in diagnosis.
>
>I remove all files from the logs directory, and restart the server. The
>entire contents of catalina.out, (hopefully) formatted for readability. So
>the only thing different between this and the actual output is whitespace
>and newlines.
>
>mikec@tbird:/usr/tomcat51/logs$ cat engine_log.2005-10-19.txt
>
>2005-10-19 18:08:12
>NamingContextListener[/Catalina/foo.globallyboundless.com]:
>Resource parameters for sql/DataSource = ResourceParams[
> name=sql/DataSource,
> parameters={url=jdbc:mysql://xxx.xxx.xxx.xxx:xxxx/yyyy?autoReconnect=true,
>
> maxIdle=5,
> maxActive=5,
> driverClassName=com.mysql.jdbc.Driver,
> maxWait=5000,
> removeAbandoned=true,
> username=secret,
> factory=org.apache.commons.dbcp.BasicDataSourceFactory,
> logAbandoned=true,
> removeAbandonedTimeout=15,
> password=password}]
>
>2005-10-19 18:08:12
>NamingContextListener[/Catalina/foo.globallyboundless.com]:
>Adding resource ref sql/DataSource
>
>2005-10-19 18:08:12
>NamingContextListener[/Catalina/foo.globallyboundless.com]:
>ResourceRef[className=javax.sql.DataSource,
> factoryClassLocation=null,
> factoryClassName=org.apache.naming.factory.ResourceFactory,
> {type=scope,content=Shareable},
> {type=auth,content=Container},
>
>{type=url,content=jdbc:mysql://xxx.xxx.xxx.xxx:xxxx/yyyy?autoReconnect=true}
>,
> {type=maxIdle,content=5},
> {type=maxActive,content=5},
> {type=driverClassName,content=com.mysql.jdbc.Driver},
> {type=maxWait,content=5000},
> {type=removeAbandoned,content=true},
> {type=username,content=secret},
> {type=factory,content=org.apache.commons.dbcp.BasicDataSourceFactory},
> {type=logAbandoned,content=true},
> {type=removeAbandonedTimeout,content=15},
> {type=password,content=password}]
>
>2005-10-19 18:08:12
>NamingContextListener[/Catalina/foo.globallyboundless.com]:
>Resource parameters for mail/Session = ResourceParams[
> name=mail/Session,
> parameters={mail.smtp.host=yyyy.globallyboundless.com}]
>
>2005-10-19 18:08:12
>NamingContextListener[/Catalina/foo.globallyboundless.com]:
>Adding resource ref mail/Session
>
>2005-10-19 18:08:12
>NamingContextListener[/Catalina/foo.globallyboundless.com]:
>ResourceRef[className=javax.mail.Session,
> factoryClassLocation=null,
> factoryClassName=org.apache.naming.factory.ResourceFactory,
> {type=scope,content=Shareable},
> {type=auth,content=Container},
> {type=mail.smtp.host,content=yyyy.globallyboundless.com}]
>
>2005-10-19 18:08:12
>NamingContextListener[/Catalina/foo.globallyboundless.com]:
>Resource parameters for UserTransaction = null
>
>
>
>So you can see from the output everything seems good, though the Realm not
>showing up is strange. But it is being configured, because when I browse to
>http://foo.globallyboundless.com, it tries to authenticate (the browser
>throws up the BASIC dialog box), but it fails with this in the engine log:
>
>
>2005-10-19 18:11:43 DataSourceRealm[]: Exception performing authentication
>javax.naming.NameNotFoundException: Name sql is not bound in this Context
> at org.apache.naming.NamingContext.lookup(NamingContext.java:768)
> at org.apache.naming.NamingContext.lookup(NamingContext.java:151)
> at
>org.apache.catalina.realm.DataSourceRealm.open(DataSourceRealm.java:437)
> at
>org.apache.catalina.realm.DataSourceRealm.authenticate(DataSourceRealm.java:
>277)
> at
>org.apache.catalina.authenticator.BasicAuthenticator.authenticate(BasicAuthe
>nticator.java:129)
> at
>org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase
>.java:504)
> at
>org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex
>t.java:102)
> at
>org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
> at
>org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137
>)
> at
>org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex
>t.java:104)
> at
>org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118
>)
> at
>org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex
>t.java:102)
> at
>org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
> at
>org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
>:109)
> at
>org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex
>t.java:104)
> at
>org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
> at
>org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
> at
>org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
> at
>org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:300)
> at
>org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:374)
> at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:743)
> at
>org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)
> at
>org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:866)
> at
>org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav
>a:684)
> at java.lang.Thread.run(Thread.java:534)
>
>
>
>I've tried swapping the order of the Realm and DataSource config, thinking
>perhaps it needed to be first in the parsing of server.xml.
>
>nothing illuminating in catalina.out.
>
>Any thoughts on how to see realm debug info?
>
>Is there anything wrong with my config of the DataSourceRealm Realm or the
>DataSource Resource in server.xml ?
>
>I'm stumped!
>
>(watch, I'll have a typo somewhere!)
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
>
Hi -
I had a similar problem (with 5.5.12) that turned out to be related to
restart persistence (see post 10/17 Subj: "Odd problem with Restart
Persistance..." for more info). You can do a quick test by deleting the
SESSIONS.ser file in ...work/Catalina/localhost/<myWebApp> (or whatever
name and host relates to your installation) - start Tomcat and see if
the datasource is found. If so, you will want to disable restart
persistance for this App (see my note for more info).
Hope this Helps
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Trouble finding Datsource Resource with DataSourceRealm
Posted by GB Developer <gb...@globallyboundless.com>.
well, I couldn't get a Realm to function when the DataSource it needed was
defined in the same Context as the Realm itself.
I've made it work by declaring the datasource resource in the 'global naming
resources' section of server.xml, and the realm directly under the 'engine'
element. And then in my host, I use a resourcelink to reference (and rename)
the globalresource to what my application is expecting.
still puzzled why I couldn't get the other setup to work.
> -----Original Message-----
> From: GB Developer [mailto:gb1071nx@globallyboundless.com]
> Sent: Thursday, October 20, 2005 9:56 AM
> To: 'Tomcat Users List'
> Subject: RE: Trouble finding Datsource Resource with DataSourceRealm
>
>
> I should have mentioned, I have a ContextListener that contains the
> following:
>
> -----------------------------------------------------------
> initCtx = new InitialContext();
> envCtx = (Context) initCtx.lookup("java:comp/env");
>
> logger.info("*** loading Data Source");
> try {
> ds = (DataSource) envCtx.lookup("sql/DataSource");
> application.setAttribute("services.datasource", ds);
> logger.info("*** DataSource loaded @ services.datasource");
> } catch (NamingException ne) {
> logger.fatal("ERROR loading DataSource: ", ne);
> }
> -----------------------------------------------------------
>
> And I get both 'info' messages. So the DataSource resource
> is being loaded,
> and it *can* be found at "sql/DataSource" (by my code in the context
> listener). It's just the Realm that can't seem to find it,
> as indicated by
> the stacktrace below.
>
> However, leaving no stone un-turned, I deleted the entire
> work directory for
> the 'foo' host and get the same result.
>
>
> This still appears in the engine log when I attempt to authenticate:
>
> 2005-10-20 09:51:15 DataSourceRealm[]: Exception performing
> authentication
> javax.naming.NameNotFoundException: Name sql is not bound in
> this Context
> at org.apache.naming.NamingContext.lookup(NamingContext.java:768)
> at org.apache.naming.NamingContext.lookup(NamingContext.java:151)
> at
> org.apache.catalina.realm.DataSourceRealm.open(DataSourceRealm
> .java:437)
> at
> org.apache.catalina.realm.DataSourceRealm.authenticate(DataSou
> rceRealm.java:
> 277)
> at
> org.apache.catalina.authenticator.BasicAuthenticator.authentic
> ate(BasicAuthe
> nticator.java:129)
>
>
>
> > -----Original Message-----
> > From: Stanley Bradbury [mailto:Stan.Bradbury@gmail.com]
> > Sent: Wednesday, October 19, 2005 8:07 PM
> > To: Tomcat Users List
> > Subject: Re: Trouble finding Datsource Resource with DataSourceRealm
> >
> < big snip />
>
> > >
> > Hi -
> > I had a similar problem (with 5.5.12) that turned out to be
> > related to
> > restart persistence (see post 10/17 Subj: "Odd problem with Restart
> > Persistance..." for more info). You can do a quick test by
> > deleting the
> > SESSIONS.ser file in ...work/Catalina/localhost/<myWebApp>
> > (or whatever
> > name and host relates to your installation) - start Tomcat
> and see if
> > the datasource is found. If so, you will want to disable restart
> > persistance for this App (see my note for more info).
> >
> > Hope this Helps
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> 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: Trouble finding Datsource Resource with DataSourceRealm
Posted by GB Developer <gb...@globallyboundless.com>.
I should have mentioned, I have a ContextListener that contains the
following:
-----------------------------------------------------------
initCtx = new InitialContext();
envCtx = (Context) initCtx.lookup("java:comp/env");
logger.info("*** loading Data Source");
try {
ds = (DataSource) envCtx.lookup("sql/DataSource");
application.setAttribute("services.datasource", ds);
logger.info("*** DataSource loaded @ services.datasource");
} catch (NamingException ne) {
logger.fatal("ERROR loading DataSource: ", ne);
}
-----------------------------------------------------------
And I get both 'info' messages. So the DataSource resource is being loaded,
and it *can* be found at "sql/DataSource" (by my code in the context
listener). It's just the Realm that can't seem to find it, as indicated by
the stacktrace below.
However, leaving no stone un-turned, I deleted the entire work directory for
the 'foo' host and get the same result.
This still appears in the engine log when I attempt to authenticate:
2005-10-20 09:51:15 DataSourceRealm[]: Exception performing authentication
javax.naming.NameNotFoundException: Name sql is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:768)
at org.apache.naming.NamingContext.lookup(NamingContext.java:151)
at
org.apache.catalina.realm.DataSourceRealm.open(DataSourceRealm.java:437)
at
org.apache.catalina.realm.DataSourceRealm.authenticate(DataSourceRealm.java:
277)
at
org.apache.catalina.authenticator.BasicAuthenticator.authenticate(BasicAuthe
nticator.java:129)
> -----Original Message-----
> From: Stanley Bradbury [mailto:Stan.Bradbury@gmail.com]
> Sent: Wednesday, October 19, 2005 8:07 PM
> To: Tomcat Users List
> Subject: Re: Trouble finding Datsource Resource with DataSourceRealm
>
< big snip />
> >
> Hi -
> I had a similar problem (with 5.5.12) that turned out to be
> related to
> restart persistence (see post 10/17 Subj: "Odd problem with Restart
> Persistance..." for more info). You can do a quick test by
> deleting the
> SESSIONS.ser file in ...work/Catalina/localhost/<myWebApp>
> (or whatever
> name and host relates to your installation) - start Tomcat and see if
> the datasource is found. If so, you will want to disable restart
> persistance for this App (see my note for more info).
>
> Hope this Helps
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org