From 5f1f9a4fde1fcd7abdd5eed3f7153405e2250b87 Mon Sep 17 00:00:00 2001 From: Grzegorz Grzybek Date: Fri, 16 Jun 2023 09:38:44 +0200 Subject: [PATCH] [#1802] Switch pax-web-tomcat from javax to jakarta --- pax-web-tomcat/pom.xml | 71 +++--- .../core/ApplicationSessionCookieConfig.java | 155 ++++++++----- .../internal/OsgiContextConfiguration.java | 2 +- .../tomcat/internal/PaxWebFilterDef.java | 18 +- .../tomcat/internal/PaxWebFilterMap.java | 2 +- .../internal/PaxWebScopedStandardContext.java | 2 +- .../internal/PaxWebStandardContext.java | 24 +- .../internal/PaxWebStandardContextValve.java | 4 +- .../internal/PaxWebStandardWrapper.java | 14 +- .../internal/PaxWebStandardWrapperValve.java | 2 +- .../internal/PaxWebTaskThreadFactory.java | 12 +- .../tomcat/internal/TomcatFactory.java | 51 +++-- .../internal/TomcatServerController.java | 2 +- .../tomcat/internal/TomcatServerWrapper.java | 22 +- .../tomcat/internal/web/OsgiStandardRoot.java | 2 +- .../internal/web/TomcatResourceServlet.java | 16 +- .../internal/EmbeddedTomcatHttp2Test.java | 36 ++- .../internal/EmbeddedTomcatHttps2Test.java | 55 +++-- .../tomcat/internal/EmbeddedTomcatTest.java | 57 +++-- .../web/service/tomcat/internal/PathTest.java | 38 ++-- ...ServletContextListenerAddedFromWebXml.java | 4 +- .../tomcat/internal/UnifiedTomcatTest.java | 210 +++++++++--------- 22 files changed, 426 insertions(+), 373 deletions(-) diff --git a/pax-web-tomcat/pom.xml b/pax-web-tomcat/pom.xml index 0315a1b950..e9c871325c 100644 --- a/pax-web-tomcat/pom.xml +++ b/pax-web-tomcat/pom.xml @@ -43,23 +43,23 @@ org.ops4j.pax.web.service.tomcat.internal.Activator - - javax.servlet;version="[3.1,5)", - javax.servlet.annotation;version="[3.1,5)", - javax.servlet.descriptor;version="[3.1,5)", - javax.servlet.http;version="[3.1,5)", - - - org.osgi.framework;version="[1.8,2)", + + jakarta.servlet;version="[6,7)", + jakarta.servlet.annotation;version="[6,7)", + jakarta.servlet.descriptor;version="[6,7)", + jakarta.servlet.http;version="[6,7)", + + + org.osgi.framework;version="[1.10,2)", org.osgi.framework.wiring;version="[1.2,2)", org.osgi.util.tracker;version="[1.5,2)", - org.osgi.service.http;version="[1.2,2)", - org.osgi.service.http.whiteboard;version="[1.1,2)", + org.osgi.service.servlet.whiteboard;version="[2,3)", org.ops4j.pax.web.service;version="${pax-web.osgi.version}", + org.ops4j.pax.web.service.http;version="${pax-web.osgi.version}", org.ops4j.pax.web.utils;version="${pax-web.osgi.version}", org.ops4j.pax.web.service.spi.*;version="${pax-web.osgi.version}", @@ -67,7 +67,7 @@ org.ops4j.pax.web.jsp;version="${pax-web.osgi.version}";resolution:=optional, - org.slf4j;version="[1.7,2)", + org.slf4j;version="[2,3)", org.apache.juli.logging, @@ -100,19 +100,19 @@ org.apache.juli;version="${dependency.org.apache.tomcat}", - javax.annotation;version="[1.2,2)";resolution:=optional, + jakarta.annotation;version="[2,3)";resolution:=optional, javax.management, javax.management.modelmbean, javax.naming, javax.naming.spi, javax.net.ssl, - javax.security.auth, - javax.security.auth.callback, - javax.security.auth.login, - javax.security.auth.message, - javax.security.auth.message.callback, - javax.security.auth.message.config, - javax.security.auth.message.module, + jakarta.security.auth, + jakarta.security.auth.callback, + jakarta.security.auth.login, + jakarta.security.auth.message, + jakarta.security.auth.message.callback, + jakarta.security.auth.message.config, + jakarta.security.auth.message.module, javax.xml.parsers, javax.xml.transform, org.w3c.dom, @@ -268,11 +268,11 @@ org.osgi - osgi.cmpn + org.osgi.service.servlet provided - + jakarta.annotation @@ -284,15 +284,20 @@ provided - jakarta.authentication - jakarta.authentication-api - provided + jakarta.websocket + jakarta.websocket-api + test jakarta.websocket - jakarta.websocket-api + jakarta.websocket-client-api test + + jakarta.authentication + jakarta.authentication-api + provided + @@ -321,7 +326,7 @@ org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl test @@ -352,8 +357,18 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.assertj + assertj-core test diff --git a/pax-web-tomcat/src/main/java/org/apache/catalina/core/ApplicationSessionCookieConfig.java b/pax-web-tomcat/src/main/java/org/apache/catalina/core/ApplicationSessionCookieConfig.java index 7bca975073..e52f386d5e 100644 --- a/pax-web-tomcat/src/main/java/org/apache/catalina/core/ApplicationSessionCookieConfig.java +++ b/pax-web-tomcat/src/main/java/org/apache/catalina/core/ApplicationSessionCookieConfig.java @@ -16,12 +16,17 @@ */ package org.apache.catalina.core; -import javax.servlet.SessionCookieConfig; -import javax.servlet.http.Cookie; +import java.util.Collections; +import java.util.Map; +import java.util.TreeMap; + +import jakarta.servlet.SessionCookieConfig; +import jakarta.servlet.http.Cookie; import org.apache.catalina.Context; import org.apache.catalina.LifecycleState; import org.apache.catalina.util.SessionConfig; +import org.apache.tomcat.util.descriptor.web.Constants; import org.apache.tomcat.util.res.StringManager; import org.ops4j.pax.web.service.tomcat.internal.PaxWebSessionIdGenerator; @@ -34,14 +39,14 @@ public class ApplicationSessionCookieConfig implements SessionCookieConfig { private static final StringManager sm = StringManager.getManager(ApplicationSessionCookieConfig.class); //CHECKSTYLE:ON - private boolean httpOnly; - private boolean secure; - private int maxAge = -1; - private String comment; - private String domain; + private static final int DEFAULT_MAX_AGE = -1; + private static final boolean DEFAULT_HTTP_ONLY = false; + private static final boolean DEFAULT_SECURE = false; + + private final Map attributes = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + private String name; - private String path; - private final StandardContext context; + private StandardContext context; public ApplicationSessionCookieConfig(StandardContext context) { this.context = context; @@ -49,17 +54,21 @@ public ApplicationSessionCookieConfig(StandardContext context) { @Override public String getComment() { - return comment; + return null; } @Override public String getDomain() { - return domain; + return getAttribute(Constants.COOKIE_DOMAIN_ATTR); } @Override public int getMaxAge() { - return maxAge; + String maxAge = getAttribute(Constants.COOKIE_MAX_AGE_ATTR); + if (maxAge == null) { + return DEFAULT_MAX_AGE; + } + return Integer.parseInt(maxAge); } @Override @@ -69,65 +78,67 @@ public String getName() { @Override public String getPath() { - return path; + return getAttribute(Constants.COOKIE_PATH_ATTR); } @Override public boolean isHttpOnly() { - return httpOnly; + String httpOnly = getAttribute(Constants.COOKIE_HTTP_ONLY_ATTR); + if (httpOnly == null) { + return DEFAULT_HTTP_ONLY; + } + return Boolean.parseBoolean(httpOnly); } @Override public boolean isSecure() { - return secure; + String secure = getAttribute(Constants.COOKIE_SECURE_ATTR); + if (secure == null) { + return DEFAULT_SECURE; + } + return Boolean.parseBoolean(secure); } @Override public void setComment(String comment) { if (!context.getState().equals(LifecycleState.STARTING_PREP)) { - throw new IllegalStateException(sm.getString( - "applicationSessionCookieConfig.ise", "comment", - context.getPath())); + throw new IllegalStateException( + sm.getString("applicationSessionCookieConfig.ise", "comment", context.getPath())); } - this.comment = comment; } @Override public void setDomain(String domain) { if (!context.getState().equals(LifecycleState.STARTING_PREP)) { - throw new IllegalStateException(sm.getString( - "applicationSessionCookieConfig.ise", "domain name", - context.getPath())); + throw new IllegalStateException( + sm.getString("applicationSessionCookieConfig.ise", "domain name", context.getPath())); } - this.domain = domain; + setAttribute(Constants.COOKIE_DOMAIN_ATTR, domain); } @Override public void setHttpOnly(boolean httpOnly) { if (!context.getState().equals(LifecycleState.STARTING_PREP)) { - throw new IllegalStateException(sm.getString( - "applicationSessionCookieConfig.ise", "HttpOnly", - context.getPath())); + throw new IllegalStateException( + sm.getString("applicationSessionCookieConfig.ise", "HttpOnly", context.getPath())); } - this.httpOnly = httpOnly; + setAttribute(Constants.COOKIE_HTTP_ONLY_ATTR, Boolean.toString(httpOnly)); } @Override public void setMaxAge(int maxAge) { if (!context.getState().equals(LifecycleState.STARTING_PREP)) { - throw new IllegalStateException(sm.getString( - "applicationSessionCookieConfig.ise", "max age", - context.getPath())); + throw new IllegalStateException( + sm.getString("applicationSessionCookieConfig.ise", "max age", context.getPath())); } - this.maxAge = maxAge; + setAttribute(Constants.COOKIE_MAX_AGE_ATTR, Integer.toString(maxAge)); } @Override public void setName(String name) { if (!context.getState().equals(LifecycleState.STARTING_PREP)) { - throw new IllegalStateException(sm.getString( - "applicationSessionCookieConfig.ise", "name", - context.getPath())); + throw new IllegalStateException( + sm.getString("applicationSessionCookieConfig.ise", "name", context.getPath())); } this.name = name; } @@ -135,34 +146,52 @@ public void setName(String name) { @Override public void setPath(String path) { if (!context.getState().equals(LifecycleState.STARTING_PREP)) { - throw new IllegalStateException(sm.getString( - "applicationSessionCookieConfig.ise", "path", - context.getPath())); + throw new IllegalStateException( + sm.getString("applicationSessionCookieConfig.ise", "path", context.getPath())); } - this.path = path; + setAttribute(Constants.COOKIE_PATH_ATTR, path); } @Override public void setSecure(boolean secure) { if (!context.getState().equals(LifecycleState.STARTING_PREP)) { - throw new IllegalStateException(sm.getString( - "applicationSessionCookieConfig.ise", "secure", - context.getPath())); + throw new IllegalStateException( + sm.getString("applicationSessionCookieConfig.ise", "secure", context.getPath())); + } + setAttribute(Constants.COOKIE_SECURE_ATTR, Boolean.toString(secure)); + } + + + @Override + public void setAttribute(String name, String value) { + if (!context.getState().equals(LifecycleState.STARTING_PREP)) { + throw new IllegalStateException( + sm.getString("applicationSessionCookieConfig.ise", name, context.getPath())); } - this.secure = secure; + attributes.put(name, value); + } + + @Override + public String getAttribute(String name) { + return attributes.get(name); + } + + + @Override + public Map getAttributes() { + return Collections.unmodifiableMap(attributes); } /** * Creates a new session cookie for the given session ID * - * @param context The Context for the web application - * @param sessionId The ID of the session for which the cookie will be - * created - * @param secure Should session cookie be configured as secure + * @param context The Context for the web application + * @param sessionId The ID of the session for which the cookie will be created + * @param secure Should session cookie be configured as secure + * * @return the cookie for the session */ - public static Cookie createSessionCookie(Context context, - String sessionId, boolean secure) { + public static Cookie createSessionCookie(Context context, String sessionId, boolean secure) { // Pax Web / OSGi adjustment String sessionIdPrefix = PaxWebSessionIdGenerator.sessionIdPrefix.get(); @@ -171,20 +200,17 @@ public static Cookie createSessionCookie(Context context, } // end of Pax Web / OSGi adjustment - SessionCookieConfig scc = - context.getServletContext().getSessionCookieConfig(); + SessionCookieConfig scc = context.getServletContext().getSessionCookieConfig(); // NOTE: The priority order for session cookie configuration is: - // 1. Context level configuration - // 2. Values from SessionCookieConfig - // 3. Defaults + // 1. Context level configuration + // 2. Values from SessionCookieConfig + // 3. Defaults - Cookie cookie = new Cookie( - SessionConfig.getSessionCookieName(context), sessionId); + Cookie cookie = new Cookie(SessionConfig.getSessionCookieName(context), sessionId); // Just apply the defaults. cookie.setMaxAge(scc.getMaxAge()); - cookie.setComment(scc.getComment()); if (context.getSessionCookieDomain() == null) { // Avoid possible NPE @@ -207,6 +233,23 @@ public static Cookie createSessionCookie(Context context, cookie.setPath(SessionConfig.getSessionCookiePath(context)); + // Other attributes + for (Map.Entry attribute : scc.getAttributes().entrySet()) { + switch (attribute.getKey()) { + case Constants.COOKIE_COMMENT_ATTR: + case Constants.COOKIE_DOMAIN_ATTR: + case Constants.COOKIE_MAX_AGE_ATTR: + case Constants.COOKIE_PATH_ATTR: + case Constants.COOKIE_SECURE_ATTR: + case Constants.COOKIE_HTTP_ONLY_ATTR: + // Handled above so NO-OP + break; + default: { + cookie.setAttribute(attribute.getKey(), attribute.getValue()); + } + } + } + return cookie; } } diff --git a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/OsgiContextConfiguration.java b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/OsgiContextConfiguration.java index c07084fd7c..eeb10e14c6 100644 --- a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/OsgiContextConfiguration.java +++ b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/OsgiContextConfiguration.java @@ -56,7 +56,7 @@ import org.slf4j.LoggerFactory; import org.xml.sax.SAXException; -import javax.servlet.SessionCookieConfig; +import jakarta.servlet.SessionCookieConfig; /** * A {@link LifecycleListener} that configures {@link PaxWebStandardContext} with highest-ranked diff --git a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebFilterDef.java b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebFilterDef.java index bf44ddde07..a6573850b9 100644 --- a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebFilterDef.java +++ b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebFilterDef.java @@ -16,14 +16,14 @@ package org.ops4j.pax.web.service.tomcat.internal; import java.io.IOException; -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.GenericFilter; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.GenericFilter; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; import org.apache.tomcat.util.descriptor.web.FilterDef; import org.ops4j.pax.web.service.spi.model.OsgiContextModel; @@ -35,7 +35,7 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceObjects; import org.osgi.framework.ServiceReference; -import org.osgi.service.http.runtime.dto.DTOConstants; +import org.osgi.service.servlet.runtime.dto.DTOConstants; /** * Extension of Tomcat's {@link FilterDef} which can tell if it's suitable for a chain with given target diff --git a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebFilterMap.java b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebFilterMap.java index 75d5f37b77..8231f652b3 100644 --- a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebFilterMap.java +++ b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebFilterMap.java @@ -15,7 +15,7 @@ */ package org.ops4j.pax.web.service.tomcat.internal; -import javax.servlet.DispatcherType; +import jakarta.servlet.DispatcherType; import org.apache.tomcat.util.descriptor.web.FilterMap; import org.ops4j.pax.web.service.spi.model.elements.FilterModel; diff --git a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebScopedStandardContext.java b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebScopedStandardContext.java index 5b02d65f73..f8dd07efc8 100644 --- a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebScopedStandardContext.java +++ b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebScopedStandardContext.java @@ -17,7 +17,7 @@ import java.util.LinkedList; import java.util.List; -import javax.servlet.FilterConfig; +import jakarta.servlet.FilterConfig; import org.apache.catalina.Container; import org.apache.catalina.LifecycleState; diff --git a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebStandardContext.java b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebStandardContext.java index d3c1110351..64a1751393 100644 --- a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebStandardContext.java +++ b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebStandardContext.java @@ -23,15 +23,15 @@ import java.util.Set; import java.util.TreeMap; import java.util.stream.Collectors; -import javax.servlet.DispatcherType; -import javax.servlet.Filter; -import javax.servlet.Servlet; -import javax.servlet.ServletContainerInitializer; -import javax.servlet.ServletContext; -import javax.servlet.ServletContextListener; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSessionListener; +import jakarta.servlet.DispatcherType; +import jakarta.servlet.Filter; +import jakarta.servlet.Servlet; +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpSessionListener; import org.apache.catalina.Container; import org.apache.catalina.LifecycleException; @@ -53,14 +53,14 @@ import org.ops4j.pax.web.service.spi.servlet.OsgiSessionAttributeListener; import org.ops4j.pax.web.service.spi.servlet.PreprocessorFilterConfig; import org.ops4j.pax.web.service.spi.servlet.SCIWrapper; -import org.osgi.service.http.whiteboard.Preprocessor; +import org.osgi.service.servlet.whiteboard.Preprocessor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Extension of {@link StandardContext} that keeps track of default * {@link org.ops4j.pax.web.service.spi.model.OsgiContextModel} and - * {@link javax.servlet.ServletContext} to use for chains that do not have target servlet mapped. These are + * {@link jakarta.servlet.ServletContext} to use for chains that do not have target servlet mapped. These are * required by filters which may be associated with such servlet-less chains. */ public class PaxWebStandardContext extends StandardContext { @@ -199,7 +199,7 @@ public void setDefaultServletContext(OsgiServletContext defaultServletContext) { /** * We have to ensure that this {@link StandardContext} will always return - * proper instance of {@link javax.servlet.ServletContext} - especially in the events passed to listeners + * proper instance of {@link jakarta.servlet.ServletContext} - especially in the events passed to listeners * * @param osgiServletContext */ diff --git a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebStandardContextValve.java b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebStandardContextValve.java index ecd42f47ca..fcaaa2f238 100644 --- a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebStandardContextValve.java +++ b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebStandardContextValve.java @@ -16,8 +16,8 @@ package org.ops4j.pax.web.service.tomcat.internal; import java.io.IOException; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletResponse; import org.apache.catalina.Wrapper; import org.apache.catalina.connector.Request; diff --git a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebStandardWrapper.java b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebStandardWrapper.java index 99d31d1071..bb2618d9b4 100644 --- a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebStandardWrapper.java +++ b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebStandardWrapper.java @@ -15,9 +15,9 @@ */ package org.ops4j.pax.web.service.tomcat.internal; -import javax.servlet.Servlet; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; +import jakarta.servlet.Servlet; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; import org.apache.catalina.Container; import org.apache.catalina.LifecycleException; @@ -34,7 +34,7 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceObjects; import org.osgi.framework.ServiceReference; -import org.osgi.service.http.runtime.dto.DTOConstants; +import org.osgi.service.servlet.runtime.dto.DTOConstants; /** * Tomcat's version of Jetty's {@code org.ops4j.pax.web.service.jetty.internal.PaxWebServletHolder} which @@ -49,7 +49,7 @@ public class PaxWebStandardWrapper extends StandardWrapper { private Class servletClass; private ServiceReference serviceReference; - /** This {@link ServletContext} is scoped to single {@link org.osgi.service.http.context.ServletContextHelper} */ + /** This {@link ServletContext} is scoped to single {@link org.osgi.service.servlet.context.ServletContextHelper} */ private final OsgiServletContext osgiServletContext; /** This {@link ServletContext} is scoped to particular Whiteboard servlet */ private final OsgiScopedServletContext servletContext; @@ -104,7 +104,7 @@ public class PaxWebStandardWrapper extends StandardWrapper { * in which' context we're adding given servlet to Jetty. * @param servletModel * @param osgiContextModel - * @param osgiServletContext {@link org.osgi.service.http.context.ServletContextHelper} specific {@link ServletContext} + * @param osgiServletContext {@link org.osgi.service.servlet.context.ServletContextHelper} specific {@link ServletContext} * @param realContext */ public PaxWebStandardWrapper(ServletModel servletModel, OsgiContextModel osgiContextModel, @@ -174,7 +174,7 @@ public OsgiContextModel getOsgiContextModel() { } /** - * This method is called from {@link javax.servlet.ServletConfig} passed to the servlet instance of this wrapper. + * This method is called from {@link jakarta.servlet.ServletConfig} passed to the servlet instance of this wrapper. * Thus there's no need to create {@link OsgiInitializedServlet} wrapper around the servlet. * @return */ diff --git a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebStandardWrapperValve.java b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebStandardWrapperValve.java index e8ccf2cca6..4b2fe85c2f 100644 --- a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebStandardWrapperValve.java +++ b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebStandardWrapperValve.java @@ -16,7 +16,7 @@ package org.ops4j.pax.web.service.tomcat.internal; import java.io.IOException; -import javax.servlet.ServletException; +import jakarta.servlet.ServletException; import org.apache.catalina.connector.Request; import org.apache.catalina.connector.Response; diff --git a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebTaskThreadFactory.java b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebTaskThreadFactory.java index 6f49d4d2be..507c84928f 100644 --- a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebTaskThreadFactory.java +++ b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/PaxWebTaskThreadFactory.java @@ -15,11 +15,6 @@ */ package org.ops4j.pax.web.service.tomcat.internal; -import java.security.AccessController; -import java.security.PrivilegedAction; - -import org.apache.tomcat.util.security.PrivilegedSetTccl; -import org.apache.tomcat.util.threads.Constants; import org.apache.tomcat.util.threads.TaskThreadFactory; public class PaxWebTaskThreadFactory extends TaskThreadFactory { @@ -35,12 +30,7 @@ public Thread newThread(Runnable r) { // and this is it - we need TCCL of the thread to be a CL from pax-web-tomcat, not // from pax-web-tomcat-common which would be used because org.apache.tomcat.util.threads.TaskThreadFactory // is container in pax-web-tomcat-common bundle - if (Constants.IS_SECURITY_ENABLED) { - PrivilegedAction pa = new PrivilegedSetTccl(t, TomcatFactory.class.getClassLoader()); - AccessController.doPrivileged(pa); - } else { - t.setContextClassLoader(TomcatFactory.class.getClassLoader()); - } + t.setContextClassLoader(TomcatFactory.class.getClassLoader()); return t; } diff --git a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/TomcatFactory.java b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/TomcatFactory.java index 54a134eca1..4bece59309 100644 --- a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/TomcatFactory.java +++ b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/TomcatFactory.java @@ -32,9 +32,10 @@ import org.apache.catalina.startup.ConnectorCreateRule; import org.apache.catalina.startup.ContextConfig; import org.apache.coyote.http2.Http2Protocol; -import org.apache.tomcat.util.compat.JreCompat; import org.apache.tomcat.util.digester.Digester; import org.apache.tomcat.util.digester.Rule; +import org.apache.tomcat.util.net.SSLHostConfig; +import org.apache.tomcat.util.net.SSLHostConfigCertificate; import org.ops4j.pax.web.service.spi.config.Configuration; import org.ops4j.pax.web.service.spi.config.SecurityConfiguration; import org.ops4j.pax.web.service.spi.config.ServerConfiguration; @@ -69,8 +70,7 @@ public class TomcatFactory { * Performs environmental discovery to check if we have some classes available on {@code CLASSPATH}. */ private void discovery() { - // that's how it's done in Tomcat. We may try to use Jetty ALPN bootclasspath approach later - alpnAvailable = JreCompat.isJre9Available(); + alpnAvailable = true; try { classLoader.loadClass("org.apache.coyote.http2.Http2Protocol"); @@ -225,54 +225,59 @@ public Connector createSecureConnector(Server server, String address, Executor e // --- server keystore for server's own identity + SSLHostConfig sslConfig = new SSLHostConfig(); + protocol.addSslHostConfig(sslConfig); + SSLHostConfigCertificate sslHostCertificate = new SSLHostConfigCertificate(sslConfig, SSLHostConfigCertificate.Type.UNDEFINED); + sslConfig.addCertificate(sslHostCertificate); + String sslKeystore = secc.getSslKeystore(); if (sslKeystore != null) { - protocol.setKeystoreFile(sslKeystore); + sslHostCertificate.setCertificateKeyFile(sslKeystore); } if (secc.getSslKeystorePassword() != null) { - protocol.setKeystorePass(secc.getSslKeystorePassword()); + sslHostCertificate.setCertificateKeystorePassword(secc.getSslKeystorePassword()); } if (secc.getSslKeyPassword() != null) { - protocol.setKeyPass(secc.getSslKeyPassword()); + sslHostCertificate.setCertificateKeyPassword(secc.getSslKeyPassword()); } if (secc.getSslKeyManagerFactoryAlgorithm() != null) { LOG.debug("Not supported SSL Key Algorithm parameter"); } if (secc.getSslKeyAlias() != null) { - protocol.setKeyAlias(secc.getSslKeyAlias()); + sslHostCertificate.setCertificateKeyAlias(secc.getSslKeyAlias()); } if (secc.getSslKeystoreType() != null) { - protocol.setKeystoreType(secc.getSslKeystoreType()); + sslHostCertificate.setCertificateKeystoreType(secc.getSslKeystoreType()); } if (secc.getSslKeystoreProvider() != null && !"".equals(secc.getSslKeystoreProvider().trim())) { - protocol.setKeystoreProvider(secc.getSslKeystoreProvider()); + sslHostCertificate.setCertificateKeystoreProvider(secc.getSslKeystoreProvider()); } // --- server truststore for client validation String sslTruststore = secc.getTruststore(); if (sslTruststore != null) { - protocol.setTruststoreFile(sslTruststore); + sslConfig.setTruststoreFile(sslTruststore); } if (secc.getTruststorePassword() != null) { - protocol.setTruststorePass(secc.getTruststorePassword()); + sslConfig.setTruststorePassword(secc.getTruststorePassword()); } if (secc.getTruststoreType() != null) { - protocol.setTruststoreType(secc.getTruststoreType()); + sslConfig.setTruststoreType(secc.getTruststoreType()); } if (secc.getTruststoreProvider() != null && !"".equals(secc.getTruststoreProvider().trim())) { - protocol.setTruststoreProvider(secc.getTruststoreProvider()); + sslConfig.setTruststoreProvider(secc.getTruststoreProvider()); } if (secc.getTrustManagerFactoryAlgorithm() != null) { - protocol.setTruststoreAlgorithm(secc.getTrustManagerFactoryAlgorithm()); + sslConfig.setTruststoreAlgorithm(secc.getTrustManagerFactoryAlgorithm()); } if (secc.isClientAuthWanted() != null && secc.isClientAuthWanted()) { - protocol.setClientAuth("want"); + sslConfig.setCertificateVerification("want"); // same as "optional" } if (secc.isClientAuthNeeded() != null && secc.isClientAuthNeeded()) { - protocol.setClientAuth("require"); + sslConfig.setCertificateVerification("require"); } // --- protocols and cipher suites @@ -290,14 +295,14 @@ public Connector createSecureConnector(Server server, String address, Executor e } if (secc.getProtocolsIncluded().length > 0) { - protocol.setSslEnabledProtocols(String.join(",", secc.getProtocolsIncluded())); + sslConfig.setEnabledProtocols(secc.getProtocolsIncluded()); } if (secc.getCiphersuiteIncluded().length > 0) { - protocol.setSSLCipherSuite(String.join(":", secc.getCiphersuiteIncluded())); + sslConfig.setCiphers(String.join(":", secc.getCiphersuiteIncluded())); } if (secc.getSslProtocol() != null) { - protocol.setSSLProtocol(secc.getSslProtocol()); + sslConfig.setSslProtocol(secc.getSslProtocol()); } if (secc.getSecureRandomAlgorithm() != null) { @@ -305,7 +310,7 @@ public Connector createSecureConnector(Server server, String address, Executor e } // javax.net.ssl.SSLParameters.setUseCipherSuitesOrder() - protocol.setUseServerCipherSuitesOrder(true); + sslConfig.setHonorCipherOrder(true); // --- SSL session and renegotiation @@ -317,12 +322,12 @@ public Connector createSecureConnector(Server server, String address, Executor e } if (secc.getSslSessionsEnabled() != null && !secc.getSslSessionsEnabled()) { - protocol.setSessionCacheSize(0); + sslConfig.setSessionCacheSize(0); } else if (secc.getSslSessionCacheSize() != null) { - protocol.setSessionCacheSize(secc.getSslSessionCacheSize()); + sslConfig.setSessionCacheSize(secc.getSslSessionCacheSize()); } if (secc.getSslSessionTimeout() != null) { - protocol.setSessionTimeout(secc.getSslSessionTimeout()); + sslConfig.setSessionTimeout(secc.getSslSessionTimeout()); } // TODO: certificate validation in Tomcat diff --git a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/TomcatServerController.java b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/TomcatServerController.java index 1027dfa373..f53546f3bc 100644 --- a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/TomcatServerController.java +++ b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/TomcatServerController.java @@ -21,7 +21,7 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; -import javax.servlet.Servlet; +import jakarta.servlet.Servlet; import org.ops4j.pax.web.service.spi.ServerController; import org.ops4j.pax.web.service.spi.ServerState; diff --git a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/TomcatServerWrapper.java b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/TomcatServerWrapper.java index 735b34b29e..d633f3e61b 100644 --- a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/TomcatServerWrapper.java +++ b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/TomcatServerWrapper.java @@ -36,13 +36,13 @@ import java.util.TreeMap; import java.util.TreeSet; import java.util.function.Supplier; -import javax.servlet.Servlet; -import javax.servlet.ServletContext; -import javax.servlet.ServletContextAttributeListener; -import javax.servlet.ServletContextListener; -import javax.servlet.SessionCookieConfig; -import javax.servlet.http.HttpSessionAttributeListener; -import javax.servlet.http.HttpSessionListener; +import jakarta.servlet.Servlet; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextAttributeListener; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.SessionCookieConfig; +import jakarta.servlet.http.HttpSessionAttributeListener; +import jakarta.servlet.http.HttpSessionListener; import org.apache.catalina.AccessLog; import org.apache.catalina.Container; @@ -215,8 +215,8 @@ class TomcatServerWrapper implements BatchVisitor { private final Map contextHandlers = new HashMap<>(); /** - * 1:1 mapping between {@link OsgiContextModel} and {@link org.osgi.service.http.context.ServletContextHelper}'s - * specific {@link javax.servlet.ServletContext}. + * 1:1 mapping between {@link OsgiContextModel} and {@link org.osgi.service.servlet.context.ServletContextHelper}'s + * specific {@link jakarta.servlet.ServletContext}. */ private final Map osgiServletContexts = new HashMap<>(); @@ -229,7 +229,7 @@ class TomcatServerWrapper implements BatchVisitor { /** * 1:N mapping between context path and sorted (by ranking rules) set of {@link OsgiContextModel}. This helps - * finding proper {@link org.osgi.service.http.context.ServletContextHelper} (1:1 with {@link OsgiContextModel}) + * finding proper {@link org.osgi.service.servlet.context.ServletContextHelper} (1:1 with {@link OsgiContextModel}) * to use for filters, when the invocation chain doesn't contain target servlet (which otherwise would * determine the ServletContextHelper to use). */ @@ -2056,7 +2056,7 @@ private void ensureServletContextStarted(PaxWebStandardContext context) { LOG.info("Starting Tomcat context \"{}\" with default Osgi Context {}", context, highestRanked); // first thing - only NOW we can set ServletContext's class loader! It affects many things, including - // the TCCL used for example by javax.el.ExpressionFactory.newInstance() + // the TCCL used for example by jakarta.el.ExpressionFactory.newInstance() // org.apache.catalina.core.ContainerBase.setParentClassLoader() sets the parent that // will be used as parent of org.apache.catalina.loader.ParallelWebappClassLoader returned diff --git a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/web/OsgiStandardRoot.java b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/web/OsgiStandardRoot.java index 4a5fb94d20..f1709686a7 100644 --- a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/web/OsgiStandardRoot.java +++ b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/web/OsgiStandardRoot.java @@ -27,7 +27,7 @@ import java.util.Collections; import java.util.Set; import java.util.jar.Manifest; -import javax.servlet.ServletContext; +import jakarta.servlet.ServletContext; import org.apache.catalina.LifecycleException; import org.apache.catalina.WebResource; diff --git a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/web/TomcatResourceServlet.java b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/web/TomcatResourceServlet.java index cfd11e5b22..6eca147c3b 100644 --- a/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/web/TomcatResourceServlet.java +++ b/pax-web-tomcat/src/main/java/org/ops4j/pax/web/service/tomcat/internal/web/TomcatResourceServlet.java @@ -17,13 +17,13 @@ import java.io.File; import java.io.IOException; -import javax.servlet.DispatcherType; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.UnavailableException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.DispatcherType; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.UnavailableException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.apache.catalina.Globals; import org.apache.catalina.LifecycleException; @@ -50,7 +50,7 @@ public class TomcatResourceServlet extends DefaultServlet { /** * If {@link #baseDirectory} is not specified, this is resource prefix to prepend when calling - * {@link org.osgi.service.http.context.ServletContextHelper#getResource(String)} + * {@link org.osgi.service.servlet.context.ServletContextHelper#getResource(String)} */ private final String chroot; diff --git a/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/EmbeddedTomcatHttp2Test.java b/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/EmbeddedTomcatHttp2Test.java index 8947b1ad25..294040168b 100644 --- a/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/EmbeddedTomcatHttp2Test.java +++ b/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/EmbeddedTomcatHttp2Test.java @@ -34,11 +34,11 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; -import javax.servlet.Servlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.PushBuilder; +import jakarta.servlet.Servlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.PushBuilder; import org.apache.catalina.Context; import org.apache.catalina.Engine; @@ -60,14 +60,12 @@ import org.apache.coyote.http2.PublicHpackDecoder; import org.apache.coyote.http2.PublicHpackEncoder; import org.apache.tomcat.util.http.MimeHeaders; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.startsWith; -import static org.hamcrest.MatcherAssert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class EmbeddedTomcatHttp2Test { @@ -79,7 +77,7 @@ public class EmbeddedTomcatHttp2Test { private PublicHpackDecoder decoder; private Map responses; - @Before + @BeforeEach public void resetState() { decoder = new PublicHpackDecoder(); responses = new HashMap<>(); @@ -434,7 +432,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO response = response.substring(0, rnrn + 4); } LOG.info("Response\n{}", response); - assertThat(fullResponse, startsWith("HTTP/1.1 101 \r\n")); + assertThat(fullResponse).startsWith("HTTP/1.1 101 \r\n"); buffer.position(rnrn + 4); boolean remains = true; while (remains) { @@ -492,9 +490,9 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO server.destroy(); // indexed by HTTP/2 Stream ID - assertThat(responses.get(1), equalTo("OK\n")); - assertThat(responses.get(2), equalTo("body { margin: 0 }\n")); - assertThat(responses.get(4), equalTo("window.alert(\"hello world\");\n")); + assertThat(responses.get(1)).isEqualTo("OK\n"); + assertThat(responses.get(2)).isEqualTo("body { margin: 0 }\n"); + assertThat(responses.get(4)).isEqualTo("window.alert(\"hello world\");\n"); } @Test @@ -722,9 +720,9 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO server.destroy(); // indexed by HTTP/2 Stream ID - assertThat(responses.get(1), equalTo("OK\n")); - assertThat(responses.get(2), equalTo("body { margin: 0 }\n")); - assertThat(responses.get(4), equalTo("window.alert(\"hello world\");\n")); + assertThat(responses.get(1)).isEqualTo("OK\n"); + assertThat(responses.get(2)).isEqualTo("body { margin: 0 }\n"); + assertThat(responses.get(4)).isEqualTo("window.alert(\"hello world\");\n"); } private void send(Selector selector, SelectionKey key, ByteBuffer buffer) throws IOException { @@ -805,7 +803,7 @@ private boolean decodeFrame(ByteBuffer buffer, boolean incoming) throws IOExcept byte[] payload = new byte[length]; int read = dis.read(payload, 0, length); if (read >= 0) { - assertThat(read, equalTo(length)); + assertThat(read).isEqualTo(length); } buffer.position(buffer.position() + 3 + 1 + 1 + 4 + length); diff --git a/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/EmbeddedTomcatHttps2Test.java b/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/EmbeddedTomcatHttps2Test.java index e4d45d7138..92dcea999d 100644 --- a/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/EmbeddedTomcatHttps2Test.java +++ b/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/EmbeddedTomcatHttps2Test.java @@ -29,11 +29,11 @@ import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManagerFactory; -import javax.servlet.Servlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.PushBuilder; +import jakarta.servlet.Servlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.PushBuilder; import org.apache.catalina.Context; import org.apache.catalina.Engine; @@ -84,11 +84,13 @@ import org.apache.hc.core5.http2.config.H2Config; import org.apache.hc.core5.io.CloseMode; import org.apache.tomcat.util.file.ConfigFileLoader; -import org.junit.Test; +import org.apache.tomcat.util.net.SSLHostConfig; +import org.apache.tomcat.util.net.SSLHostConfigCertificate; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; public class EmbeddedTomcatHttps2Test { @@ -122,28 +124,33 @@ public void https2NioExchange() throws Exception { AbstractHttp11JsseProtocol protocol = (AbstractHttp11JsseProtocol) connector.getProtocolHandler(); protocol.setSslImplementationName("org.apache.tomcat.util.net.jsse.JSSEImplementation"); - protocol.setKeystoreFile("../../pax-web-itest/etc/security/server.jks"); - protocol.setKeystorePass("passw0rd"); - protocol.setKeystoreType("JKS"); - protocol.setKeystoreProvider("SUN"); - protocol.setKeyPass("passw0rd"); - protocol.setKeyAlias("server"); - - protocol.setTruststoreFile("../../pax-web-itest/etc/security/server.jks"); - protocol.setTruststorePass("passw0rd"); - protocol.setTruststoreType("JKS"); - protocol.setTruststoreProvider("SUN"); - protocol.setTruststoreAlgorithm("SunX509"); - - protocol.setSslEnabledProtocols("TLSv1.3"); + SSLHostConfig sslConfig = new SSLHostConfig(); + protocol.addSslHostConfig(sslConfig); + SSLHostConfigCertificate sslHostCertificate = new SSLHostConfigCertificate(sslConfig, SSLHostConfigCertificate.Type.UNDEFINED); + sslConfig.addCertificate(sslHostCertificate); + + sslHostCertificate.setCertificateKeystoreFile("../../pax-web-itest/etc/security/server.jks"); + sslHostCertificate.setCertificateKeystorePassword("passw0rd"); + sslHostCertificate.setCertificateKeystoreType("JKS"); + sslHostCertificate.setCertificateKeystoreProvider("SUN"); + sslHostCertificate.setCertificateKeyPassword("passw0rd"); + sslHostCertificate.setCertificateKeyAlias("server"); + + sslConfig.setTruststoreFile("../../pax-web-itest/etc/security/server.jks"); + sslConfig.setTruststorePassword("passw0rd"); + sslConfig.setTruststoreType("JKS"); + sslConfig.setTruststoreProvider("SUN"); + sslConfig.setTruststoreAlgorithm("SunX509"); + + sslConfig.setEnabledProtocols(new String[] { "TLSv1.3" }); // only TWO ciphers are supported on JDK8 for TLSv1.3 // - sun.security.ssl.ProtocolVersion.PROTOCOLS_OF_13 is used only in TLS_AES_256_GCM_SHA384 and // TLS_AES_128_GCM_SHA256 in sun.security.ssl.CipherSuite // - sun.security.ssl.ProtocolVersion.PROTOCOLS_12_13 is not used at all // - sun.security.ssl.ProtocolVersion.PROTOCOLS_TO_13 is not used at all - protocol.setSSLCipherSuite("TLS_AES_256_GCM_SHA384"); - protocol.setSSLProtocol("TLSv1.3"); - protocol.setUseServerCipherSuitesOrder(true); + sslConfig.setCiphers("TLS_AES_256_GCM_SHA384"); + sslConfig.setSslProtocol("TLSv1.3"); + sslConfig.setHonorCipherOrder(true); connector.addUpgradeProtocol(new Http2Protocol()); service.addConnector(connector); diff --git a/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/EmbeddedTomcatTest.java b/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/EmbeddedTomcatTest.java index 581392fb4b..541bb8d569 100644 --- a/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/EmbeddedTomcatTest.java +++ b/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/EmbeddedTomcatTest.java @@ -30,22 +30,22 @@ import java.util.Set; import java.util.jar.JarOutputStream; import java.util.zip.ZipEntry; -import javax.servlet.DispatcherType; -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.GenericFilter; -import javax.servlet.Servlet; -import javax.servlet.ServletContainerInitializer; -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.DispatcherType; +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.GenericFilter; +import jakarta.servlet.Servlet; +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.apache.catalina.Context; import org.apache.catalina.Engine; @@ -80,29 +80,28 @@ import org.apache.tomcat.util.descriptor.web.FilterDef; import org.apache.tomcat.util.descriptor.web.FilterMap; import org.apache.tomcat.util.digester.Digester; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.bridge.SLF4JBridgeHandler; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class EmbeddedTomcatTest { public static final Logger LOG = LoggerFactory.getLogger(EmbeddedTomcatTest.class); - @BeforeClass + @BeforeAll public static void initClass() { SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); } - @AfterClass + @AfterAll public static void cleanupClass() { SLF4JBridgeHandler.uninstall(); } @@ -311,8 +310,8 @@ public void contextInitialized(ServletContextEvent sce) { // listener class names from web.xml, web-fragment.xml and @WebListener are added to the context using this // method. context.addApplicationListener("org.ops4j.pax.web.service.tomcat.internal.ServletContextListenerAddedFromWebXml"); - // this method is called from dynamic sc.addListener() IF the listener implements javax.servlet.http.HttpSessionListener - // or javax.servlet.ServletContextListener (the latter ONLY when org.apache.catalina.core.ApplicationContext.newServletContextListenerAllowed==true) + // this method is called from dynamic sc.addListener() IF the listener implements jakarta.servlet.http.HttpSessionListener + // or jakarta.servlet.ServletContextListener (the latter ONLY when org.apache.catalina.core.ApplicationContext.newServletContextListenerAllowed==true) // when ApplicationContext.newServletContextListenerAllowed==false, ServletContextListener is treated // as programmatic, so Tomcat throws // IllegalArgumentException("Once the first ServletContextListener has been called, no more ServletContextListeners may be added.") @@ -718,7 +717,7 @@ public Digester createStartDigester() { StandardServer server = (StandardServer) holder.getServer(); Service catalina = server.findService("Catalina"); Connector connector = catalina.findConnectors()[0]; - assertThat(((StandardThreadExecutor) catalina.getExecutor("default")).getNamePrefix(), equalTo("tomcat-pool-")); + assertThat(((StandardThreadExecutor) catalina.getExecutor("default")).getNamePrefix()).isEqualTo("tomcat-pool-"); server.start(); @@ -781,7 +780,7 @@ public Digester createStartDigester() { StandardServer server = (StandardServer) holder.getServer(); Service catalina = server.findService("Catalina"); Connector connector = catalina.findConnectors()[0]; - assertThat(((StandardThreadExecutor) catalina.getExecutor("default")).getNamePrefix(), equalTo("tomcat-pool-")); + assertThat(((StandardThreadExecutor) catalina.getExecutor("default")).getNamePrefix()).isEqualTo("tomcat-pool-"); server.start(); diff --git a/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/PathTest.java b/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/PathTest.java index 2d8fcf7e8c..f7f7aa6be9 100644 --- a/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/PathTest.java +++ b/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/PathTest.java @@ -16,32 +16,30 @@ package org.ops4j.pax.web.service.tomcat.internal; import org.apache.tomcat.util.http.RequestUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.MatcherAssert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class PathTest { @Test public void securePaths() { - assertThat(RequestUtil.normalize(""), equalTo("/")); - assertThat(RequestUtil.normalize("/"), equalTo("/")); - assertThat(RequestUtil.normalize("c:"), equalTo("/c:")); - assertThat(RequestUtil.normalize("c:/"), equalTo("/c:/")); - assertThat(RequestUtil.normalize("c:\\"), equalTo("/c:/")); - assertThat(RequestUtil.normalize("//"), equalTo("/")); - assertThat(RequestUtil.normalize("."), equalTo("/")); - assertThat(RequestUtil.normalize(".."), nullValue()); - assertThat(RequestUtil.normalize("../.."), nullValue()); - assertThat(RequestUtil.normalize("./././././././."), equalTo("/")); - assertThat(RequestUtil.normalize("../../../../../etc/passwd"), nullValue()); - assertThat(RequestUtil.normalize("path1"), equalTo("/path1")); - assertThat(RequestUtil.normalize("./path1"), equalTo("/path1")); - assertThat(RequestUtil.normalize("../path1"), nullValue()); - assertThat(RequestUtil.normalize("path1/path2"), equalTo("/path1/path2")); - assertThat(RequestUtil.normalize("path1/../path2"), equalTo("/path2")); + assertThat(RequestUtil.normalize("")).isEqualTo("/"); + assertThat(RequestUtil.normalize("/")).isEqualTo("/"); + assertThat(RequestUtil.normalize("c:")).isEqualTo("/c:"); + assertThat(RequestUtil.normalize("c:/")).isEqualTo("/c:/"); + assertThat(RequestUtil.normalize("c:\\")).isEqualTo("/c:/"); + assertThat(RequestUtil.normalize("//")).isEqualTo("/"); + assertThat(RequestUtil.normalize(".")).isEqualTo("/"); + assertThat(RequestUtil.normalize("..")).isNull(); + assertThat(RequestUtil.normalize("../..")).isNull(); + assertThat(RequestUtil.normalize("./././././././.")).isEqualTo("/"); + assertThat(RequestUtil.normalize("../../../../../etc/passwd")).isNull(); + assertThat(RequestUtil.normalize("path1")).isEqualTo("/path1"); + assertThat(RequestUtil.normalize("./path1")).isEqualTo("/path1"); + assertThat(RequestUtil.normalize("../path1")).isNull(); + assertThat(RequestUtil.normalize("path1/path2")).isEqualTo("/path1/path2"); + assertThat(RequestUtil.normalize("path1/../path2")).isEqualTo("/path2"); } } diff --git a/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/ServletContextListenerAddedFromWebXml.java b/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/ServletContextListenerAddedFromWebXml.java index ecfc23a928..053f92f490 100644 --- a/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/ServletContextListenerAddedFromWebXml.java +++ b/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/ServletContextListenerAddedFromWebXml.java @@ -15,8 +15,8 @@ */ package org.ops4j.pax.web.service.tomcat.internal; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; public class ServletContextListenerAddedFromWebXml implements ServletContextListener { diff --git a/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/UnifiedTomcatTest.java b/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/UnifiedTomcatTest.java index 65639b7bb3..5f841b9fda 100644 --- a/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/UnifiedTomcatTest.java +++ b/pax-web-tomcat/src/test/java/org/ops4j/pax/web/service/tomcat/internal/UnifiedTomcatTest.java @@ -26,11 +26,11 @@ import java.util.Arrays; import java.util.LinkedHashMap; import java.util.Map; -import javax.servlet.Servlet; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.Servlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.apache.catalina.Context; import org.apache.catalina.Engine; @@ -55,16 +55,14 @@ import org.apache.catalina.valves.ValveBase; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.ops4j.pax.web.service.tomcat.internal.web.TomcatResourceServlet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.hamcrest.CoreMatchers.endsWith; -import static org.hamcrest.CoreMatchers.startsWith; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test that has matching tests in pax-web-jetty and pax-web-undertow @@ -265,11 +263,11 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se int port = connector.getLocalPort(); String response = send(port, "/"); - assertThat(response, endsWith("'indexx'")); + assertThat(response).endsWith("'indexx'"); response = send(port, "/sub/"); - assertThat(response, endsWith("'sub/index'")); + assertThat(response).endsWith("'sub/index'"); response = send(port, "/sub"); - assertThat(response, startsWith("HTTP/1.1 302")); + assertThat(response).startsWith("HTTP/1.1 302"); server.stop(); server.destroy(); @@ -350,20 +348,20 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se int port = connector.getLocalPort(); String response = send(port, "/"); - assertThat(response, startsWith("HTTP/1.1 404")); + assertThat(response).startsWith("HTTP/1.1 404"); response = send(port, "/sub/"); - assertThat(response, startsWith("HTTP/1.1 404")); + assertThat(response).startsWith("HTTP/1.1 404"); response = send(port, "/sub"); - assertThat(response, startsWith("HTTP/1.1 404")); + assertThat(response).startsWith("HTTP/1.1 404"); response = send(port, "/c"); - assertThat(response, startsWith("HTTP/1.1 302")); + assertThat(response).startsWith("HTTP/1.1 302"); response = send(port, "/c/"); - assertThat(response, endsWith("'indexx'")); + assertThat(response).endsWith("'indexx'"); response = send(port, "/c/sub/"); - assertThat(response, endsWith("'sub/index'")); + assertThat(response).endsWith("'sub/index'"); response = send(port, "/c/sub"); - assertThat(response, startsWith("HTTP/1.1 302")); + assertThat(response).startsWith("HTTP/1.1 302"); server.stop(); server.destroy(); @@ -444,9 +442,9 @@ public void resourceServletWithWelcomePages() throws Exception { assertTrue(response.contains("HTTP/1.1 404")); response = send(port, "/d1/hello.txt"); - assertThat(response, endsWith("'hello.txt'")); + assertThat(response).endsWith("'hello.txt'"); response = send(port, "/d1/sub/hello.txt"); - assertThat(response, endsWith("'sub/hello.txt'")); + assertThat(response).endsWith("'sub/hello.txt'"); response = send(port, "/d1/../hello.txt"); assertTrue(response.contains("HTTP/1.1 404")); @@ -455,13 +453,13 @@ public void resourceServletWithWelcomePages() throws Exception { // Tomcat and Undertow, such support has to be added. response = send(port, "/d1/"); - assertThat(response, endsWith("'index.txt'")); + assertThat(response).endsWith("'index.txt'"); response = send(port, "/d1/sub/"); - assertThat(response, endsWith("'sub/index.txt'")); + assertThat(response).endsWith("'sub/index.txt'"); response = send(port, "/d1"); - assertThat(response, startsWith("HTTP/1.1 302")); + assertThat(response).startsWith("HTTP/1.1 302"); response = send(port, "/d1/sub"); - assertThat(response, startsWith("HTTP/1.1 302")); + assertThat(response).startsWith("HTTP/1.1 302"); server.stop(); server.destroy(); @@ -575,18 +573,18 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se resp.getWriter().println("req.servlet_path=\"" + req.getServletPath() + "\""); resp.getWriter().println("req.path_info=\"" + req.getPathInfo() + "\""); resp.getWriter().println("req.query_string=\"" + req.getQueryString() + "\""); - resp.getWriter().println("javax.servlet.forward.mapping=\"" + req.getAttribute("javax.servlet.forward.mapping") + "\""); - resp.getWriter().println("javax.servlet.forward.request_uri=\"" + req.getAttribute("javax.servlet.forward.request_uri") + "\""); - resp.getWriter().println("javax.servlet.forward.context_path=\"" + req.getAttribute("javax.servlet.forward.context_path") + "\""); - resp.getWriter().println("javax.servlet.forward.servlet_path=\"" + req.getAttribute("javax.servlet.forward.servlet_path") + "\""); - resp.getWriter().println("javax.servlet.forward.path_info=\"" + req.getAttribute("javax.servlet.forward.path_info") + "\""); - resp.getWriter().println("javax.servlet.forward.query_string=\"" + req.getAttribute("javax.servlet.forward.query_string") + "\""); - resp.getWriter().println("javax.servlet.include.mapping=\"" + req.getAttribute("javax.servlet.include.mapping") + "\""); - resp.getWriter().println("javax.servlet.include.request_uri=\"" + req.getAttribute("javax.servlet.include.request_uri") + "\""); - resp.getWriter().println("javax.servlet.include.context_path=\"" + req.getAttribute("javax.servlet.include.context_path") + "\""); - resp.getWriter().println("javax.servlet.include.servlet_path=\"" + req.getAttribute("javax.servlet.include.servlet_path") + "\""); - resp.getWriter().println("javax.servlet.include.path_info=\"" + req.getAttribute("javax.servlet.include.path_info") + "\""); - resp.getWriter().println("javax.servlet.include.query_string=\"" + req.getAttribute("javax.servlet.include.query_string") + "\""); + resp.getWriter().println("jakarta.servlet.forward.mapping=\"" + req.getAttribute("jakarta.servlet.forward.mapping") + "\""); + resp.getWriter().println("jakarta.servlet.forward.request_uri=\"" + req.getAttribute("jakarta.servlet.forward.request_uri") + "\""); + resp.getWriter().println("jakarta.servlet.forward.context_path=\"" + req.getAttribute("jakarta.servlet.forward.context_path") + "\""); + resp.getWriter().println("jakarta.servlet.forward.servlet_path=\"" + req.getAttribute("jakarta.servlet.forward.servlet_path") + "\""); + resp.getWriter().println("jakarta.servlet.forward.path_info=\"" + req.getAttribute("jakarta.servlet.forward.path_info") + "\""); + resp.getWriter().println("jakarta.servlet.forward.query_string=\"" + req.getAttribute("jakarta.servlet.forward.query_string") + "\""); + resp.getWriter().println("jakarta.servlet.include.mapping=\"" + req.getAttribute("jakarta.servlet.include.mapping") + "\""); + resp.getWriter().println("jakarta.servlet.include.request_uri=\"" + req.getAttribute("jakarta.servlet.include.request_uri") + "\""); + resp.getWriter().println("jakarta.servlet.include.context_path=\"" + req.getAttribute("jakarta.servlet.include.context_path") + "\""); + resp.getWriter().println("jakarta.servlet.include.servlet_path=\"" + req.getAttribute("jakarta.servlet.include.servlet_path") + "\""); + resp.getWriter().println("jakarta.servlet.include.path_info=\"" + req.getAttribute("jakarta.servlet.include.path_info") + "\""); + resp.getWriter().println("jakarta.servlet.include.query_string=\"" + req.getAttribute("jakarta.servlet.include.query_string") + "\""); } }; indexxWrapper.setServlet(indexxServlet); @@ -638,15 +636,15 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se response = send(port, "/"); assertTrue(response.contains("req.context_path=\"\"")); assertTrue(response.contains("req.request_uri=\"/index.y\"")); - assertTrue(response.contains("javax.servlet.forward.request_uri=\"/\"")); + assertTrue(response.contains("jakarta.servlet.forward.request_uri=\"/\"")); // Forward vs. Include: // in forward method: - // - original servletPath, pathInfo, requestURI are available ONLY through javax.servlet.forward.* attributes + // - original servletPath, pathInfo, requestURI are available ONLY through jakarta.servlet.forward.* attributes // - values used to obtain the dispatcher are available through request object // in include method: // - original servletPath, pathInfo, requestURI are available through request object - // - values used to obtain the dispatcher are available through javax.servlet.include.* attributes + // - values used to obtain the dispatcher are available through jakarta.servlet.include.* attributes // "/" (but through gateway) - similar forward, but performed explicitly by gateway servlet // 9.4 The Forward Method: @@ -656,20 +654,20 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se response = send(port, "/gateway/x?what=forward&where=/"); assertTrue(response.contains("req.context_path=\"\"")); assertTrue(response.contains("req.request_uri=\"/index.y\"")); - assertTrue(response.contains("javax.servlet.forward.context_path=\"\"")); - assertTrue(response.contains("javax.servlet.forward.request_uri=\"/gateway/x\"")); - assertTrue(response.contains("javax.servlet.forward.servlet_path=\"/gateway\"")); - assertTrue(response.contains("javax.servlet.forward.path_info=\"/x\"")); + assertTrue(response.contains("jakarta.servlet.forward.context_path=\"\"")); + assertTrue(response.contains("jakarta.servlet.forward.request_uri=\"/gateway/x\"")); + assertTrue(response.contains("jakarta.servlet.forward.servlet_path=\"/gateway\"")); + assertTrue(response.contains("jakarta.servlet.forward.path_info=\"/x\"")); // "/", but included by gateway servlet // "gateway" includes "/" which includes "/index.y" response = send(port, "/gateway/x?what=include&where=/"); assertTrue(response.contains("req.context_path=\"\"")); assertTrue(response.contains("req.request_uri=\"/gateway/x\"")); - assertTrue(response.contains("javax.servlet.include.context_path=\"\"")); - assertTrue(response.contains("javax.servlet.include.request_uri=\"/index.y\"")); - assertTrue(response.contains("javax.servlet.include.servlet_path=\"/index.y\"")); - assertTrue(response.contains("javax.servlet.include.path_info=\"null\"")); + assertTrue(response.contains("jakarta.servlet.include.context_path=\"\"")); + assertTrue(response.contains("jakarta.servlet.include.request_uri=\"/index.y\"")); + assertTrue(response.contains("jakarta.servlet.include.servlet_path=\"/index.y\"")); + assertTrue(response.contains("jakarta.servlet.include.path_info=\"null\"")); response = send(port, "/sub"); assertTrue(response.startsWith("HTTP/1.1 302")); @@ -695,26 +693,26 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se response = send(port, "/sub/"); assertTrue(response.contains("req.context_path=\"\"")); assertTrue(response.contains("req.request_uri=\"/sub/index.x\"")); - assertTrue(response.contains("javax.servlet.forward.context_path=\"\"")); - assertTrue(response.contains("javax.servlet.forward.request_uri=\"/sub/\"")); - assertTrue(response.contains("javax.servlet.forward.servlet_path=\"/sub/\"")); - assertTrue(response.contains("javax.servlet.forward.path_info=\"null\"")); + assertTrue(response.contains("jakarta.servlet.forward.context_path=\"\"")); + assertTrue(response.contains("jakarta.servlet.forward.request_uri=\"/sub/\"")); + assertTrue(response.contains("jakarta.servlet.forward.servlet_path=\"/sub/\"")); + assertTrue(response.contains("jakarta.servlet.forward.path_info=\"null\"")); response = send(port, "/gateway/x?what=forward&where=/sub/"); assertTrue(response.contains("req.context_path=\"\"")); assertTrue(response.contains("req.request_uri=\"/sub/index.x\"")); - assertTrue(response.contains("javax.servlet.forward.context_path=\"\"")); - assertTrue(response.contains("javax.servlet.forward.request_uri=\"/gateway/x\"")); - assertTrue(response.contains("javax.servlet.forward.servlet_path=\"/gateway\"")); - assertTrue(response.contains("javax.servlet.forward.path_info=\"/x\"")); + assertTrue(response.contains("jakarta.servlet.forward.context_path=\"\"")); + assertTrue(response.contains("jakarta.servlet.forward.request_uri=\"/gateway/x\"")); + assertTrue(response.contains("jakarta.servlet.forward.servlet_path=\"/gateway\"")); + assertTrue(response.contains("jakarta.servlet.forward.path_info=\"/x\"")); response = send(port, "/gateway/x?what=include&where=/sub/"); assertTrue(response.contains("req.context_path=\"\"")); assertTrue(response.contains("req.request_uri=\"/gateway/x\"")); - assertTrue(response.contains("javax.servlet.include.context_path=\"\"")); - assertTrue(response.contains("javax.servlet.include.request_uri=\"/sub/index.x\"")); - assertTrue(response.contains("javax.servlet.include.servlet_path=\"/sub/index.x\"")); - assertTrue(response.contains("javax.servlet.include.path_info=\"null\"")); + assertTrue(response.contains("jakarta.servlet.include.context_path=\"\"")); + assertTrue(response.contains("jakarta.servlet.include.request_uri=\"/sub/index.x\"")); + assertTrue(response.contains("jakarta.servlet.include.servlet_path=\"/sub/index.x\"")); + assertTrue(response.contains("jakarta.servlet.include.path_info=\"null\"")); // --- resource access through "/r" servlet @@ -909,18 +907,18 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se resp.getWriter().println("req.servlet_path=\"" + req.getServletPath() + "\""); resp.getWriter().println("req.path_info=\"" + req.getPathInfo() + "\""); resp.getWriter().println("req.query_string=\"" + req.getQueryString() + "\""); - resp.getWriter().println("javax.servlet.forward.mapping=\"" + req.getAttribute("javax.servlet.forward.mapping") + "\""); - resp.getWriter().println("javax.servlet.forward.request_uri=\"" + req.getAttribute("javax.servlet.forward.request_uri") + "\""); - resp.getWriter().println("javax.servlet.forward.context_path=\"" + req.getAttribute("javax.servlet.forward.context_path") + "\""); - resp.getWriter().println("javax.servlet.forward.servlet_path=\"" + req.getAttribute("javax.servlet.forward.servlet_path") + "\""); - resp.getWriter().println("javax.servlet.forward.path_info=\"" + req.getAttribute("javax.servlet.forward.path_info") + "\""); - resp.getWriter().println("javax.servlet.forward.query_string=\"" + req.getAttribute("javax.servlet.forward.query_string") + "\""); - resp.getWriter().println("javax.servlet.include.mapping=\"" + req.getAttribute("javax.servlet.include.mapping") + "\""); - resp.getWriter().println("javax.servlet.include.request_uri=\"" + req.getAttribute("javax.servlet.include.request_uri") + "\""); - resp.getWriter().println("javax.servlet.include.context_path=\"" + req.getAttribute("javax.servlet.include.context_path") + "\""); - resp.getWriter().println("javax.servlet.include.servlet_path=\"" + req.getAttribute("javax.servlet.include.servlet_path") + "\""); - resp.getWriter().println("javax.servlet.include.path_info=\"" + req.getAttribute("javax.servlet.include.path_info") + "\""); - resp.getWriter().println("javax.servlet.include.query_string=\"" + req.getAttribute("javax.servlet.include.query_string") + "\""); + resp.getWriter().println("jakarta.servlet.forward.mapping=\"" + req.getAttribute("jakarta.servlet.forward.mapping") + "\""); + resp.getWriter().println("jakarta.servlet.forward.request_uri=\"" + req.getAttribute("jakarta.servlet.forward.request_uri") + "\""); + resp.getWriter().println("jakarta.servlet.forward.context_path=\"" + req.getAttribute("jakarta.servlet.forward.context_path") + "\""); + resp.getWriter().println("jakarta.servlet.forward.servlet_path=\"" + req.getAttribute("jakarta.servlet.forward.servlet_path") + "\""); + resp.getWriter().println("jakarta.servlet.forward.path_info=\"" + req.getAttribute("jakarta.servlet.forward.path_info") + "\""); + resp.getWriter().println("jakarta.servlet.forward.query_string=\"" + req.getAttribute("jakarta.servlet.forward.query_string") + "\""); + resp.getWriter().println("jakarta.servlet.include.mapping=\"" + req.getAttribute("jakarta.servlet.include.mapping") + "\""); + resp.getWriter().println("jakarta.servlet.include.request_uri=\"" + req.getAttribute("jakarta.servlet.include.request_uri") + "\""); + resp.getWriter().println("jakarta.servlet.include.context_path=\"" + req.getAttribute("jakarta.servlet.include.context_path") + "\""); + resp.getWriter().println("jakarta.servlet.include.servlet_path=\"" + req.getAttribute("jakarta.servlet.include.servlet_path") + "\""); + resp.getWriter().println("jakarta.servlet.include.path_info=\"" + req.getAttribute("jakarta.servlet.include.path_info") + "\""); + resp.getWriter().println("jakarta.servlet.include.query_string=\"" + req.getAttribute("jakarta.servlet.include.query_string") + "\""); } }; indexxWrapper.setServlet(indexxServlet); @@ -972,15 +970,15 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se response = send(port, "/c/"); assertTrue(response.contains("req.context_path=\"/c\"")); assertTrue(response.contains("req.request_uri=\"/c/index.y\"")); - assertTrue(response.contains("javax.servlet.forward.request_uri=\"/c/\"")); + assertTrue(response.contains("jakarta.servlet.forward.request_uri=\"/c/\"")); // Forward vs. Include: // in forward method: - // - original servletPath, pathInfo, requestURI are available ONLY through javax.servlet.forward.* attributes + // - original servletPath, pathInfo, requestURI are available ONLY through jakarta.servlet.forward.* attributes // - values used to obtain the dispatcher are available through request object // in include method: // - original servletPath, pathInfo, requestURI are available through request object - // - values used to obtain the dispatcher are available through javax.servlet.include.* attributes + // - values used to obtain the dispatcher are available through jakarta.servlet.include.* attributes // "/" (but through gateway) - similar forward, but performed explicitly by gateway servlet // 9.4 The Forward Method: @@ -990,20 +988,20 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se response = send(port, "/c/gateway/x?what=forward&where=/"); assertTrue(response.contains("req.context_path=\"/c\"")); assertTrue(response.contains("req.request_uri=\"/c/index.y\"")); - assertTrue(response.contains("javax.servlet.forward.context_path=\"/c\"")); - assertTrue(response.contains("javax.servlet.forward.request_uri=\"/c/gateway/x\"")); - assertTrue(response.contains("javax.servlet.forward.servlet_path=\"/gateway\"")); - assertTrue(response.contains("javax.servlet.forward.path_info=\"/x\"")); + assertTrue(response.contains("jakarta.servlet.forward.context_path=\"/c\"")); + assertTrue(response.contains("jakarta.servlet.forward.request_uri=\"/c/gateway/x\"")); + assertTrue(response.contains("jakarta.servlet.forward.servlet_path=\"/gateway\"")); + assertTrue(response.contains("jakarta.servlet.forward.path_info=\"/x\"")); // "/", but included by gateway servlet // "gateway" includes "/" which includes "/index.y" response = send(port, "/c/gateway/x?what=include&where=/"); assertTrue(response.contains("req.context_path=\"/c\"")); assertTrue(response.contains("req.request_uri=\"/c/gateway/x\"")); - assertTrue(response.contains("javax.servlet.include.context_path=\"/c\"")); - assertTrue(response.contains("javax.servlet.include.request_uri=\"/c/index.y\"")); - assertTrue(response.contains("javax.servlet.include.servlet_path=\"/index.y\"")); - assertTrue(response.contains("javax.servlet.include.path_info=\"null\"")); + assertTrue(response.contains("jakarta.servlet.include.context_path=\"/c\"")); + assertTrue(response.contains("jakarta.servlet.include.request_uri=\"/c/index.y\"")); + assertTrue(response.contains("jakarta.servlet.include.servlet_path=\"/index.y\"")); + assertTrue(response.contains("jakarta.servlet.include.path_info=\"null\"")); response = send(port, "/c/sub"); assertTrue(response.startsWith("HTTP/1.1 302")); @@ -1029,26 +1027,26 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se response = send(port, "/c/sub/"); assertTrue(response.contains("req.context_path=\"/c\"")); assertTrue(response.contains("req.request_uri=\"/c/sub/index.x\"")); - assertTrue(response.contains("javax.servlet.forward.context_path=\"/c\"")); - assertTrue(response.contains("javax.servlet.forward.request_uri=\"/c/sub/\"")); - assertTrue(response.contains("javax.servlet.forward.servlet_path=\"/sub/\"")); - assertTrue(response.contains("javax.servlet.forward.path_info=\"null\"")); + assertTrue(response.contains("jakarta.servlet.forward.context_path=\"/c\"")); + assertTrue(response.contains("jakarta.servlet.forward.request_uri=\"/c/sub/\"")); + assertTrue(response.contains("jakarta.servlet.forward.servlet_path=\"/sub/\"")); + assertTrue(response.contains("jakarta.servlet.forward.path_info=\"null\"")); response = send(port, "/c/gateway/x?what=forward&where=/sub/"); assertTrue(response.contains("req.context_path=\"/c\"")); assertTrue(response.contains("req.request_uri=\"/c/sub/index.x\"")); - assertTrue(response.contains("javax.servlet.forward.context_path=\"/c\"")); - assertTrue(response.contains("javax.servlet.forward.request_uri=\"/c/gateway/x\"")); - assertTrue(response.contains("javax.servlet.forward.servlet_path=\"/gateway\"")); - assertTrue(response.contains("javax.servlet.forward.path_info=\"/x\"")); + assertTrue(response.contains("jakarta.servlet.forward.context_path=\"/c\"")); + assertTrue(response.contains("jakarta.servlet.forward.request_uri=\"/c/gateway/x\"")); + assertTrue(response.contains("jakarta.servlet.forward.servlet_path=\"/gateway\"")); + assertTrue(response.contains("jakarta.servlet.forward.path_info=\"/x\"")); response = send(port, "/c/gateway/x?what=include&where=/sub/"); assertTrue(response.contains("req.context_path=\"/c\"")); assertTrue(response.contains("req.request_uri=\"/c/gateway/x\"")); - assertTrue(response.contains("javax.servlet.include.context_path=\"/c\"")); - assertTrue(response.contains("javax.servlet.include.request_uri=\"/c/sub/index.x\"")); - assertTrue(response.contains("javax.servlet.include.servlet_path=\"/sub/index.x\"")); - assertTrue(response.contains("javax.servlet.include.path_info=\"null\"")); + assertTrue(response.contains("jakarta.servlet.include.context_path=\"/c\"")); + assertTrue(response.contains("jakarta.servlet.include.request_uri=\"/c/sub/index.x\"")); + assertTrue(response.contains("jakarta.servlet.include.servlet_path=\"/sub/index.x\"")); + assertTrue(response.contains("jakarta.servlet.include.path_info=\"null\"")); // --- resource access through "/r" servlet @@ -1240,7 +1238,7 @@ public void invoke(Request request, Response response) throws IOException, Servl // - path info = "/" // - servlet path == "" // - context path == "" - // - match type = javax.servlet.http.MappingMatch.CONTEXT_ROOT + // - match type = jakarta.servlet.http.MappingMatch.CONTEXT_ROOT rootContext.addServletMappingDecoded("", wrapper1.getName(), false); // A string containing only the '/' character indicates the "default" servlet of the application. @@ -1266,15 +1264,15 @@ public void invoke(Request request, Response response) throws IOException, Servl // Tomcat mapping is done in 3 stages: // - host finding: org.apache.catalina.connector.CoyoteAdapter.postParseRequest() - // - javax.servlet.ServletRequest.getServerName() is set to match "Host" HTTP header - // - javax.servlet.ServletRequest.getLocalName() is set to result of: + // - jakarta.servlet.ServletRequest.getServerName() is set to match "Host" HTTP header + // - jakarta.servlet.ServletRequest.getLocalName() is set to result of: // - NIO: java.net.Socket.getLocalAddress().getHostName() // - NIO2: java.nio.channels.AsynchronousSocketChannel.getLocalAddress().getHostName() // - APR: org.apache.tomcat.jni.Address.getnameinfo() // - org.apache.catalina.connector.Connector.getUseIPVHosts() == true - // - host is chosed directly from javax.servlet.ServletRequest.getLocalName() + // - host is chosed directly from jakarta.servlet.ServletRequest.getLocalName() // - org.apache.catalina.connector.Connector.getUseIPVHosts() == false - // - host is chosed directly from javax.servlet.ServletRequest.getServerName() + // - host is chosed directly from jakarta.servlet.ServletRequest.getServerName() // - it defaults to what's set in org.apache.catalina.Engine.setDefaultHost() // - context finding: org.apache.catalina.mapper.Mapper.internalMap() // - org.apache.catalina.mapper.Mapper.MappedHost.contextList is searched @@ -1285,7 +1283,7 @@ public void invoke(Request request, Response response) throws IOException, Servl // 1 = {org.apache.catalina.mapper.Mapper$MappedContext@3458} // name: java.lang.String = "/c1" // - the array (it is sorted) is searched by incoming URI - // - the found context's path is available as javax.servlet.http.HttpServletRequest.getContextPath() + // - the found context's path is available as jakarta.servlet.http.HttpServletRequest.getContextPath() // - servlet finding: inside org.apache.catalina.mapper.Mapper.internalMapWrapper() // - org.apache.catalina.mapper.Mapper.ContextVersion.exactWrappers are searched first // contextVersion.exactWrappers = {org.apache.catalina.mapper.Mapper$MappedWrapper[2]@3722} @@ -1326,7 +1324,7 @@ public void invoke(Request request, Response response) throws IOException, Servl // - org.apache.catalina.core.StandardContextValve.invoke() // - requires existing org.apache.catalina.connector.Request.getWrapper() // - org.apache.catalina.core.StandardWrapperValve.invoke() - // - important org.apache.catalina.core.StandardWrapper.allocate() call that returns a javax.servlet.Servlet + // - important org.apache.catalina.core.StandardWrapper.allocate() call that returns a jakarta.servlet.Servlet // - org.apache.catalina.connector.Request.getFilterChain() is called inside static // org.apache.catalina.core.ApplicationFilterFactory.createFilterChain(), so it'd be better to set // such filter chain earlier. the same static method determines the filters to use and calls @@ -1345,7 +1343,7 @@ public void invoke(Request request, Response response) throws IOException, Servl // just can't send `GET HTTP/1.1` request // response = send(connector.getLocalPort(), ""); response = send(connector.getLocalPort(), "/"); - assertTrue("Special, strange Servlet API 4 mapping rule", response.endsWith("| | | / |")); + assertTrue(response.endsWith("| | | / |"), "Special, strange Servlet API 4 mapping rule"); response = send(connector.getLocalPort(), "/x"); assertTrue(response.endsWith("| | /x | null |")); response = send(connector.getLocalPort(), "/y"); @@ -1363,7 +1361,7 @@ public void invoke(Request request, Response response) throws IOException, Servl response = send(connector.getLocalPort(), "/c1/"); // https://bz.apache.org/bugzilla/show_bug.cgi?id=64109 // assertTrue("Special, strange Servlet API 4 mapping rule", response.endsWith("| | | / |")); - assertTrue("Special, strange Servlet API 4 mapping rule", response.endsWith("| /c1 | | / |")); + assertTrue(response.endsWith("| /c1 | | / |"), "Special, strange Servlet API 4 mapping rule"); response = send(connector.getLocalPort(), "/c1/x"); assertTrue(response.endsWith("| /c1 | /x | null |")); response = send(connector.getLocalPort(), "/c1/y");