Author: markt
Date: Wed Aug 2 15:31:42 2017
New Revision: 1803828
URL: http://svn.apache.org/viewvc?rev=1803828&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=61366
Add a new attribute, localDataSource, to the JDBCStore that allows the Store to
be configured to use a DataSource defined by the web application rather than
the default of using a globally defined DataSource.
Patch provided by Jonathan Horowitz.
This closes #71
Modified:
tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java
tomcat/trunk/webapps/docs/changelog.xml
tomcat/trunk/webapps/docs/config/manager.xml
Modified: tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java?rev=1803828&r1=1803827&r2=1803828&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java (original)
+++ tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java Wed Aug 2
15:31:42 2017
@@ -108,6 +108,11 @@ public class JDBCStore extends StoreBase
protected String dataSourceName = null;
/**
+ * Context local datasource.
+ */
+ private boolean localDataSource = false;
+
+ /**
* DataSource to use
*/
protected DataSource dataSource = null;
@@ -455,6 +460,23 @@ public class JDBCStore extends StoreBase
return this.dataSourceName;
}
+ /**
+ * @return if the datasource will be looked up in the webapp JNDI Context.
+ */
+ public boolean getLocalDataSource() {
+ return localDataSource;
+ }
+
+ /**
+ * Set to {@code true} to cause the datasource to be looked up in the
webapp
+ * JNDI Context.
+ *
+ * @param localDataSource the new flag value
+ */
+ public void setLocalDataSource(boolean localDataSource) {
+ this.localDataSource = localDataSource;
+ }
+
// --------------------------------------------------------- Public Methods
@@ -868,16 +890,26 @@ public class JDBCStore extends StoreBase
return dbConnection;
if (dataSourceName != null && dataSource == null) {
+ org.apache.catalina.Context context = getManager().getContext();
+ ClassLoader oldThreadContextCL = null;
+ if (localDataSource) {
+ oldThreadContextCL = context.bind(Globals.IS_SECURITY_ENABLED,
null);
+ }
+
Context initCtx;
try {
initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
this.dataSource = (DataSource)
envCtx.lookup(this.dataSourceName);
} catch (NamingException e) {
- manager.getContext().getLogger().error(
+ context.getLogger().error(
sm.getString(getStoreName() + ".wrongDataSource",
this.dataSourceName), e);
- }
+ } finally {
+ if (localDataSource) {
+ context.unbind(Globals.IS_SECURITY_ENABLED,
oldThreadContextCL);
+ }
+ }
}
if (dataSource != null) {
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1803828&r1=1803827&r2=1803828&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Wed Aug 2 15:31:42 2017
@@ -66,6 +66,13 @@
web.xml and similar locations that may legitimately contain characters
that are not permitted by RFC 3986. (markt)
</fix>
+ <add>
+ <bug>61366</bug>: Add a new attribute, <code>localDataSource</code>, to
+ the <code>JDBCStore</code> that allows the Store to be configured to
use
+ a DataSource defined by the web application rather than the default of
+ using a globally defined DataSource. Patch provided by Jonathan
+ Horowitz. (markt)
+ </add>
</changelog>
</subsection>
<subsection name="Coyote">
Modified: tomcat/trunk/webapps/docs/config/manager.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/manager.xml?rev=1803828&r1=1803827&r2=1803828&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/manager.xml (original)
+++ tomcat/trunk/webapps/docs/config/manager.xml Wed Aug 2 15:31:42 2017
@@ -422,6 +422,12 @@
<p>Java class name of the JDBC driver to be used.</p>
</attribute>
+ <attribute name="localDataSource" required="false">
+ <p>This allows the Store to use a DataSource defined for the Context
+ rather than a global DataSource. If not specified, the default is
+ <code>false</code>: use a global DataSource.</p>
+ </attribute>
+
<attribute name="sessionAppCol" required="false">
<p>Name of the database column, contained in the specified session table,
that contains the Engine, Host, and Web Application Context name in the
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]