webXml.version.nfe=Unable to parse [{0}] from the version string [{1}]. This component of the version string will be ignored.
webXml.wrongFragmentName=Used a wrong fragment name {0} at web.xml absolute-ordering tag!
-namingResources.cleanupCloseFailed=Failed to invoke close method for resource [{0}] in container [{1}] so no cleanup was performed for that resource
-namingResources.cleanupCloseSecurity=Unable to retrieve close method for resource [{0}] in container [{1}] so no cleanup was performed for that resource
-namingResources.cleanupNoClose=Resource [{0}] in container [{1}] does not have a close method so no cleanup was performed for that resource
+namingResources.cleanupCloseFailed=Failed to invoke method [{0}] for resource [{1}] in container [{2}] so no cleanup was performed for that resource
+namingResources.cleanupCloseSecurity=Unable to retrieve method [{0}] for resource [{1}] in container [{2}] so no cleanup was performed for that resource
+namingResources.cleanupNoClose=Resource [{0}] in container [{1}] does not have a [{2}] method so no cleanup was performed for that resource
namingResources.cleanupNoContext=Failed to retrieve JNDI naming context for container [{0}] so no cleanup was performed for that container
namingResources.cleanupNoResource=Failed to retrieve JNDI resource [{0}] for container [{1}] so no cleanup was performed for that resource
namingResources.mbeanCreateFail=Failed to create MBean for naming resource [{0}]
import java.util.Hashtable;
import javax.naming.NamingException;
-import javax.sql.DataSource;
import org.apache.catalina.Container;
import org.apache.catalina.Context;
return;
}
for (ContextResource cr: resources.values()) {
- if (DataSource.class.getName().equals(cr.getType())) {
+ String closeMethod = cr.getCloseMethod();
+ if (closeMethod != null && closeMethod.length() > 0) {
String name = cr.getName();
- DataSource ds;
+ Object resource;
try {
- ds = (DataSource) ctxt.lookup(name);
+ resource = ctxt.lookup(name);
} catch (NamingException e) {
log.warn(sm.getString("namingResources.cleanupNoResource",
cr.getName(), container), e);
continue;
}
- cleanUp(ds, name);
+ cleanUp(resource, name, cr.getCloseMethod());
}
}
}
/**
- * Closing a database connection pool will close it's open connections. This
+ * Clean up a resource by calling the defined close method. For example,
+ * closing a database connection pool will close it's open connections. This
* will happen on GC but that leaves db connections open that may cause
* issues.
- * @param ds The DataSource to close.
+ *
+ * @param resource The resource to close.
*/
- private void cleanUp(DataSource ds, String name) {
+ private void cleanUp(Object resource, String name, String closeMethod) {
// Look for a zero-arg close() method
Method m = null;
try {
- m = ds.getClass().getMethod("close", (Class<?>[]) null);
+ m = resource.getClass().getMethod(closeMethod, (Class<?>[]) null);
} catch (SecurityException e) {
- log.debug(sm.getString("namingResources.cleanupCloseSecurity", name,
- container));
+ log.debug(sm.getString("namingResources.cleanupCloseSecurity",
+ closeMethod, name, container));
return;
} catch (NoSuchMethodException e) {
- log.debug(sm.getString("namingResources.cleanupNoClose", name,
- container));
+ log.debug(sm.getString("namingResources.cleanupNoClose",
+ name, container, closeMethod));
return;
}
if (m != null) {
try {
- m.invoke(ds, (Object[]) null);
+ m.invoke(resource, (Object[]) null);
} catch (IllegalArgumentException e) {
log.warn(sm.getString("namingResources.cleanupCloseFailed",
- name, container), e);
+ closeMethod, name, container), e);
} catch (IllegalAccessException e) {
log.warn(sm.getString("namingResources.cleanupCloseFailed",
- name, container), e);
+ closeMethod, name, container), e);
} catch (InvocationTargetException e) {
log.warn(sm.getString("namingResources.cleanupCloseFailed",
- name, container), e);
+ closeMethod, name, container), e);
}
}
}