You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2021/11/18 16:48:47 UTC
[tomcat] branch main updated: Remove some unnecessary restrictions. Aligns with Servlet 6.0
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new bdb3c45 Remove some unnecessary restrictions. Aligns with Servlet 6.0
bdb3c45 is described below
commit bdb3c4589fb28ca121c032dafaa0170cb29ee7eb
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Nov 18 16:48:34 2021 +0000
Remove some unnecessary restrictions. Aligns with Servlet 6.0
---
java/jakarta/servlet/ServletContext.java | 75 ++--------------------
java/org/apache/catalina/core/StandardContext.java | 27 +++-----
.../apache/catalina/core/TesterTldListener.java | 4 +-
webapps/docs/changelog.xml | 8 +++
4 files changed, 26 insertions(+), 88 deletions(-)
diff --git a/java/jakarta/servlet/ServletContext.java b/java/jakarta/servlet/ServletContext.java
index 6a61c2d..8f93735 100644
--- a/java/jakarta/servlet/ServletContext.java
+++ b/java/jakarta/servlet/ServletContext.java
@@ -121,14 +121,6 @@ public interface ServletContext {
*
* @return The major version declared in web.xml
*
- * @throws UnsupportedOperationException If called from a
- * {@link ServletContextListener#contextInitialized(ServletContextEvent)}
- * method of a {@link ServletContextListener} that was not defined in a
- * web.xml file, a web-fragment.xml file nor annotated with
- * {@link jakarta.servlet.annotation.WebListener}. For example, a
- * {@link ServletContextListener} defined in a TLD would not be able to
- * use this method.
- *
* @since Servlet 3.0
*/
public int getEffectiveMajorVersion();
@@ -139,14 +131,6 @@ public interface ServletContext {
*
* @return The minor version declared in web.xml
*
- * @throws UnsupportedOperationException If called from a
- * {@link ServletContextListener#contextInitialized(ServletContextEvent)}
- * method of a {@link ServletContextListener} that was not defined in a
- * web.xml file, a web-fragment.xml file nor annotated with
- * {@link jakarta.servlet.annotation.WebListener}. For example, a
- * {@link ServletContextListener} defined in a TLD would not be able to
- * use this method.
- *
* @since Servlet 3.0
*/
public int getEffectiveMinorVersion();
@@ -795,15 +779,10 @@ public interface ServletContext {
* SessionTrackingMode#SSL} is supported if at least one of the connectors
* used by this context has the attribute <code>secure</code> set to
* <code>true</code>.
+ *
* @return The set of default session tracking modes for this web
* application
- * @throws UnsupportedOperationException If called from a
- * {@link ServletContextListener#contextInitialized(ServletContextEvent)}
- * method of a {@link ServletContextListener} that was not defined in a
- * web.xml file, a web-fragment.xml file nor annotated with
- * {@link jakarta.servlet.annotation.WebListener}. For example, a
- * {@link ServletContextListener} defined in a TLD would not be able to
- * use this method.
+ *
* @since Servlet 3.0
*/
public Set<SessionTrackingMode> getDefaultSessionTrackingModes();
@@ -811,15 +790,10 @@ public interface ServletContext {
/**
* Obtains the currently enabled session tracking modes for this web
* application.
+ *
* @return The value supplied via {@link #setSessionTrackingModes(Set)} if
* one was previously set, else return the defaults
- * @throws UnsupportedOperationException If called from a
- * {@link ServletContextListener#contextInitialized(ServletContextEvent)}
- * method of a {@link ServletContextListener} that was not defined in a
- * web.xml file, a web-fragment.xml file nor annotated with
- * {@link jakarta.servlet.annotation.WebListener}. For example, a
- * {@link ServletContextListener} defined in a TLD would not be able to
- * use this method.
+ *
* @since Servlet 3.0
*/
public Set<SessionTrackingMode> getEffectiveSessionTrackingModes();
@@ -887,13 +861,7 @@ public interface ServletContext {
/**
* @return TODO
- * @throws UnsupportedOperationException If called from a
- * {@link ServletContextListener#contextInitialized(ServletContextEvent)}
- * method of a {@link ServletContextListener} that was not defined in a
- * web.xml file, a web-fragment.xml file nor annotated with
- * {@link jakarta.servlet.annotation.WebListener}. For example, a
- * {@link ServletContextListener} defined in a TLD would not be able to
- * use this method.
+ *
* @since Servlet 3.0 TODO SERVLET3 - Add comments
*/
public JspConfigDescriptor getJspConfigDescriptor();
@@ -903,15 +871,9 @@ public interface ServletContext {
*
* @return The associated web application class loader
*
- * @throws UnsupportedOperationException If called from a
- * {@link ServletContextListener#contextInitialized(ServletContextEvent)}
- * method of a {@link ServletContextListener} that was not defined in a
- * web.xml file, a web-fragment.xml file nor annotated with
- * {@link jakarta.servlet.annotation.WebListener}. For example, a
- * {@link ServletContextListener} defined in a TLD would not be able to
- * use this method.
* @throws SecurityException if access to the class loader is prevented by a
* SecurityManager
+ *
* @since Servlet 3.0
*/
public ClassLoader getClassLoader();
@@ -940,6 +902,7 @@ public interface ServletContext {
*
* @return The primary name of the virtual host on which this context is
* deployed
+ *
* @since Servlet 3.1
*/
public String getVirtualServerName();
@@ -949,14 +912,6 @@ public interface ServletContext {
*
* @return The current default session timeout in minutes
*
- * @throws UnsupportedOperationException If called from a
- * {@link ServletContextListener#contextInitialized(ServletContextEvent)}
- * method of a {@link ServletContextListener} that was not defined in a
- * web.xml file, a web-fragment.xml file nor annotated with
- * {@link jakarta.servlet.annotation.WebListener}. For example, a
- * {@link ServletContextListener} defined in a TLD would not be able to
- * use this method.
- *
* @since Servlet 4.0
*/
public int getSessionTimeout();
@@ -987,14 +942,6 @@ public interface ServletContext {
* @return The character encoding name or {@code null} if no default has
* been specified
*
- * @throws UnsupportedOperationException If called from a
- * {@link ServletContextListener#contextInitialized(ServletContextEvent)}
- * method of a {@link ServletContextListener} that was not defined in a
- * web.xml file, a web-fragment.xml file nor annotated with
- * {@link jakarta.servlet.annotation.WebListener}. For example, a
- * {@link ServletContextListener} defined in a TLD would not be able to
- * use this method.
- *
* @since Servlet 4.0
*/
public String getRequestCharacterEncoding();
@@ -1026,14 +973,6 @@ public interface ServletContext {
* @return The character encoding name or {@code null} if no default has
* been specified
*
- * @throws UnsupportedOperationException If called from a
- * {@link ServletContextListener#contextInitialized(ServletContextEvent)}
- * method of a {@link ServletContextListener} that was not defined in a
- * web.xml file, a web-fragment.xml file nor annotated with
- * {@link jakarta.servlet.annotation.WebListener}. For example, a
- * {@link ServletContextListener} defined in a TLD would not be able to
- * use this method.
- *
* @since Servlet 4.0
*/
public String getResponseCharacterEncoding();
diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java
index 47c20e1..ebc5448 100644
--- a/java/org/apache/catalina/core/StandardContext.java
+++ b/java/org/apache/catalina/core/StandardContext.java
@@ -6441,14 +6441,12 @@ public class StandardContext extends ContainerBase
@Override
public int getEffectiveMajorVersion() {
- throw new UnsupportedOperationException(
- sm.getString("noPluggabilityServletContext.notAllowed"));
+ return sc.getEffectiveMajorVersion();
}
@Override
public int getEffectiveMinorVersion() {
- throw new UnsupportedOperationException(
- sm.getString("noPluggabilityServletContext.notAllowed"));
+ return sc.getEffectiveMinorVersion();
}
@Override
@@ -6641,14 +6639,12 @@ public class StandardContext extends ContainerBase
@Override
public Set<SessionTrackingMode> getDefaultSessionTrackingModes() {
- throw new UnsupportedOperationException(
- sm.getString("noPluggabilityServletContext.notAllowed"));
+ return sc.getDefaultSessionTrackingModes();
}
@Override
public Set<SessionTrackingMode> getEffectiveSessionTrackingModes() {
- throw new UnsupportedOperationException(
- sm.getString("noPluggabilityServletContext.notAllowed"));
+ return sc.getEffectiveSessionTrackingModes();
}
@Override
@@ -6678,14 +6674,12 @@ public class StandardContext extends ContainerBase
@Override
public JspConfigDescriptor getJspConfigDescriptor() {
- throw new UnsupportedOperationException(
- sm.getString("noPluggabilityServletContext.notAllowed"));
+ return sc.getJspConfigDescriptor();
}
@Override
public ClassLoader getClassLoader() {
- throw new UnsupportedOperationException(
- sm.getString("noPluggabilityServletContext.notAllowed"));
+ return sc.getClassLoader();
}
@Override
@@ -6701,8 +6695,7 @@ public class StandardContext extends ContainerBase
@Override
public int getSessionTimeout() {
- throw new UnsupportedOperationException(
- sm.getString("noPluggabilityServletContext.notAllowed"));
+ return sc.getSessionTimeout();
}
@Override
@@ -6713,8 +6706,7 @@ public class StandardContext extends ContainerBase
@Override
public String getRequestCharacterEncoding() {
- throw new UnsupportedOperationException(
- sm.getString("noPluggabilityServletContext.notAllowed"));
+ return sc.getRequestCharacterEncoding();
}
@Override
@@ -6725,8 +6717,7 @@ public class StandardContext extends ContainerBase
@Override
public String getResponseCharacterEncoding() {
- throw new UnsupportedOperationException(
- sm.getString("noPluggabilityServletContext.notAllowed"));
+ return sc.getResponseCharacterEncoding();
}
@Override
diff --git a/test/org/apache/catalina/core/TesterTldListener.java b/test/org/apache/catalina/core/TesterTldListener.java
index e79d92e..37c6dbf 100644
--- a/test/org/apache/catalina/core/TesterTldListener.java
+++ b/test/org/apache/catalina/core/TesterTldListener.java
@@ -38,7 +38,7 @@ public class TesterTldListener implements ServletContextListener {
// Try and use one of the Servlet 3.0 methods that should be blocked
try {
- sc.getEffectiveMajorVersion();
+ sc.getServletRegistrations();
log.append("FAIL-01");
} catch (UnsupportedOperationException uoe) {
log.append("PASS-01");
@@ -53,7 +53,7 @@ public class TesterTldListener implements ServletContextListener {
if (servletContext == sce.getServletContext()) {
log.append("PASS-02");
} else {
- //log.append("FAIL-03");
+ log.append("FAIL-03");
}
}
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index a01e8fc..2eb6c43 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -111,6 +111,14 @@
Log warning if a listener is not nested inside a Server element
although it must have been. (michaelo)
</update>
+ <fix>
+ Where the getter can be called safely, remove the checks for
+ <code>ServletContext</code> getters called from a
+ <code>contextInitialized()</code> method of a
+ <code>ServletContextListener</code> that was not defined in a
+ <code>web.xml</code> file, a <code>web-fragment.xml</code> file nor
+ annotated with <code>WebListener</code>. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org