Please bear with my english and please let me know if my question is not clear or confusing, I will try to rephrase it :)
I have multiple Tomcat running with different data source like below in server.xml:
<GlobalNamingResources>
<Resource
auth="Container"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
logAbandoned="true"
maxActive="20"
maxIdle="10"
maxWait="5000"
name="jdbc/datasource1"
removeAbandoned="true"
removeAbandonedTimeout="60"
type="javax.sql.DataSource"
url="jdbc:sqlserver://localhost;databaseName=database1"
username="username"
password="password"/>
</GlobalNamingResources>
I would like to create a webapp which I can simply deploy to each Tomcat and test out all the data source configured in server.xml by triggering a servlet.
By saying test out the data source, I mean execute below snippet for each data source:
try {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("datasource1");
ds.getConnection(); // If this line doesn't throw SQLException, the db connection is established successfully
} catch(NamingException ex) {
System.out.println("JNDI lookup failed: " + ex.getMessage());
} catch(SQLException se) {
System.out.println("Unable to establish connection: " + se.getMessage());
}
Problem
I can't find a way to retrieve all data source from server.xml without keeping the "datasource1" in my context.xml, for example:
<ResourceLink global="jdbc/datasource1" name="datasource1" type="javax.sql.DataSource"/>
So my questino is that, is there a way to read all data source configured in server.xml without having the context.xml file ?
Thanks in advance.