You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Doug Mewhort <do...@net-linx.com> on 2006/09/12 13:50:07 UTC
Problem getting DB connection
Hi we are working with JBoss 4.0.4.CR2 and trying to test some DBCP SQL
connection using code that looks like
Context jndiContext = getInitialContext();
String dataSourceJndiName =
JndiNameProvider.getInstance().getDataSourceName(dataSourceName);
DataSource dataSource = (DataSource)
jndiContext.lookup(dataSourceJndiName);
return dataSource.getConnection();
We have creates a test.war that contains:
Web-INF/classes <- our test classes
WEB-INF/lib <- the important cactus jars and all of the jars that make
up our applications ear (which is deployed in the same jboss), including
the classes being tested.
WEB-INF/jboss-web.xml that contains:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<resource-ref>
<res-ref-name>OracleDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<jndi-name>java:/OracleDS</jndi-name>
</resource-ref>
</jboss-web>
WEB-INF/web.xml that contains:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<filter>
<filter-name>FilterRedirector</filter-name>
<filter-class>org.apache.cactus.server.FilterTestRedirector</filter-class>
</filter>
<filter-mapping>
<filter-name>FilterRedirector</filter-name>
<url-pattern>/FilterRedirector</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>ServletRedirector</servlet-name>
<servlet-class>org.apache.cactus.server.ServletTestRedirector</servlet-class>
</servlet>
<servlet>
<servlet-name>JspRedirector</servlet-name>
<jsp-file>/jspRedirector.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>ServletRedirector</servlet-name>
<url-pattern>/ServletRedirector</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>JspRedirector</servlet-name>
<url-pattern>/JspRedirector</url-pattern>
</servlet-mapping>
<!-- JDBC DataSources (java:comp/env/jdbc) -->
<resource-ref>
<description>The default DS</description>
<res-ref-name>OracleDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
The res-ref stuff is our latest attempt but it doesn't seem to have
helped as the problem has not changed.
The interesting thing is the four unittest functions that call code that
does not access the DB work fine server side. It's just the one that
tries to get a connection that blows up as the line:
DataSource dataSource = (DataSource)
jndiContext.lookup(dataSourceJndiName);
returns null.
Any help would be greatly appreciated.
Thanks
Doug