This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new eb98272d1d Add support for the java:module namespace
eb98272d1d is described below
commit eb98272d1dda71a575a289965e3c583a0934112e
Author: Mark Thomas <[email protected]>
AuthorDate: Tue May 20 10:19:04 2025 +0100
Add support for the java:module namespace
---
.../catalina/core/NamingContextListener.java | 7 +++
test/org/apache/naming/TestNamingContext.java | 56 ++++++++++++++++++++++
webapps/docs/changelog.xml | 8 ++++
3 files changed, 71 insertions(+)
diff --git a/java/org/apache/catalina/core/NamingContextListener.java
b/java/org/apache/catalina/core/NamingContextListener.java
index 2f4ec5bee3..ccf19e8bfe 100644
--- a/java/org/apache/catalina/core/NamingContextListener.java
+++ b/java/org/apache/catalina/core/NamingContextListener.java
@@ -491,6 +491,13 @@ public class NamingContextListener implements
LifecycleListener, PropertyChangeL
} else {
compCtx = namingContext.createSubcontext("comp");
envCtx = compCtx.createSubcontext("env");
+ /*
+ * Jakarta Platform Specification, 5.2.2: Application Component
Environment Namespaces
+ *
+ * "java:module" and "java:comp" refer to the same namespace in a
web module (i.e. a web application).
+ * Implement this by binding the "comp" sub-context we just
created to the "module" name as well.
+ */
+ namingContext.bind("module", compCtx);
}
int i;
diff --git a/test/org/apache/naming/TestNamingContext.java
b/test/org/apache/naming/TestNamingContext.java
index 25ea465c1c..576f59fbd9 100644
--- a/test/org/apache/naming/TestNamingContext.java
+++ b/test/org/apache/naming/TestNamingContext.java
@@ -22,6 +22,8 @@ import javax.naming.NamingException;
import org.junit.Assert;
import org.junit.Test;
+import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.core.NamingContextListener;
import org.apache.catalina.startup.Tomcat;
import org.apache.catalina.startup.TomcatBaseTest;
import org.apache.naming.factory.ResourceLinkFactory;
@@ -31,6 +33,7 @@ import
org.apache.tomcat.util.descriptor.web.ContextResourceLink;
public class TestNamingContext extends TomcatBaseTest {
private static final String COMP_ENV = "comp/env";
+ private static final String MODULE_ENV = "module/env";
private static final String GLOBAL_NAME = "global";
private static final String LOCAL_NAME = "local";
private static final String DATA = "Cabbage";
@@ -92,6 +95,59 @@ public class TestNamingContext extends TomcatBaseTest {
}
+ @Test
+ public void testModuleEquivalentToComp() throws Exception {
+ Tomcat tomcat = getTomcatInstance();
+ tomcat.enableNaming();
+
+ org.apache.catalina.Context ctx = getProgrammaticRootContext();
+
+ tomcat.start();
+
+ // Equivalent to: Context initContext = new InitialContext();
+ Context webappInitial = ContextBindings.getContext(ctx);
+
+ // Make it writable (it is normally read-only)
+ String namingContextName = null;
+ LifecycleListener[] listeners = ctx.findLifecycleListeners();
+ for (LifecycleListener listener : listeners) {
+ if (listener instanceof NamingContextListener) {
+ NamingContextListener namingListener = (NamingContextListener)
listener;
+ namingContextName = namingListener.getName();
+ break;
+ }
+ }
+ ContextAccessController.setWritable(namingContextName,
ctx.getNamingToken());
+
+ // Nothing created so should be null
+ Object obj = doLookup(webappInitial, COMP_ENV + "/" + LOCAL_NAME);
+ Assert.assertNull(obj);
+ obj = doLookup(webappInitial, MODULE_ENV + "/" + LOCAL_NAME);
+ Assert.assertNull(obj);
+
+ // Create in java:comp/env
+ webappInitial.bind(COMP_ENV + "/" + LOCAL_NAME, DATA);
+
+ // Check it was created in java:comp/env and java:module/env
+ obj = doLookup(webappInitial, COMP_ENV + "/" + LOCAL_NAME);
+ Assert.assertEquals(DATA, obj);
+ obj = doLookup(webappInitial, MODULE_ENV + "/" + LOCAL_NAME);
+ Assert.assertEquals(DATA, obj);
+
+ // Remove it
+ webappInitial.unbind(COMP_ENV + "/" + LOCAL_NAME);
+
+ // Create in java:module/env
+ webappInitial.bind(MODULE_ENV + "/" + LOCAL_NAME, DATA);
+
+ // Check it was created in java:comp/env and java:module/env
+ obj = doLookup(webappInitial, COMP_ENV + "/" + LOCAL_NAME);
+ Assert.assertEquals(DATA, obj);
+ obj = doLookup(webappInitial, MODULE_ENV + "/" + LOCAL_NAME);
+ Assert.assertEquals(DATA, obj);
+ }
+
+
private Object doLookup(Context context, String name) {
Object result = null;
try {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 7830f81807..5312b9cee8 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -105,6 +105,14 @@
issues do not "pop up" wrt. others).
-->
<section name="Tomcat 10.1.42 (schultz)" rtext="in development">
+ <subsection name="Catalina">
+ <changelog>
+ <fix>
+ Add support for the <code>java:module</code> namespace which mirrors
+ the <code>java:comp</code> namespace. (markt)
+ </fix>
+ </changelog>
+ </subsection>
<subsection name="Web applications">
<changelog>
<fix>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]