Hi,
I'm testing this functionality (versions 6.0.35 and 7.0.27) but it's not
working for me (https://issues.apache.org/bugzilla/show_bug.cgi?id=49543 ,
http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Resource_Links).
-->server.xml
<GlobalNamingResources>
<Resource name="jdbc/globalpg" auth="Container"
type="javax.sql.DataSource" removeAbandoned="true"
removeAbandonedTimeout="300"
maxActive="400" maxIdle="30"
maxWait="10000"
validationQuery="select 1"
testOnBorrow="true"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://
172.17.1.5:5432/tjse"
username="user1"
password="validpassword"
/>
</GlobalNamingResources>
-->conf/Catalina/localhost/app1.xml
<Context>
<ResourceLink name="jdbc/localpg"
global="jdbc/globalpg"
type="javax.sql.DataSource"
factory="org.apache.naming.factory.DataSourceLinkFactory"
username="user2"
password="invalidpassword"
/>
</Context>
-->webapps/app1/index.jsp
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ page session="false" import="javax.naming.*, java.sql.*, javax.sql.*" %>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test shared data source</title>
</head>
<body>
<%
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/localpg");
Connection c = ds.getConnection();
Statement stm = c.createStatement();
ResultSet rs = stm.executeQuery("select 'this should fail because the
password of localpg is invalid but it is working.'");
rs.next();
%>
<%= rs.getString(1) %><br/>
<%
c.close();
%>
</body>
</html>
Am I doing some wrong?
Thanks in advance,
Robert