tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Richards <Paul.Richa...@Sun.COM>
Subject Re: Tomcat and DataSource JNDI
Date Tue, 13 Apr 2004 21:04:51 GMT
On Tue, 2004-04-13 at 14:26, Parsons Technical Services wrote:
> Paul,
> 
> If manager is in this install then when you view the manager page it is
> listed at the bottom.
> 

It's not, this is the Web Services Developer Pack from Sun, so they have
changed all the names to just say JWSDP 1.3..  I'm sure it's Tomcat 5
though from some things mentioned in the JWSDP Tutorials.


> If you are able to put the context.xml in the META-INF directory and it get
> deployed via that context then you are on TC5. If this is TC4 then that is
> part of your problem. It will deploy using the default context which will
> not give you the link to the resource. Look in your logs for the deploy
> actions and see if it is seeing the context.xml. While you are there also
> see if any error are showing up in the logs.
> 

This is all I see in the logs, nothing about my context.xml which is
definately in WEB-INF of my war file.  The Tomcat JNDI DataSource howto
I posted the URL to doesn't make mention of putting in a context.xml
file.  And my log is identical if I remove it..



2004-04-13 14:49:10 Manager: deploy: Deploying web application at
'/phoenix'
2004-04-13 14:49:10 Manager: Uploading WAR file to
/home/pr146755/jwsdp-1.3/webapps/phoenix.war
2004-04-13 14:49:10 Manager: Extracting XML file to
/home/pr146755/jwsdp-1.3/conf/Catalina/localhost/phoenix.xml
2004-04-13 14:49:10 Manager: install: Installing web application at
'/phoenix' from
'jar:file:/home/pr146755/jwsdp-1.3/webapps/phoenix.war!/'




> Yeah, go ahead and post all your config file parts and the code snippet that
> calls the database.
> 

web.xml:

<web-app>
  <display-name>Phoenix web interface</display-name>
  <description>A web interface to the Phoenix system</description>
  <session-config>
    <session-timeout>60</session-timeout>
  </session-config>
  <resource-ref>
    <res-ref-name>jdbc/PhoenixDB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref> 

  <servlet>
    <display-name>PhoenixServlet</display-name>
    <servlet-name>PhoenixServlet</servlet-name>
    <servlet-class>phoenix.servlet.PhoenixServlet</servlet-class>
  </servlet>  
  <servlet-mapping>
    <servlet-name>PhoenixServlet</servlet-name>
    <url-pattern>/Phoenix</url-pattern>
  </servlet-mapping>

</web-app>



context.xml:

<Context path="/phoenix"
  docBase="." 
  debug="5">
  <ResourceLink name="jdbc/PhoenixDB" global="jdbc/PhoenixDB"/>
</Context> 


server.xml:

<Server className="org.apache.catalina.core.StandardServer" debug="0"
port="8005" shutdown="SHUTDOWN">

[ Snip listeners ]

  <GlobalNamingResources>
    <Environment description="Absolute Pathname of the JWSDP
Installation" name="jwsdp.home" override="true" type="java.lang.String"
value="/home/pr146755/jwsdp-1.3"/>
    <Environment name="simpleValue" override="true"
type="java.lang.Integer" value="30"/>
    <Resource name="jdbc/PhoenixDB" scope="Shareable"
type="javax.sql.DataSource"/>
    <Resource auth="Container" description="User database that can be
updated and saved" name="UserDatabase" scope="Shareable"
type="org.apache.catalina.UserDatabase"/>
    <ResourceParams name="jdbc/PhoenixDB">


    <!-- Have tried with and without the following commented block -->
    <!--
      <parameter>
        <name>factory</name>
        <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
      </parameter>
     -->
      <parameter>
        <name>maxActive</name>
        <value>4</value>
      </parameter>
      <parameter>
        <name>maxIdle</name>
        <value>2</value>
      </parameter>
      <parameter>
        <name>maxWait</name>
        <value>5000</value>
      </parameter>
      <parameter>
        <name>username</name>
        <value>****</value>
      </parameter>
      <parameter>
        <name>password</name>
        <value>****</value>
      </parameter>
      <parameter>
        <name>driverClassName</name>
        <value>com.mysql.jdbc.Driver</value>
      </parameter>
      <parameter>
        <name>url</name>
        <value>jdbc:mysql://drusilla.central/phoenix</value>
      </parameter>
    </ResourceParams>
    <ResourceParams name="UserDatabase">
      <parameter>
        <name>factory</name>
       
<value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
      </parameter>
      <parameter>
        <name>pathname</name>
        <value>conf/tomcat-users.xml</value>
      </parameter>
    </ResourceParams>
  </GlobalNamingResources>

