From c826a66f7f1422a74d91054b8eb079afa2ee7578 Mon Sep 17 00:00:00 2001 From: Grzegorz Grzybek Date: Fri, 16 Jun 2023 10:02:16 +0200 Subject: [PATCH] [#1802] Switch pax-web-undertow from javax to jakarta --- .../ops4j/pax/web/service/PaxWebConfig.java | 14 +- pax-web-undertow/internals.adoc | 4 +- pax-web-undertow/pom.xml | 92 ++++---- .../model/UndertowSubsystem.java | 2 +- .../internal/ContextAwarePathHandler.java | 6 +- .../undertow/internal/PaxWebFilterInfo.java | 8 +- .../internal/PaxWebOuterHandlerWrapper.java | 6 +- .../internal/PaxWebPreprocessorsHandler.java | 16 +- .../internal/PaxWebSecurityHandler.java | 6 +- .../undertow/internal/PaxWebServletInfo.java | 8 +- .../internal/UndertowServerController.java | 2 +- .../internal/UndertowServerWrapper.java | 40 ++-- .../undertow/internal/web/DefaultServlet.java | 27 +-- .../internal/web/FlexibleDeployment.java | 2 +- .../internal/web/OsgiResourceManager.java | 12 +- .../OsgiServletContainerInitializerInfo.java | 2 +- .../internal/web/UndertowResourceServlet.java | 22 +- .../model/ConfigurationParserTest.java | 17 +- .../internal/EmbeddedUndertowHttp2Test.java | 34 ++- .../internal/EmbeddedUndertowHttps2Test.java | 12 +- .../internal/EmbeddedUndertowTest.java | 81 ++++--- .../service/undertow/internal/PathTest.java | 37 ++-- .../internal/UnifiedUndertowTest.java | 200 +++++++++--------- .../configuration/PredicateParserTest.java | 11 +- 24 files changed, 326 insertions(+), 335 deletions(-) diff --git a/pax-web-api/src/main/java/org/ops4j/pax/web/service/PaxWebConfig.java b/pax-web-api/src/main/java/org/ops4j/pax/web/service/PaxWebConfig.java index 377607d729..a8d99a237e 100644 --- a/pax-web-api/src/main/java/org/ops4j/pax/web/service/PaxWebConfig.java +++ b/pax-web-api/src/main/java/org/ops4j/pax/web/service/PaxWebConfig.java @@ -65,28 +65,28 @@ public interface PaxWebConfig { * This property specifies the port used for servlets and resources accessible via HTTP. * The default value for this property is {@code 80} according to specification, but we'll use {@code 8080}. */ - String PID_CFG_HTTP_PORT = "org.osgi.service.servlet.port"; + String PID_CFG_HTTP_PORT = "org.osgi.service.http.port"; /** * This property specifies the port used for servlets and resources accessible via HTTPS. * The default value for this property is {@code 443} according to specificaton, but we'll use {@code 8443}. */ - String PID_CFG_HTTP_PORT_SECURE = "org.osgi.service.servlet.port.secure"; + String PID_CFG_HTTP_PORT_SECURE = "org.osgi.service.http.port.secure"; /** Should the default non-secure port be enabled? */ - String PID_CFG_HTTP_ENABLED = "org.osgi.service.servlet.enabled"; + String PID_CFG_HTTP_ENABLED = "org.osgi.service.http.enabled"; /** Should the default secure port be enabled? */ - String PID_CFG_HTTP_SECURE_ENABLED = "org.osgi.service.servlet.secure.enabled"; + String PID_CFG_HTTP_SECURE_ENABLED = "org.osgi.service.http.secure.enabled"; /** Comma-separated list of addresses to bind listeners/connectors to. Defaults to {@code 0.0.0.0} */ String PID_CFG_LISTENING_ADDRESSES = "org.ops4j.pax.web.listening.addresses"; /** Name to use as default (non-secure) connector, defaults to {@code default}. */ - String PID_CFG_HTTP_CONNECTOR_NAME = "org.osgi.service.servlet.connector.name"; + String PID_CFG_HTTP_CONNECTOR_NAME = "org.osgi.service.http.connector.name"; /** Name to use as secure connector, defaults to {@code secureDefault}. */ - String PID_CFG_HTTP_SECURE_CONNECTOR_NAME = "org.osgi.service.servlet.secure.connector.name"; + String PID_CFG_HTTP_SECURE_CONNECTOR_NAME = "org.osgi.service.http.secure.connector.name"; /** * Jetty: {@code org.eclipse.jetty.server.AbstractConnector#setIdleTimeout(long)} @@ -119,7 +119,7 @@ public interface PaxWebConfig { /** * Jetty: adds {@code org.eclipse.jetty.server.ForwardedRequestCustomizer} to {@code HttpConfiguration} */ - String PID_CFG_HTTP_CHECK_FORWARDED_HEADERS = "org.osgi.service.servlet.checkForwardedHeaders"; + String PID_CFG_HTTP_CHECK_FORWARDED_HEADERS = "org.osgi.service.http.checkForwardedHeaders"; /** * Comma-separated list of virtual hosts to set on every deployed context if the context itself diff --git a/pax-web-undertow/internals.adoc b/pax-web-undertow/internals.adoc index e2f58696e3..041a2a5a58 100644 --- a/pax-web-undertow/internals.adoc +++ b/pax-web-undertow/internals.adoc @@ -57,7 +57,7 @@ QueuedNioTcpServer@10249 = "TCP server (NIO) " <2> This is default handler invoked when nothing is matched using <4> <3> PathHandler will be drilled down later <4> These 4 welcome pages are defaults from `io.undertow.server.handlers.resource.ResourceHandler.welcomeFiles` -<5> Standard javax.servlet context mapping +<5> Standard jakarta.servlet context mapping Here's how `io.undertow.Undertow` (Wildfly's version is `org.wildfly.extension.undertow.Server`) instance can be found (there's one instance of this class): @@ -149,7 +149,7 @@ next: {io.undertow.server.handlers.PathHandler@10199} <2> Path matching within single web application <3> Servlets of web application <4> The actual instance of one of the the servlets -<5> Resource manager for calls to e.g., `javax.servlet.ServletContext.getResource()` +<5> Resource manager for calls to e.g., `jakarta.servlet.ServletContext.getResource()` Here's what really is invoked by `io.undertow.servlet.handlers.ServletDispatchingHandler`: diff --git a/pax-web-undertow/pom.xml b/pax-web-undertow/pom.xml index 3cb80a5740..671aebb1cc 100644 --- a/pax-web-undertow/pom.xml +++ b/pax-web-undertow/pom.xml @@ -43,61 +43,61 @@ org.ops4j.pax.web.service.undertow.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}", - org.slf4j;version="[1.7,2)", + org.slf4j;version="[2,3)", org.jboss.logging;version="[3.4,4)", org.xnio;version="[3.8,4)", org.xnio.channels;version="[3.8,4)", - io.undertow;version="[2.2,3)", - io.undertow.connector;version="[2.2,3)", - io.undertow.io;version="[2.2,3)", - io.undertow.predicate;version="[2.2,3)", - io.undertow.protocols.ssl;version="[2.2,3)", - io.undertow.security.api;version="[2.2,3)", - io.undertow.security.idm;version="[2.2,3)", - io.undertow.server;version="[2.2,3)", - io.undertow.server.handlers;version="[2.2,3)", - io.undertow.server.handlers.accesslog;version="[2.2,3)", - io.undertow.server.handlers.builder;version="[2.2,3)", - io.undertow.server.handlers.cache;version="[2.2,3)", - io.undertow.server.handlers.encoding;version="[2.2,3)", - io.undertow.server.handlers.resource;version="[2.2,3)", - io.undertow.server.protocol.http;version="[2.2,3)", - io.undertow.server.protocol.http2;version="[2.2,3)", - io.undertow.server.session;version="[2.2,3)", - io.undertow.servlet;version="[2.2,3)", - io.undertow.servlet.api;version="[2.2,3)", - io.undertow.servlet.core;version="[2.2,3)", - io.undertow.servlet.handlers;version="[2.2,3)", - io.undertow.servlet.spec;version="[2.2,3)", - io.undertow.servlet.util;version="[2.2,3)", - io.undertow.util;version="[2.2,3)", + io.undertow;version="[2.3,3)", + io.undertow.connector;version="[2.3,3)", + io.undertow.io;version="[2.3,3)", + io.undertow.predicate;version="[2.3,3)", + io.undertow.protocols.ssl;version="[2.3,3)", + io.undertow.security.api;version="[2.3,3)", + io.undertow.security.idm;version="[2.3,3)", + io.undertow.server;version="[2.3,3)", + io.undertow.server.handlers;version="[2.3,3)", + io.undertow.server.handlers.accesslog;version="[2.3,3)", + io.undertow.server.handlers.builder;version="[2.3,3)", + io.undertow.server.handlers.cache;version="[2.3,3)", + io.undertow.server.handlers.encoding;version="[2.3,3)", + io.undertow.server.handlers.resource;version="[2.3,3)", + io.undertow.server.protocol.http;version="[2.3,3)", + io.undertow.server.protocol.http2;version="[2.3,3)", + io.undertow.server.session;version="[2.3,3)", + io.undertow.servlet;version="[2.3,3)", + io.undertow.servlet.api;version="[2.3,3)", + io.undertow.servlet.core;version="[2.3,3)", + io.undertow.servlet.handlers;version="[2.3,3)", + io.undertow.servlet.spec;version="[2.3,3)", + io.undertow.servlet.util;version="[2.3,3)", + io.undertow.util;version="[2.3,3)", - javax.annotation;version="[1.2,2)";resolution:=optional, + jakarta.annotation;version="[2,3)";resolution:=optional, javax.net.ssl, javax.security.auth, javax.security.auth.callback, @@ -163,11 +163,11 @@ org.osgi - osgi.cmpn + org.osgi.service.servlet provided - + jakarta.annotation @@ -225,9 +225,14 @@ jul-to-slf4j provided + + org.assertj + assertj-core + test + org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl test @@ -258,8 +263,13 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine test diff --git a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/configuration/model/UndertowSubsystem.java b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/configuration/model/UndertowSubsystem.java index 1c23e655f0..fa4f40c997 100644 --- a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/configuration/model/UndertowSubsystem.java +++ b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/configuration/model/UndertowSubsystem.java @@ -410,7 +410,7 @@ public static CustomFilter create(Map attributes, Locator locator @Override public HttpHandler configure(HttpHandler handler, Predicate predicate) { - // TODO: use javax.servlet filters or just generic io.undertow.server.HttpHandler? + // TODO: use jakarta.servlet filters or just generic io.undertow.server.HttpHandler? return handler; } diff --git a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/ContextAwarePathHandler.java b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/ContextAwarePathHandler.java index 65a7c1e183..2a304d8533 100644 --- a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/ContextAwarePathHandler.java +++ b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/ContextAwarePathHandler.java @@ -16,7 +16,7 @@ package org.ops4j.pax.web.service.undertow.internal; import java.util.Dictionary; -import javax.servlet.Servlet; +import jakarta.servlet.Servlet; import io.undertow.Handlers; import io.undertow.server.HttpHandler; @@ -25,13 +25,13 @@ import io.undertow.server.handlers.ResponseCodeHandler; import io.undertow.server.handlers.cache.LRUCache; import org.ops4j.pax.web.annotations.Review; -import org.osgi.service.http.HttpContext; +import org.ops4j.pax.web.service.http.HttpContext; /** *

A {@link PathHandler} that can (try to) resolve conflicts when registering multiple contexts under * the same path.

*

The problem is that when using {@code etc/undertow.xml} with {@code } handlers and - * when using normal WARs and {@link org.osgi.service.http.HttpService#registerServlet(String, Servlet, Dictionary, HttpContext)} we may + * when using normal WARs and {@link org.ops4j.pax.web.service.http.HttpService#registerServlet(String, Servlet, Dictionary, HttpContext)} we may * end up with multiple {@link io.undertow.server.HttpHandler handlers} handling {@code "/"} path. We should always prefer * the path from {@code etc/undertow.xml} configuration - assuming it's configured and user know what (s)he's * doing.

diff --git a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/PaxWebFilterInfo.java b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/PaxWebFilterInfo.java index c1abbecc6a..0551b443a5 100644 --- a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/PaxWebFilterInfo.java +++ b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/PaxWebFilterInfo.java @@ -16,8 +16,8 @@ package org.ops4j.pax.web.service.undertow.internal; import java.util.Map; -import javax.servlet.Filter; -import javax.servlet.ServletContext; +import jakarta.servlet.Filter; +import jakarta.servlet.ServletContext; import io.undertow.servlet.api.FilterInfo; import io.undertow.servlet.api.InstanceFactory; @@ -31,7 +31,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; /** * Special {@link FilterInfo} that can be configured from {@link FilterModel}. @@ -40,7 +40,7 @@ public class PaxWebFilterInfo extends FilterInfo { private final FilterModel filterModel; - /** 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; private ServiceReference serviceReference; diff --git a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/PaxWebOuterHandlerWrapper.java b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/PaxWebOuterHandlerWrapper.java index 73e8084242..128c0ee38d 100644 --- a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/PaxWebOuterHandlerWrapper.java +++ b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/PaxWebOuterHandlerWrapper.java @@ -15,8 +15,8 @@ */ package org.ops4j.pax.web.service.undertow.internal; -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.ServletContext; +import jakarta.servlet.http.HttpServletRequest; import io.undertow.server.HandlerWrapper; import io.undertow.server.HttpHandler; @@ -32,7 +32,7 @@ import org.ops4j.pax.web.service.spi.servlet.OsgiSessionAttributeListener; /** - * This {@link HandlerWrapper} ensures that {@link org.osgi.service.http.whiteboard.Preprocessor preprocessors}, + * This {@link HandlerWrapper} ensures that {@link org.osgi.service.servlet.whiteboard.Preprocessor preprocessors}, * filters and target servlet use proper request wrapper that returns proper {@link ServletContext}. */ public class PaxWebOuterHandlerWrapper implements HandlerWrapper { diff --git a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/PaxWebPreprocessorsHandler.java b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/PaxWebPreprocessorsHandler.java index dd906da631..d63c3f3a7e 100644 --- a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/PaxWebPreprocessorsHandler.java +++ b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/PaxWebPreprocessorsHandler.java @@ -19,12 +19,12 @@ import java.util.LinkedList; import java.util.List; import java.util.stream.Collectors; -import javax.servlet.FilterChain; -import javax.servlet.ServletContext; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import io.undertow.server.HandlerWrapper; import io.undertow.server.HttpHandler; @@ -32,10 +32,10 @@ import io.undertow.servlet.handlers.ServletRequestContext; import org.ops4j.pax.web.service.spi.servlet.OsgiFilterChain; import org.ops4j.pax.web.service.spi.servlet.PreprocessorFilterConfig; -import org.osgi.service.http.whiteboard.Preprocessor; +import org.osgi.service.servlet.whiteboard.Preprocessor; /** - * This {@link HandlerWrapper} ensures that {@link org.osgi.service.http.whiteboard.Preprocessor preprocessors}, + * This {@link HandlerWrapper} ensures that {@link org.osgi.service.servlet.whiteboard.Preprocessor preprocessors}, * filters and target servlet use proper request wrapper that returns proper {@link ServletContext}. */ public class PaxWebPreprocessorsHandler implements HandlerWrapper { diff --git a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/PaxWebSecurityHandler.java b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/PaxWebSecurityHandler.java index c1592b8441..3aeb68682e 100644 --- a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/PaxWebSecurityHandler.java +++ b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/PaxWebSecurityHandler.java @@ -15,9 +15,9 @@ */ package org.ops4j.pax.web.service.undertow.internal; -import javax.servlet.Servlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.Servlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import io.undertow.server.HandlerWrapper; import io.undertow.server.HttpHandler; diff --git a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/PaxWebServletInfo.java b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/PaxWebServletInfo.java index 651ff7493e..7c259133ea 100644 --- a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/PaxWebServletInfo.java +++ b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/PaxWebServletInfo.java @@ -15,8 +15,8 @@ */ package org.ops4j.pax.web.service.undertow.internal; -import javax.servlet.Servlet; -import javax.servlet.ServletContext; +import jakarta.servlet.Servlet; +import jakarta.servlet.ServletContext; import io.undertow.servlet.api.InstanceFactory; import io.undertow.servlet.api.InstanceHandle; @@ -33,7 +33,7 @@ import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceObjects; -import org.osgi.service.http.runtime.dto.DTOConstants; +import org.osgi.service.servlet.runtime.dto.DTOConstants; import java.util.ArrayList; import java.util.List; @@ -52,7 +52,7 @@ public class PaxWebServletInfo extends ServletInfo { private Class servletClass; - /** 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; diff --git a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/UndertowServerController.java b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/UndertowServerController.java index ba8fac7e9c..2992ee680b 100644 --- a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/UndertowServerController.java +++ b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/UndertowServerController.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 io.undertow.security.idm.IdentityManager; import org.ops4j.pax.web.service.spi.ServerController; diff --git a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/UndertowServerWrapper.java b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/UndertowServerWrapper.java index a0dd4725b3..282a653ac0 100644 --- a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/UndertowServerWrapper.java +++ b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/UndertowServerWrapper.java @@ -46,16 +46,16 @@ import java.util.TreeSet; import java.util.UUID; import java.util.function.Supplier; -import javax.servlet.DispatcherType; -import javax.servlet.Servlet; -import javax.servlet.ServletContext; -import javax.servlet.ServletContextAttributeListener; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; -import javax.servlet.ServletException; -import javax.servlet.SessionCookieConfig; -import javax.servlet.annotation.ServletSecurity; -import javax.servlet.http.HttpSessionAttributeListener; +import jakarta.servlet.DispatcherType; +import jakarta.servlet.Servlet; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextAttributeListener; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.ServletException; +import jakarta.servlet.SessionCookieConfig; +import jakarta.servlet.annotation.ServletSecurity; +import jakarta.servlet.http.HttpSessionAttributeListener; import javax.xml.XMLConstants; import javax.xml.parsers.SAXParserFactory; @@ -182,7 +182,7 @@ import org.osgi.framework.Bundle; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.wiring.BundleWiring; -import org.osgi.service.http.whiteboard.Preprocessor; +import org.osgi.service.servlet.whiteboard.Preprocessor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xml.sax.InputSource; @@ -304,8 +304,8 @@ class UndertowServerWrapper implements BatchVisitor, UndertowSupport { private final Map preprocessorsHandlers = new HashMap<>(); /** - * Handlers that call {@link org.osgi.service.http.HttpContext#handleSecurity} and/or - * {@link org.osgi.service.http.context.ServletContextHelper#handleSecurity}. + * Handlers that call {@link org.ops4j.pax.web.service.http.HttpContext#handleSecurity} and/or + * {@link org.osgi.service.servlet.context.ServletContextHelper#handleSecurity}. */ private final Map securityHandlers = new HashMap<>(); @@ -318,14 +318,14 @@ class UndertowServerWrapper implements BatchVisitor, UndertowSupport { private final Map deploymentInfos = 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<>(); /** * 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). */ @@ -1561,7 +1561,7 @@ public void visitServletModelChange(ServletModelChange change) { info.setRunAs(model.getRunAs()); // when only adding new servlet, we can simply alter existing deployment - // because this is possible (as required by methods like javax.servlet.ServletContext.addServlet()) + // because this is possible (as required by methods like jakarta.servlet.ServletContext.addServlet()) // we can't go the easy way when _removing_ servlets deploymentInfo.addServlet(info); if (deployment != null) { @@ -2337,7 +2337,7 @@ public void visitContainerInitializerModelChange(ContainerInitializerModelChange if (initializers != null) { // just remove the ServletContainerInitializerInfo without _cleaning_ it, because it was // _cleaned_ just after io.undertow.servlet.core.DeploymentManagerImpl.deploy() called - // javax.servlet.ServletContainerInitializer.onStartup() + // jakarta.servlet.ServletContainerInitializer.onStartup() initializers.removeIf(i -> i.getModel() == model); } }); @@ -2615,7 +2615,7 @@ private void ensureServletContextStarted(final String contextPath) { deployment.addServletExtension(new ContextLinkingServletExtension(contextPath, highestRankedContext, highestRankedDynamicContext)); // 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() if (highestRankedContext.getClassLoader() != null) { deployment.setClassLoader(highestRankedContext.getClassLoader()); } @@ -2890,7 +2890,7 @@ public String rewriteUrl(String originalUrl, String sessionId) { manager = servletContainer.addDeployment(deployment); - // here's where Undertow-specific instance of javax.servlet.ServletContext is created + // here's where Undertow-specific instance of jakarta.servlet.ServletContext is created manager.deploy(); HttpHandler handler = manager.start(); diff --git a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/web/DefaultServlet.java b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/web/DefaultServlet.java index e54e7467a1..986bb9b7c8 100644 --- a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/web/DefaultServlet.java +++ b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/web/DefaultServlet.java @@ -21,21 +21,19 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.Map; import java.util.Set; -import javax.servlet.DispatcherType; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.DispatcherType; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import io.undertow.io.IoCallback; import io.undertow.io.Sender; @@ -485,16 +483,7 @@ private boolean isAllowed(String path, DispatcherType dispatcherType) { } protected static ServletRequestContext requireCurrentServletRequestContext() { - if (System.getSecurityManager() == null) { - return ServletRequestContext.requireCurrent(); - } else { - return AccessController.doPrivileged(new PrivilegedAction() { - @Override - public ServletRequestContext run() { - return ServletRequestContext.requireCurrent(); - } - }); - } + return ServletRequestContext.requireCurrent(); } } diff --git a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/web/FlexibleDeployment.java b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/web/FlexibleDeployment.java index 349277d6dd..c9cbc3afb0 100644 --- a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/web/FlexibleDeployment.java +++ b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/web/FlexibleDeployment.java @@ -21,7 +21,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.Executor; -import javax.servlet.ServletContext; +import jakarta.servlet.ServletContext; import io.undertow.security.api.AuthenticationMechanism; import io.undertow.server.HttpHandler; diff --git a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/web/OsgiResourceManager.java b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/web/OsgiResourceManager.java index b260704856..2d96b492dd 100644 --- a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/web/OsgiResourceManager.java +++ b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/web/OsgiResourceManager.java @@ -23,7 +23,7 @@ import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; -import javax.servlet.ServletContext; +import jakarta.servlet.ServletContext; import io.undertow.server.handlers.resource.PathResource; import io.undertow.server.handlers.resource.PathResourceManager; @@ -31,7 +31,7 @@ import io.undertow.server.handlers.resource.ResourceChangeListener; import io.undertow.server.handlers.resource.ResourceManager; import io.undertow.server.handlers.resource.URLResource; -import org.osgi.service.http.HttpContext; +import org.ops4j.pax.web.service.http.HttpContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,14 +40,14 @@ public class OsgiResourceManager implements ResourceManager { public static final Logger LOG = LoggerFactory.getLogger(OsgiResourceManager.class); /** - * The {@link javax.servlet.ServletContext} which (according to OSGi CMPN web specifications) should delegate - * to {@link org.osgi.service.http.HttpContext} / {@link org.osgi.service.http.context.ServletContextHelper}. + * The {@link jakarta.servlet.ServletContext} which (according to OSGi CMPN web specifications) should delegate + * to {@link org.ops4j.pax.web.service.http.HttpContext} / {@link org.osgi.service.servlet.context.ServletContextHelper}. */ private final ServletContext osgiScopedServletContext; /** - * 2nd parameter of {@link org.osgi.service.http.HttpService#registerResources(String, String, HttpContext)} - * or {@link org.osgi.service.http.whiteboard.HttpWhiteboardConstants#HTTP_WHITEBOARD_RESOURCE_PREFIX} + * 2nd parameter of {@link org.ops4j.pax.web.service.http.HttpService#registerResources(String, String, HttpContext)} + * or {@link org.osgi.service.servlet.whiteboard.HttpWhiteboardConstants#HTTP_WHITEBOARD_RESOURCE_PREFIX} */ private final String chroot; diff --git a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/web/OsgiServletContainerInitializerInfo.java b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/web/OsgiServletContainerInitializerInfo.java index 88d5829491..af3a3d15fe 100644 --- a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/web/OsgiServletContainerInitializerInfo.java +++ b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/web/OsgiServletContainerInitializerInfo.java @@ -15,7 +15,7 @@ */ package org.ops4j.pax.web.service.undertow.internal.web; -import javax.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContainerInitializer; import io.undertow.servlet.api.InstanceFactory; import io.undertow.servlet.api.InstanceHandle; diff --git a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/web/UndertowResourceServlet.java b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/web/UndertowResourceServlet.java index 6e714c3557..e233547609 100644 --- a/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/web/UndertowResourceServlet.java +++ b/pax-web-undertow/src/main/java/org/ops4j/pax/web/service/undertow/internal/web/UndertowResourceServlet.java @@ -19,13 +19,13 @@ import java.io.IOException; import java.nio.file.Paths; import java.util.Enumeration; -import javax.servlet.DispatcherType; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletConfig; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.DispatcherType; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import io.undertow.server.HttpServerExchange; import io.undertow.server.handlers.cache.DirectBufferCache; @@ -46,7 +46,7 @@ * *

Due to caching infrastructure of Undertow, we need this servlet to implement {@link ResourceManager}, because * {@link io.undertow.server.handlers.resource.CachingResourceManager} should be created up front. The details - * of {@link ResourceManager} will be set up in {@link javax.servlet.Servlet#init(ServletConfig)}.

+ * of {@link ResourceManager} will be set up in {@link jakarta.servlet.Servlet#init(ServletConfig)}.

* *

This servlet extends forked version of oroginal {@link io.undertow.servlet.handlers.DefaultServlet} and * is implemented as if the original version was more extensible. After forking I could implement everything @@ -64,11 +64,11 @@ public class UndertowResourceServlet extends DefaultServlet implements ResourceM /** * 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; - /** The real {@link ResourceManager} configured in {@link javax.servlet.Servlet#init(ServletConfig)} */ + /** The real {@link ResourceManager} configured in {@link jakarta.servlet.Servlet#init(ServletConfig)} */ private ResourceManager resourceManager; private String[] welcomeFiles; @@ -338,7 +338,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // https://github.com/ops4j/org.ops4j.pax.web/issues/1664 // - // instead of relying on reflection used in javax.servlet.http.HttpServlet.doOptions() + // instead of relying on reflection used in jakarta.servlet.http.HttpServlet.doOptions() // we simply return fixed set of methods (to be compatible with Jetty and Tomcat) resp.setHeader("Allow", "OPTIONS, GET, HEAD, POST"); } diff --git a/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/configuration/model/ConfigurationParserTest.java b/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/configuration/model/ConfigurationParserTest.java index c6d3aa034f..2270ff3c3b 100644 --- a/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/configuration/model/ConfigurationParserTest.java +++ b/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/configuration/model/ConfigurationParserTest.java @@ -19,7 +19,7 @@ import java.util.Map; import javax.xml.parsers.SAXParserFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.ops4j.pax.web.service.PaxWebConfig; import org.ops4j.pax.web.service.undertow.internal.configuration.ResolvingContentHandler; import org.ops4j.pax.web.service.undertow.internal.configuration.UnmarshallingContentHandler; @@ -28,8 +28,7 @@ import org.xml.sax.InputSource; import org.xml.sax.XMLReader; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.MatcherAssert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class ConfigurationParserTest { @@ -59,13 +58,13 @@ public void model() throws Exception { cfg.init(); LOG.info("Configuration: {}", cfg); - assertThat(cfg.getSocketBindings().get(0).getPort(), equalTo(8123)); - assertThat(cfg.getSocketBindings().get(0).getName(), equalTo("http")); - assertThat(cfg.getSocketBindings().get(1).getPort(), equalTo(8423)); - assertThat(cfg.getSocketBindings().get(1).getName(), equalTo("https")); + assertThat(cfg.getSocketBindings().get(0).getPort()).isEqualTo(8123); + assertThat(cfg.getSocketBindings().get(0).getName()).isEqualTo("http"); + assertThat(cfg.getSocketBindings().get(1).getPort()).isEqualTo(8423); + assertThat(cfg.getSocketBindings().get(1).getName()).isEqualTo("https"); - assertThat(cfg.getSecurityRealms().get(1).getIdentities().getSsl().getKeystore().getPath(), - equalTo("/data/tmp/certs/server.keystore")); + assertThat(cfg.getSecurityRealms().get(1).getIdentities().getSsl().getKeystore().getPath()) + .isEqualTo("/data/tmp/certs/server.keystore"); } } diff --git a/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/EmbeddedUndertowHttp2Test.java b/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/EmbeddedUndertowHttp2Test.java index 4fc9813e52..2ed8f8687a 100644 --- a/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/EmbeddedUndertowHttp2Test.java +++ b/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/EmbeddedUndertowHttp2Test.java @@ -34,10 +34,10 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.PushBuilder; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.PushBuilder; import io.undertow.Handlers; import io.undertow.Undertow; @@ -56,14 +56,12 @@ import io.undertow.servlet.util.ImmediateInstanceFactory; import io.undertow.util.HeaderMap; import io.undertow.util.Headers; -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 EmbeddedUndertowHttp2Test { @@ -75,7 +73,7 @@ public class EmbeddedUndertowHttp2Test { private HpackDecoder decoder; private Map responses; - @Before + @BeforeEach public void resetState() { decoder = new HpackDecoder(); responses = new HashMap<>(); @@ -392,7 +390,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 Switching Protocols\r\n")); + assertThat(fullResponse).startsWith("HTTP/1.1 101 Switching Protocols\r\n"); buffer.position(rnrn + 4); boolean remains = true; while (remains) { @@ -449,9 +447,9 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO server.stop(); // 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 @@ -660,9 +658,9 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO server.stop(); // 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 { @@ -743,7 +741,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-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/EmbeddedUndertowHttps2Test.java b/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/EmbeddedUndertowHttps2Test.java index d8db569891..5dc88a9677 100644 --- a/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/EmbeddedUndertowHttps2Test.java +++ b/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/EmbeddedUndertowHttps2Test.java @@ -29,10 +29,10 @@ import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManagerFactory; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.PushBuilder; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.PushBuilder; import io.undertow.Handlers; import io.undertow.Undertow; @@ -74,13 +74,13 @@ import org.apache.hc.core5.http2.HttpVersionPolicy; import org.apache.hc.core5.http2.config.H2Config; import org.apache.hc.core5.io.CloseMode; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xnio.Options; import org.xnio.Sequence; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; public class EmbeddedUndertowHttps2Test { diff --git a/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/EmbeddedUndertowTest.java b/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/EmbeddedUndertowTest.java index a209b168fe..e58468fa12 100644 --- a/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/EmbeddedUndertowTest.java +++ b/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/EmbeddedUndertowTest.java @@ -29,19 +29,19 @@ import java.util.List; import java.util.Map; import java.util.Set; -import javax.servlet.DispatcherType; -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.ServletConfig; -import javax.servlet.ServletContainerInitializer; -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; -import javax.servlet.ServletException; -import javax.servlet.http.HttpFilter; -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.ServletConfig; +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpFilter; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import io.undertow.Handlers; import io.undertow.Undertow; @@ -70,7 +70,7 @@ import io.undertow.servlet.util.ImmediateInstanceFactory; import io.undertow.util.ETag; import io.undertow.util.StatusCodes; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xnio.ChannelListener; @@ -83,10 +83,9 @@ import org.xnio.XnioWorker; import org.xnio.channels.AcceptingChannel; -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 EmbeddedUndertowTest { @@ -102,7 +101,7 @@ public void undertowWithSingleContextAndServlet() throws Exception { HttpServlet servletInstance = new HttpServlet() { @Override - protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException { LOG.info("Handling request: {}", req.toString()); resp.setContentType("text/plain"); resp.setCharacterEncoding("UTF-8"); @@ -113,7 +112,7 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws } }; - ServletInfo servlet = Servlets.servlet("s1", servletInstance.getClass(), new ImmediateInstanceFactory(servletInstance)); + ServletInfo servlet = Servlets.servlet("s1", servletInstance.getClass(), new ImmediateInstanceFactory<>(servletInstance)); servlet.addMapping("/s1/*"); DeploymentInfo deploymentInfo = Servlets.deployment() @@ -160,7 +159,7 @@ public void embeddedServerWithUndertowResourceServlet() throws Exception { HttpServlet servletInstance = new DefaultServlet(); - ServletInfo servlet = Servlets.servlet("default", servletInstance.getClass(), new ImmediateInstanceFactory(servletInstance)); + ServletInfo servlet = Servlets.servlet("default", servletInstance.getClass(), new ImmediateInstanceFactory<>(servletInstance)); servlet.addInitParam("directory-listing", "true"); // with "/" mapping, io.undertow.servlet.handlers.ServletPathMatch is used with @@ -231,7 +230,7 @@ public void dynamicListeners() throws Exception { HttpServlet servletInstance = new HttpServlet() { @Override - protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException { LOG.info("Handling request: {}", req.toString()); resp.setContentType("text/plain"); resp.setCharacterEncoding("UTF-8"); @@ -251,7 +250,7 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws } }; - ServletInfo servlet = Servlets.servlet("default", servletInstance.getClass(), new ImmediateInstanceFactory(servletInstance)); + ServletInfo servlet = Servlets.servlet("default", servletInstance.getClass(), new ImmediateInstanceFactory<>(servletInstance)); servlet.addMapping("/s1"); DeploymentInfo deploymentInfo = Servlets.deployment() @@ -282,7 +281,7 @@ public void contextInitialized(ServletContextEvent sce) { .addServletContainerInitializer(new ServletContainerInitializerInfo(ServletContainerInitializer.class, new ImmediateInstanceFactory(new ServletContainerInitializer() { @Override - public void onStartup(Set> c, ServletContext ctx) throws ServletException { + public void onStartup(Set> c, ServletContext ctx) { // ServletContextListener added from SCI - this is real "programmatic listener" ctx.addListener(new ServletContextListener() { @Override @@ -354,7 +353,7 @@ public void undertowWithRequestWrappers() throws Exception { HttpServlet servletInstance = new HttpServlet() { @Override - protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException { LOG.info("Handling request: {}", req.toString()); resp.setContentType("text/plain"); resp.setCharacterEncoding("UTF-8"); @@ -372,7 +371,7 @@ protected void doFilter(HttpServletRequest req, HttpServletResponse res, FilterC } }; - ServletInfo servlet = Servlets.servlet("s1", servletInstance.getClass(), new ImmediateInstanceFactory(servletInstance)); + ServletInfo servlet = Servlets.servlet("s1", servletInstance.getClass(), new ImmediateInstanceFactory<>(servletInstance)); servlet.addMapping("/s1/*"); FilterInfo filter = Servlets.filter("f1", filterInstance.getClass(), new ImmediateInstanceFactory<>(filterInstance)); @@ -434,7 +433,7 @@ protected void doFilter(HttpServletRequest req, HttpServletResponse res, FilterC // "XNIO-1 task-1@2434" prio=5 tid=0x17 nid=NA runnable // java.lang.Thread.State: RUNNABLE // at org.ops4j.pax.web.service.undertow.internal.EmbeddedUndertowTest$2.service(EmbeddedUndertowTest.java:139) - // at javax.servlet.http.HttpServlet.service(HttpServlet.java:590) + // at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:590) // at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74) // at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) // at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68) @@ -559,7 +558,7 @@ public void undertowUsingLowLevelBuilders() throws Exception { HttpServlet servletInstance = new HttpServlet() { @Override - protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException { LOG.info("Handling request: {}", req.toString()); resp.setContentType("text/plain"); resp.setCharacterEncoding("UTF-8"); @@ -570,7 +569,7 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws } }; - ServletInfo servlet = Servlets.servlet("s1", servletInstance.getClass(), new ImmediateInstanceFactory(servletInstance)); + ServletInfo servlet = Servlets.servlet("s1", servletInstance.getClass(), new ImmediateInstanceFactory<>(servletInstance)); servlet.addMapping("/s1/*"); DeploymentInfo deploymentInfo = Servlets.deployment() @@ -606,7 +605,7 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws response = send(port, "/c1/s2"); assertTrue(response.contains("HTTP/1.1 404")); - ServletInfo servlet2 = Servlets.servlet("s2", servletInstance.getClass(), new ImmediateInstanceFactory(servletInstance)); + ServletInfo servlet2 = Servlets.servlet("s2", servletInstance.getClass(), new ImmediateInstanceFactory<>(servletInstance)); servlet2.addMapping("/s2/*"); // this is not necessary. Not even reasonable, because the deployment info is originally cloned inside // the deployment @@ -963,7 +962,7 @@ public void init(ServletConfig config) throws ServletException { } @Override - protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException { LOG.info("Handling request: {}", req.toString()); resp.setContentType("text/plain"); resp.setCharacterEncoding("UTF-8"); @@ -983,11 +982,11 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws // another example of "info" like class. "servlet info" is added to "deployment info" (directly, not as clone) // which means "servlet is registered inside servlet context" - ServletInfo servlet = Servlets.servlet("c1s1", servletInstance.getClass(), new ImmediateInstanceFactory(servletInstance)); + ServletInfo servlet = Servlets.servlet("c1s1", servletInstance.getClass(), new ImmediateInstanceFactory<>(servletInstance)); servlet.addMapping("/s1/*"); // "deployment info" represents a full information about single "servlet context" which can simply be - // treated as "JavaEE web application" with single context path + // treated as "JakartaEE web application" with single context path // this info is in 1:1 relation with single web.xml descriptor DeploymentInfo deploymentInfo1 = Servlets.deployment() .setClassLoader(this.getClass().getClassLoader()) @@ -1011,7 +1010,7 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws // - returned as io.undertow.servlet.api.DeploymentManager object that controls the lifecycle of // associated "physical deployment" DeploymentManager dm1 = container.addDeployment(deploymentInfo1); - assertThat(dm1.getState(), equalTo(DeploymentManager.State.UNDEPLOYED)); + assertThat(dm1.getState()).isEqualTo(DeploymentManager.State.UNDEPLOYED); // "deploying" clones the already cloned "deployment info" again and turns it into "physical deployment" // represented by io.undertow.servlet.api.Deployment, which allows read access to various aspects @@ -1019,7 +1018,7 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws // the problem with Undertow is that while we can add new servlets to existing "deployment", we can't // remove them... // "deploy" does few important things: - // - creates instance of io.undertow.servlet.spec.ServletContextImpl (THE javax.servlet.ServletContext) + // - creates instance of io.undertow.servlet.spec.ServletContextImpl (THE jakarta.servlet.ServletContext) // - creates instance of io.undertow.servlet.core.DeploymentImpl // - prepares all the "web elements" by turning "info" into "physical representation" of e.g., servlet // - e.g., io.undertow.servlet.api.ServletInfo is turned into io.undertow.servlet.core.ManagedServlet @@ -1032,11 +1031,11 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws // - the final handler is put as io.undertow.servlet.core.DeploymentImpl.initialHandler and then // returned from (as-is) io.undertow.servlet.api.DeploymentManager.start() dm1.deploy(); - assertThat(dm1.getState(), equalTo(DeploymentManager.State.DEPLOYED)); + assertThat(dm1.getState()).isEqualTo(DeploymentManager.State.DEPLOYED); // "start" starts all lifecycle objects (servlets, filters, listeners) HttpHandler handler = dm1.start(); - assertThat(dm1.getState(), equalTo(DeploymentManager.State.STARTED)); + assertThat(dm1.getState()).isEqualTo(DeploymentManager.State.STARTED); path.addPrefixPath("/c1", handler); @@ -1056,7 +1055,7 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws // add new context - ServletInfo servlet2 = Servlets.servlet("c2s1", servletInstance.getClass(), new ImmediateInstanceFactory(servletInstance)); + ServletInfo servlet2 = Servlets.servlet("c2s1", servletInstance.getClass(), new ImmediateInstanceFactory<>(servletInstance)); servlet2.addMapping("/s1/*"); DeploymentInfo deploymentInfo2 = Servlets.deployment() @@ -1076,7 +1075,7 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws // add new servlet to existing context - ServletInfo servlet3 = Servlets.servlet("c1s2", servletInstance.getClass(), new ImmediateInstanceFactory(servletInstance)); + ServletInfo servlet3 = Servlets.servlet("c1s2", servletInstance.getClass(), new ImmediateInstanceFactory<>(servletInstance)); servlet3.addMapping("/s2/*"); response = send(port, "/c1/s2"); @@ -1122,7 +1121,7 @@ private String send(int port, String request, String... headers) throws IOExcept s.getOutputStream().write(("Connection: close\r\n\r\n").getBytes()); byte[] buf = new byte[64]; - int read = -1; + int read; StringWriter sw = new StringWriter(); while ((read = s.getInputStream().read(buf)) > 0) { sw.append(new String(buf, 0, read)); @@ -1135,7 +1134,7 @@ private String send(int port, String request, String... headers) throws IOExcept private Map extractHeaders(String response) throws IOException { Map headers = new LinkedHashMap<>(); try (BufferedReader reader = new BufferedReader(new StringReader(response))) { - String line = null; + String line; while ((line = reader.readLine()) != null) { if (line.trim().equals("")) { break; diff --git a/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/PathTest.java b/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/PathTest.java index 037ea1c9b5..3a45324d21 100644 --- a/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/PathTest.java +++ b/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/PathTest.java @@ -15,32 +15,31 @@ */ package org.ops4j.pax.web.service.undertow.internal; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static io.undertow.util.CanonicalPathUtils.canonicalize; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.MatcherAssert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class PathTest { @Test public void securePaths() { - assertThat(canonicalize(""), equalTo("")); - assertThat(canonicalize("/"), equalTo("/")); - assertThat(canonicalize("c:"), equalTo("c:")); - assertThat(canonicalize("c:/"), equalTo("c:/")); - assertThat(canonicalize("c:\\"), equalTo("c:\\")); - assertThat(canonicalize("//"), equalTo("/")); // Jetty: "//" - assertThat(canonicalize("."), equalTo(".")); // Jetty: "" - assertThat(canonicalize(".."), equalTo("..")); // Jetty: null, meaning we go out of chroot - assertThat(canonicalize("../.."), equalTo("..")); // Jetty: null, meaning we go out of chroot - assertThat(canonicalize("./././././././."), equalTo(".")); // Jetty: "" - assertThat(canonicalize("../../../../../etc/passwd"), equalTo("../etc/passwd")); // Jetty: null, meaning we go out of chroot - assertThat(canonicalize("path1"), equalTo("path1")); - assertThat(canonicalize("./path1"), equalTo("./path1")); // Jetty: "path1" - assertThat(canonicalize("../path1"), equalTo("../path1")); // Jetty: null, meaning we go out of chroot - assertThat(canonicalize("path1/path2"), equalTo("path1/path2")); - assertThat(canonicalize("path1/../path2"), equalTo("path1/path2")); // Jetty: "path2" + assertThat(canonicalize("")).isEqualTo(""); + assertThat(canonicalize("/")).isEqualTo("/"); + assertThat(canonicalize("c:")).isEqualTo("c:"); + assertThat(canonicalize("c:/")).isEqualTo("c:/"); + assertThat(canonicalize("c:\\")).isEqualTo("c:\\"); + assertThat(canonicalize("//")).isEqualTo("/"); // Jetty: "//" + assertThat(canonicalize(".")).isEqualTo("."); // Jetty: "" + assertThat(canonicalize("..")).isEqualTo(".."); // Jetty: null, meaning we go out of chroot + assertThat(canonicalize("../..")).isEqualTo(".."); // Jetty: null, meaning we go out of chroot + assertThat(canonicalize("./././././././.")).isEqualTo("."); // Jetty: "" + assertThat(canonicalize("../../../../../etc/passwd")).isEqualTo("../etc/passwd"); // Jetty: null, meaning we go out of chroot + assertThat(canonicalize("path1")).isEqualTo("path1"); + assertThat(canonicalize("./path1")).isEqualTo("./path1"); // Jetty: "path1" + assertThat(canonicalize("../path1")).isEqualTo("../path1"); // Jetty: null, meaning we go out of chroot + assertThat(canonicalize("path1/path2")).isEqualTo("path1/path2"); + assertThat(canonicalize("path1/../path2")).isEqualTo("path1/path2"); // Jetty: "path2" } } diff --git a/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/UnifiedUndertowTest.java b/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/UnifiedUndertowTest.java index 6f6203ba06..7f258dcac7 100644 --- a/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/UnifiedUndertowTest.java +++ b/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/UnifiedUndertowTest.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 io.undertow.Handlers; import io.undertow.Undertow; @@ -48,16 +48,14 @@ import io.undertow.servlet.util.ImmediateInstanceFactory; 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.undertow.internal.web.UndertowResourceServlet; 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-tomcat @@ -227,11 +225,11 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se int port = ((InetSocketAddress) server.getListenerInfo().get(0).getAddress()).getPort(); 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(); } @@ -290,20 +288,20 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se int port = ((InetSocketAddress) server.getListenerInfo().get(0).getAddress()).getPort(); 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(); } @@ -373,25 +371,25 @@ 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"); // because Undertow canonicalizes the path without returning "bad request" - assertThat(response, endsWith("'hello.txt'")); + assertThat(response).endsWith("'hello.txt'"); // here's where problems started. Jetty's default servlet itself handles welcome files, while in // 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(); } @@ -478,18 +476,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") + "\""); } }; ServletInfo indexxServletInfo = Servlets.servlet("indexx", indexxServlet.getClass(), new ImmediateInstanceFactory(indexxServlet)); @@ -551,15 +549,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: @@ -569,20 +567,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")); @@ -608,26 +606,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 @@ -795,18 +793,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") + "\""); } }; ServletInfo indexxServletInfo = Servlets.servlet("indexx", indexxServlet.getClass(), new ImmediateInstanceFactory(indexxServlet)); @@ -868,15 +866,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: @@ -886,20 +884,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")); @@ -925,26 +923,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 @@ -1137,7 +1135,7 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws // and calls io.undertow.servlet.handlers.ServletChain.handler.handleRequest() // - the above handler calls init() if needed (for the first time) and passes to // io.undertow.servlet.handlers.ServletHandler.handleRequest() - // - javax.servlet.Servlet.service() is called + // - jakarta.servlet.Servlet.service() is called String response; @@ -1149,7 +1147,7 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws // just can't send `GET HTTP/1.1` request // response = send(port, ""); response = send(port, "/"); - assertTrue("Special, strange Servlet API 4 mapping rule", response.endsWith("| | / | null |")); + assertTrue(response.endsWith("| | / | null |"), "Special, strange Servlet API 4 mapping rule"); response = send(port, "/x"); assertTrue(response.endsWith("| | /x | null |")); response = send(port, "/y"); @@ -1166,7 +1164,7 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws assertTrue(response.contains("HTTP/1.1 404")); response = send(port, "/c1/"); // https://bz.apache.org/bugzilla/show_bug.cgi?id=64109 - assertTrue("Special, strange Servlet API 4 mapping rule", response.endsWith("| /c1 | / | null |")); + assertTrue(response.endsWith("| /c1 | / | null |"), "Special, strange Servlet API 4 mapping rule"); response = send(port, "/c1/x"); assertTrue(response.endsWith("| /c1 | /x | null |")); response = send(port, "/c1/y"); diff --git a/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/configuration/PredicateParserTest.java b/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/configuration/PredicateParserTest.java index bb341279e0..c320d8e4f6 100644 --- a/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/configuration/PredicateParserTest.java +++ b/pax-web-undertow/src/test/java/org/ops4j/pax/web/service/undertow/internal/configuration/PredicateParserTest.java @@ -21,11 +21,10 @@ import io.undertow.server.HandlerWrapper; import io.undertow.server.handlers.IPAddressAccessControlHandler; import io.undertow.server.handlers.builder.HandlerParser; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class PredicateParserTest { @@ -33,14 +32,14 @@ public class PredicateParserTest { public void parseExpression() { HandlerWrapper wrapper = HandlerParser.parse("ip-access-control(default-allow=false, acl={'127.0.0.1 allow', '127.0.0.2 allow'})", this.getClass().getClassLoader()); assertNotNull(wrapper); - assertThat(wrapper.wrap(null).getClass(), equalTo(IPAddressAccessControlHandler.class)); + assertThat(wrapper.wrap(null).getClass()).isEqualTo(IPAddressAccessControlHandler.class); } @Test public void parsePredicate() { Predicate predicate = Predicates.parse("path-prefix('/cxf')", this.getClass().getClassLoader()); assertNotNull(predicate); - assertThat(predicate.getClass(), equalTo(PathPrefixPredicate.class)); + assertThat(predicate.getClass()).isEqualTo(PathPrefixPredicate.class); } }