tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Smith <d...@cornell.edu>
Subject Re: Exception when trying to configure a pool of connections for use of WS
Date Fri, 05 Sep 2008 17:00:00 GMT
And the code you use to get a connection?  Looks like the database pool 
should be fine, you are getting a javax.sql.DataSource object but 
treating it as a java.naming.Context object.

As an aside and definitely not things affecting the issue you describe 
below:
1. Do not use the root user in the database service for a web 
application.  It's a potential security flaw big enough to fit a jumbo 
jet into.
2. Do use strong passwords on the database (especially for the root 
account) with at least three character classes (upper case, lower case, 
punctuation, numbers) and no dictionary words present.
2. Add a validatonQuery="select 1" attribute to your <Resource ... /> 
element so connections are tested and regenerated as needed.

--David

Daniele Development-ML wrote:
> Hello everybody,
>
> I am trying to set up the configuration for a pool of connections to a MySQL
> DB and I get the following exception when deploying on Tomcat.
> I followed the steps at
> http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html.
>
> The application actually consists of a web service that performs a query to
> the DB.
>
> Any hints or suggestions? Thank you!
>
> Context file
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Context path="/DB_WS" debug="5" reloadable="true" crossContext="true">
>     <Resource name="jdbc/MySQL_cellmlrep" type="javax.sql.DataSource"
> auth="Container"
>               user="root" password="root"
> driverClassName="com.mysql.jdbc.Driver"
>               url="jdbc:mysql://localhost:3306/cellmlrep" maxActive="8"
> maxIdle="4"/>
> </Context>
>
> Web.xml
>
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
> http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
>     <listener>
>
> <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
>     </listener>
>     <servlet>
>         <servlet-name>DBAccess</servlet-name>
>
> <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
>         <load-on-startup>1</load-on-startup>
>     </servlet>
>     <servlet>
>         <servlet-name>DBAccessService</servlet-name>
>
> <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
>         <load-on-startup>1</load-on-startup>
>     </servlet>
>     <servlet-mapping>
>         <servlet-name>DBAccess</servlet-name>
>         <url-pattern>/DBAccess</url-pattern>
>     </servlet-mapping>
>     <servlet-mapping>
>         <servlet-name>DBAccessService</servlet-name>
>         <url-pattern>/DBAccessService</url-pattern>
>     </servlet-mapping>
>     <session-config>
>         <session-timeout>
>             30
>         </session-timeout>
>     </session-config>
>     <welcome-file-list>
>         <welcome-file>index.jsp</welcome-file>
>     </welcome-file-list>
>     <resource-ref>
>         <description>
>             The database DataSource for the Acme web application.
>         </description>
>         <res-ref-name>jdbc/MySQL_cellmlrep</res-ref-name>
>         <res-type>javax.sql.DataSource</res-type>
>         <res-auth>Container</res-auth>
>     </resource-ref>
> </web-app>
>
>
> Exception
>
> java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.BasicDataSource
> cannot be cast to javax.naming.Context
>         at
> org.apache.catalina.core.NamingContextListener.createSubcontexts(NamingContextListener.java:1203)
>         at
> org.apache.catalina.core.NamingContextListener.addResource(NamingContextListener.java:1015)
>         at
> org.apache.catalina.core.NamingContextListener.createNamingContext(NamingContextListener.java:633)
>         at
> org.apache.catalina.core.NamingContextListener.lifecycleEvent(NamingContextListener.java:237)
>         at
> org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
>         at
> org.apache.catalina.core.StandardContext.start(StandardContext.java:4252)
>         at
> org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
>         at
> org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
>         at
> org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
>         at
> org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:627)
>         at
> org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
>         at
> org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
>         at
> org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
>         at
> org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
>         at
> org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
>         at
> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
>         at
> org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
>         at
> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
>         at
> org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
>         at
> org.apache.catalina.core.StandardService.start(StandardService.java:516)
>         at
> org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
>         at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:597)
>         at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
>         at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
>
>   


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