[ Snip Service stuff ]

</Server>


Code to access JNDI stuffs:

    DataSource ds = null;
    try {
        Context ctx = new InitialContext();
        ds =
(DataSource)ctx.lookup("java:comp/env/jdbc/PhoenixDB");        
        if (ds == null)
            throw new Exception("DS was null");
        ds.getConnection("phoenix", "ashes").close();
    } catch (Exception e) {
        out.println("JNDI lookup failed");
        e.printStackTrace(out);
        MysqlConnectionPoolDataSource dsi = new
com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource();
        dsi.setURL("jdbc:mysql://drusilla.central/phoenix");
        ds = dsi;
    }
    
    Connection con =  ds.getConnection("phoenix", "ashes");
    out.println("Created connection to database.");



> Doug
> 
> ----- Original Message ----- 
> From: "Paul Richards" <Paul.Richards@Sun.COM>
> To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
> Sent: Tuesday, April 13, 2004 4:12 PM
> Subject: Re: Tomcat and DataSource JNDI
> 
> 
> > On Tue, 2004-04-13 at 13:35, Parsons Technical Services wrote:
> > > Paul,
> > >
> > > Several questions:
> > >
> > > What version of Tomcat is this?
> >
> > Version 5 from what I can tell from the licence agreement.  (What is the
> > correct way to determine?)
> >
> > > What platform/OS are you on?
> >
> > Solaris 9 (MU3 applied) on Sparc
> >
> > > Which JDK version?
> >
> > Sun J2SDK build 1.4.2-b28
> >
> > >
> > > Typically this error is from a mis-configuration for the jndi.
> > >
> > > Here are my configuration files or parts of for my development box.
> > >
> > > First in the server.xml set up a GlobalResource such as this:
> > >
> > > Of course replace the necesary data with your specifics.
> > >
> > [snip]
> >
> > I have this.
> >
> >
> >
> > > Next place this, at the bottom, in your web.xml for the app:
> > >
> > [snip]
> >
> > I have this also..
> >
> > Both of these I have copied almost verbatim from the Tomcat JNDI
> > DataSource HowTo.  I can paste you in my exact code if you think it
> > would help.
> >
> >
> > > For TC5: Now create a file in the META-INF directory. Name the file
> > > context.xml.
> > > In this file you will need to define the context and the link to the
> jdbc.
> > > For TC4: Add this to the server.xml
> > >
> > [snip]
> >
> > I have tried with and without the context.xml, it didn't make any
> > difference.  I do not think that the JNDI binding is the real problem as
> > when I change the calling code in my Servlet to look up the wrong JNDI
> > name I get different errors.
> >
> > I think that the binding is there but it is somehow not getting the
> > correct parameters.  In particular the driver class name.
> >
> >
> >
> > > ----- Original Message ----- 
> > > From: "Paul Richards" <Paul.Richards@Sun.COM>
> > > To: <tomcat-user@jakarta.apache.org>
> > > Sent: Tuesday, April 13, 2004 3:03 PM
> > > Subject: Tomcat and DataSource JNDI
> > >
> > >
> > > > Hi,
> > > > I am running Tomcat from the Java Webservices Developer Pack 1.3 and I
> > > > cannot get JNDI working for mysql DataSource objects.  I have googled
> > > > around for my error which is:
> > > >
> > > > java.sql.SQLException: Cannot load JDBC driver class 'null'
> > > > at
> > >
> org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.jav
> > > a:529)
> > > > at
> > >
> org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:3
> > > 29)
> > > >
> > > >
> > > > What I found on google was that this error is not just a problem with
> > > Mysql and that people have experienced it with Oracle and Postgresql
> also:
> > > >
> > >
> http://archives.real-time.com/pipermail/tomcat-users/2002-October/081368.html
> > > >
> > > > I tried the suggestion in this last URL of using the exact orderings
> of
> > > > parameters in the server.xml file as shown in the Tomcat JNDI
> DataSource
> > > > HowTo.  Unfortunately this has not helped my case.
> > > >
> > > >
> > > > I appreciate that a very similar thread to this is currently running
> but
> > > > that problem looks different to mine.
> > > >
> > > >
> > > > I have failover code which created a Mysql datasource manually if the
> > > > JNDI fails and the failover code works perfectly.  This makes me sure
> > > > that my CLASSPATHs are correct.
> > > >
> > > >
> > > >
> > > > -- 
> > > > Paul Richards <Paul.Richards@Sun.COM>
> > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> > > >
> > > >
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> > -- 
> > Paul Richards <Paul.Richards@Sun.COM>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
-- 
Paul Richards <Paul.Richards@Sun.COM>


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


Mime
View raw message