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.

[EMAIL PROTECTED]:/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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to