From 1b26a2f8ea394d696a6780ff0fa92b2613019dff Mon Sep 17 00:00:00 2001 From: Grzegorz Grzybek Date: Mon, 26 Jun 2023 09:26:46 +0200 Subject: [PATCH] [#1802] Adjust code to Jetty 12 SNAPSHOT (20230626) --- .../jetty/internal/JettyServerWrapper.java | 8 +-- .../internal/PaxWebServletContextHandler.java | 5 +- .../internal/PaxWebSessionIdManager.java | 5 +- .../jetty/internal/web/DefaultServlet.java | 58 +++++++------------ .../internal/EmbeddedJettyHttp2Test.java | 5 +- .../jetty/internal/EmbeddedJettyTest.java | 27 ++++----- .../internal/EmbeddedJettyWebSocketsTest.java | 4 +- .../jetty/internal/UnifiedJettyTest.java | 32 +++++----- .../src/test/resources/etc/jetty-webapp.xml | 2 +- 9 files changed, 64 insertions(+), 82 deletions(-) diff --git a/pax-web-jetty/src/main/java/org/ops4j/pax/web/service/jetty/internal/JettyServerWrapper.java b/pax-web-jetty/src/main/java/org/ops4j/pax/web/service/jetty/internal/JettyServerWrapper.java index 41dfb66244..114539bb7d 100644 --- a/pax-web-jetty/src/main/java/org/ops4j/pax/web/service/jetty/internal/JettyServerWrapper.java +++ b/pax-web-jetty/src/main/java/org/ops4j/pax/web/service/jetty/internal/JettyServerWrapper.java @@ -24,8 +24,6 @@ import jakarta.servlet.SessionCookieConfig; import jakarta.servlet.annotation.ServletSecurity; import jakarta.servlet.http.HttpSessionAttributeListener; -import org.eclipse.jetty.ee.security.ConstraintAware; -import org.eclipse.jetty.ee.security.ConstraintMapping; import org.eclipse.jetty.ee10.servlet.ErrorPageErrorHandler; import org.eclipse.jetty.ee10.servlet.FilterHolder; import org.eclipse.jetty.ee10.servlet.FilterMapping; @@ -34,6 +32,8 @@ import org.eclipse.jetty.ee10.servlet.ServletHolder; import org.eclipse.jetty.ee10.servlet.ServletMapping; import org.eclipse.jetty.ee10.servlet.SessionHandler; +import org.eclipse.jetty.ee10.servlet.security.ConstraintAware; +import org.eclipse.jetty.ee10.servlet.security.ConstraintMapping; import org.eclipse.jetty.ee10.servlet.security.ConstraintSecurityHandler; import org.eclipse.jetty.http.HttpCookie; import org.eclipse.jetty.http.PreEncodedHttpField; @@ -754,11 +754,11 @@ public void visitServletContextModelChange(ServletContextModelChange change) { LOG.info("Creating new Jetty context for {}", model); - PaxWebServletContextHandler sch = new PaxWebServletContextHandler(null, contextPath, configuration); + PaxWebServletContextHandler sch = new PaxWebServletContextHandler(contextPath, configuration); // special, OSGi-aware org.eclipse.jetty.servlet.ServletHandler sch.setServletHandler(new PaxWebServletHandler(default404Servlet, new OsgiSessionAttributeListener(sessionListenerModels))); // setting "false" here will trigger 302 redirect when browsing to context without trailing "/" - sch.setAllowNullPathInfo(false); + sch.setAllowNullPathInContext(false); // welcome files will be handled at default/resource servlet level and OsgiServletContext sch.setWelcomeFiles(new String[0]); diff --git a/pax-web-jetty/src/main/java/org/ops4j/pax/web/service/jetty/internal/PaxWebServletContextHandler.java b/pax-web-jetty/src/main/java/org/ops4j/pax/web/service/jetty/internal/PaxWebServletContextHandler.java index d1aaef782c..33c431580e 100644 --- a/pax-web-jetty/src/main/java/org/ops4j/pax/web/service/jetty/internal/PaxWebServletContextHandler.java +++ b/pax-web-jetty/src/main/java/org/ops4j/pax/web/service/jetty/internal/PaxWebServletContextHandler.java @@ -106,12 +106,11 @@ public class PaxWebServletContextHandler extends ServletContextHandler { * {@code org.eclipse.jetty.webapp.WebAppContext} which does all the sort of XML/annotation configuration, but * we take some of the mechanisms from {@code WebAppContext} if they're useful in Pax Web. * - * @param parent * @param contextPath * @param configuration */ - public PaxWebServletContextHandler(Handler.Container parent, String contextPath, Configuration configuration) { - super(parent, contextPath, true, true); + public PaxWebServletContextHandler(String contextPath, Configuration configuration) { + super(contextPath, true, true); // TCCL of sessionManager timer threads will be set to thread of pax-web-jetty bundle, not to current TCCL ScheduledExecutorScheduler executorScheduler = new ScheduledExecutorScheduler(getSessionHandler().toString() + "Timer", true, diff --git a/pax-web-jetty/src/main/java/org/ops4j/pax/web/service/jetty/internal/PaxWebSessionIdManager.java b/pax-web-jetty/src/main/java/org/ops4j/pax/web/service/jetty/internal/PaxWebSessionIdManager.java index 306267e6c3..e0a034e729 100644 --- a/pax-web-jetty/src/main/java/org/ops4j/pax/web/service/jetty/internal/PaxWebSessionIdManager.java +++ b/pax-web-jetty/src/main/java/org/ops4j/pax/web/service/jetty/internal/PaxWebSessionIdManager.java @@ -16,6 +16,8 @@ package org.ops4j.pax.web.service.jetty.internal; import org.eclipse.jetty.ee10.servlet.ServletContextRequest; +import org.eclipse.jetty.ee10.servlet.ServletHandler; +import org.eclipse.jetty.http.pathmap.MatchedResource; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.session.DefaultSessionIdManager; @@ -34,7 +36,8 @@ public PaxWebSessionIdManager(Server server) { public static String getSessionIdSuffix(Request r) { ServletContextRequest req = Request.as(r, ServletContextRequest.class); - if (req.getMappedServlet() != null && req.getMappedServlet().getServletHolder() instanceof PaxWebServletHolder holder) { + MatchedResource match = req.getMatchedResource(); + if (match != null && match.getResource() != null && match.getResource().getServletHolder() instanceof PaxWebServletHolder holder) { OsgiContextModel ocm = holder.getOsgiContextModel(); // we can't replace '/' to '_' because of how // org.eclipse.jetty.server.session.FileSessionDataStore.initializeStore() analyzes the diff --git a/pax-web-jetty/src/main/java/org/ops4j/pax/web/service/jetty/internal/web/DefaultServlet.java b/pax-web-jetty/src/main/java/org/ops4j/pax/web/service/jetty/internal/web/DefaultServlet.java index de226aa7cc..52c8167ee7 100644 --- a/pax-web-jetty/src/main/java/org/ops4j/pax/web/service/jetty/internal/web/DefaultServlet.java +++ b/pax-web-jetty/src/main/java/org/ops4j/pax/web/service/jetty/internal/web/DefaultServlet.java @@ -13,7 +13,6 @@ package org.ops4j.pax.web.service.jetty.internal.web; -//CHECKSTYLE:OFF import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; @@ -33,8 +32,6 @@ import java.util.Set; import java.util.StringTokenizer; import java.util.concurrent.CompletableFuture; -import java.util.function.Function; -import java.util.function.Predicate; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -48,7 +45,6 @@ import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponseWrapper; import org.eclipse.jetty.ee10.servlet.ServletApiRequest; -import org.eclipse.jetty.ee10.servlet.ServletApiResponse; import org.eclipse.jetty.ee10.servlet.ServletContextHandler; import org.eclipse.jetty.ee10.servlet.ServletContextRequest; import org.eclipse.jetty.ee10.servlet.ServletContextResponse; @@ -71,13 +67,17 @@ import org.eclipse.jetty.io.ByteBufferInputStream; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.server.Context; -import org.eclipse.jetty.server.HttpStream; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.ResourceService; import org.eclipse.jetty.server.Response; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.ContextHandler; -import org.eclipse.jetty.util.*; +import org.eclipse.jetty.util.Blocker; +import org.eclipse.jetty.util.BufferUtil; +import org.eclipse.jetty.util.Callback; +import org.eclipse.jetty.util.IO; +import org.eclipse.jetty.util.StringUtil; +import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.ResourceFactory; import org.eclipse.jetty.util.resource.Resources; @@ -227,7 +227,7 @@ public void init() throws ServletException } } - // for welcome file handling we need some _baseResource + // Pax Web: for welcome file handling we need some _baseResource _baseResource = configureBaseResource(); List precompressedFormats = parsePrecompressedFormats(getInitParameter("precompressed"), @@ -477,7 +477,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se else if (isPathInfoOnly()) encodedPathInContext = URIUtil.encodePath(req.getPathInfo()); else if (req instanceof ServletApiRequest apiRequest) - encodedPathInContext = Context.getPathInContext(req.getContextPath(), apiRequest.getServletContextRequest().getHttpURI().getCanonicalPath()); + encodedPathInContext = Context.getPathInContext(req.getContextPath(), apiRequest.getRequest().getHttpURI().getCanonicalPath()); else encodedPathInContext = Context.getPathInContext(req.getContextPath(), URIUtil.canonicalPath(req.getRequestURI())); @@ -649,17 +649,6 @@ public boolean isSecure() return _servletRequest.isSecure(); } - @Override - public boolean addErrorListener(Predicate onError) - { - return false; - } - - @Override - public void addHttpStreamWrapper(Function wrapper) - { - } - @Override public Object removeAttribute(String name) { @@ -908,12 +897,7 @@ public HttpFields.Mutable getHeaders() public ServletContextResponse getServletContextResponse() { - if (_response instanceof ServletApiResponse) - { - ServletApiResponse apiResponse = (ServletApiResponse)_response; - return apiResponse.getResponse(); - } - return null; + return ServletContextResponse.getServletContextResponse(_response); } @Override @@ -1033,6 +1017,12 @@ public CompletableFuture writeInterim(int status, HttpFields headers) { return null; } + + @Override + public String toString() + { + return "%s@%x{%s,%s}".formatted(this.getClass().getSimpleName(), hashCode(), this._coreRequest, _response); + } } private class ServletResourceService extends ResourceService implements ResourceService.WelcomeFactory @@ -1045,23 +1035,14 @@ private ServletResourceService(ServletContextHandler servletContextHandler) } @Override - public String getWelcomeTarget(Request coreRequest) + public String getWelcomeTarget(HttpContent content, Request coreRequest) { String[] welcomes = _servletContextHandler.getWelcomeFiles(); if (welcomes == null) return null; - - HttpServletRequest request = getServletRequest(coreRequest); String pathInContext = Request.getPathInContext(coreRequest); - String includedServletPath = (String)request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH); - String requestTarget; - if (includedServletPath != null) - requestTarget = getIncludedPathInContext(request, includedServletPath, isPathInfoOnly()); - else - requestTarget = isPathInfoOnly() ? request.getPathInfo() : pathInContext; - String welcomeTarget = null; - Resource base = _baseResource.resolve(requestTarget); + Resource base = content.getResource(); if (Resources.isReadableDirectory(base)) { for (String welcome : welcomes) @@ -1070,13 +1051,16 @@ public String getWelcomeTarget(Request coreRequest) // If the welcome resource is a file, it has // precedence over resources served by Servlets. - Resource welcomePath = base.resolve(welcome); + Resource welcomePath = content.getResource().resolve(welcome); if (Resources.isReadableFile(welcomePath)) return welcomeInContext; // Check whether a Servlet may serve the welcome resource. if (_welcomeServletMode != WelcomeServletMode.NONE && welcomeTarget == null) { + if (isPathInfoOnly() && !isIncluded(getServletRequest(coreRequest))) + welcomeTarget = URIUtil.addPaths(getServletRequest(coreRequest).getPathInfo(), welcome); + ServletHandler.MappedServlet entry = _servletContextHandler.getServletHandler().getMappedServlet(welcomeInContext); // Is there a different Servlet that may serve the welcome resource? if (entry != null && entry.getServletHolder().getServletInstance() != DefaultServlet.this) diff --git a/pax-web-jetty/src/test/java/org/ops4j/pax/web/service/jetty/internal/EmbeddedJettyHttp2Test.java b/pax-web-jetty/src/test/java/org/ops4j/pax/web/service/jetty/internal/EmbeddedJettyHttp2Test.java index cd8c49f655..4f14010d92 100644 --- a/pax-web-jetty/src/test/java/org/ops4j/pax/web/service/jetty/internal/EmbeddedJettyHttp2Test.java +++ b/pax-web-jetty/src/test/java/org/ops4j/pax/web/service/jetty/internal/EmbeddedJettyHttp2Test.java @@ -82,7 +82,8 @@ public class EmbeddedJettyHttp2Test { @BeforeEach public void resetState() { - decoder = new HpackDecoder(4096, 8192); + decoder = new HpackDecoder(8192); + decoder.setMaxTableCapacity(4096); responses = new HashMap<>(); } @@ -253,7 +254,6 @@ public void http2NioExchange() throws Exception { final CountDownLatch latch = new CountDownLatch(3); ServletContextHandler handler = new ServletContextHandler("/"); - handler.setAllowNullPathInfo(true); handler.setAllowNullPathInContext(true); handler.addServlet(new ServletHolder("default-servlet", new HttpServlet() { @Override @@ -468,7 +468,6 @@ public void http2NioExchangeWithDirectUpgrade() throws Exception { final CountDownLatch latch = new CountDownLatch(3); ServletContextHandler handler = new ServletContextHandler("/"); - handler.setAllowNullPathInfo(true); handler.setAllowNullPathInContext(true); handler.addServlet(new ServletHolder("default-servlet", new HttpServlet() { @Override diff --git a/pax-web-jetty/src/test/java/org/ops4j/pax/web/service/jetty/internal/EmbeddedJettyTest.java b/pax-web-jetty/src/test/java/org/ops4j/pax/web/service/jetty/internal/EmbeddedJettyTest.java index 47a858f0cd..ebaf81f0f6 100644 --- a/pax-web-jetty/src/test/java/org/ops4j/pax/web/service/jetty/internal/EmbeddedJettyTest.java +++ b/pax-web-jetty/src/test/java/org/ops4j/pax/web/service/jetty/internal/EmbeddedJettyTest.java @@ -302,8 +302,7 @@ public void embeddedServerWithServletContextHandler() throws Exception { // servlet context handler extends ContextHandler for easier ContextHandler with _handler = ServletHandler // created ServletContextHandler will already have session, security handlers (depending on options) and // ServletHandler and we can add servlets/filters through ServletContextHandler - ServletContextHandler handler1 = new ServletContextHandler(null, "/c1", ServletContextHandler.NO_SESSIONS); - handler1.setAllowNullPathInfo(true); // for ServletContextHandler + ServletContextHandler handler1 = new ServletContextHandler("/c1", ServletContextHandler.NO_SESSIONS); handler1.setAllowNullPathInContext(true); // for ContextHandler // this single method adds both ServletHolder and ServletMapping // calling org.eclipse.jetty.servlet.ServletHandler.addServletWithMapping() @@ -317,8 +316,7 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws } }), "/"); - ServletContextHandler handler2 = new ServletContextHandler(null, "/c2", ServletContextHandler.NO_SESSIONS); - handler2.setAllowNullPathInfo(true); + ServletContextHandler handler2 = new ServletContextHandler("/c2", ServletContextHandler.NO_SESSIONS); handler2.setAllowNullPathInContext(true); handler2.addServlet(new ServletHolder("default-servlet", new HttpServlet() { @Override @@ -388,7 +386,7 @@ public void embeddedServerWithServletContextHandlerAnd404Servlet() throws Except ContextHandlerCollection chc = new ContextHandlerCollection(); - ServletContextHandler h = new ServletContextHandler(null, "/c1", ServletContextHandler.NO_SESSIONS); + ServletContextHandler h = new ServletContextHandler("/c1", ServletContextHandler.NO_SESSIONS); h.setAllowNullPathInContext(false); h.addServlet(new ServletHolder("default-servlet", new ServletHandler.Default404Servlet()), "/*"); @@ -430,8 +428,7 @@ public void embeddedServerWithServletContextHandlerAndDynamicInitializers() thro ContextHandlerCollection chc = new ContextHandlerCollection(); - ServletContextHandler handler1 = new ServletContextHandler(null, "/c1", ServletContextHandler.NO_SESSIONS); - handler1.setAllowNullPathInfo(true); + ServletContextHandler handler1 = new ServletContextHandler("/c1", ServletContextHandler.NO_SESSIONS); handler1.setAllowNullPathInContext(true); // SCI that adds a ServletContextListener which tries to add ServletContextListener @@ -521,8 +518,8 @@ public void embeddedServerWithJettyResourceServlet() throws Exception { server.setConnectors(new Connector[] { connector }); ContextHandlerCollection chc = new ContextHandlerCollection(); - ServletContextHandler handler1 = new ServletContextHandler(null, "/", ServletContextHandler.NO_SESSIONS); - handler1.setAllowNullPathInfo(true); + ServletContextHandler handler1 = new ServletContextHandler("/", ServletContextHandler.NO_SESSIONS); + handler1.setAllowNullPathInContext(true); ServletHolder sh1 = new ServletHolder("default", new DefaultServlet()); sh1.setInitParameter("dirAllowed", "false"); @@ -564,12 +561,11 @@ public void embeddedServerWithServletContextHandlerAndOnlyFilter() throws Except ContextHandlerCollection chc = new ContextHandlerCollection(); - ServletContextHandler handler1 = new ServletContextHandler(null, "/c1", ServletContextHandler.NO_SESSIONS); + ServletContextHandler handler1 = new ServletContextHandler("/c1", ServletContextHandler.NO_SESSIONS); // without "default 404 servlet", jetty won't invoke a "pipeline" that has only a filter. handler1.getServletHandler().setEnsureDefaultServlet(true); - handler1.setAllowNullPathInfo(true); handler1.setAllowNullPathInContext(true); handler1.addFilter(new FilterHolder(new Filter() { @Override @@ -619,7 +615,7 @@ public void embeddedServerWithServletContextHandlerAddedAfterServerHasStarted() ContextHandlerCollection chc = new ContextHandlerCollection(); - ServletContextHandler handler1 = new ServletContextHandler(chc, "/c1", ServletContextHandler.NO_SESSIONS); + ServletContextHandler handler1 = new ServletContextHandler("/c1", ServletContextHandler.NO_SESSIONS); handler1.addServlet(new ServletHolder("s1", new HttpServlet() { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException { @@ -630,6 +626,7 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws } }), "/s1"); + chc.addHandler(handler1); server.setHandler(chc); server.start(); @@ -648,8 +645,8 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws // add new context - ServletContextHandler handler2 = new ServletContextHandler(chc, "/c2", ServletContextHandler.NO_SESSIONS); - handler2.setAllowNullPathInfo(true); + ServletContextHandler handler2 = new ServletContextHandler("/c2", ServletContextHandler.NO_SESSIONS); + handler2.setAllowNullPathInContext(true); handler2.addServlet(new ServletHolder("s1", new HttpServlet() { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException { @@ -659,6 +656,7 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws resp.getWriter().close(); } }), "/s1"); + chc.addHandler(handler2); handler2.start(); // add new servlet to existing context @@ -702,7 +700,6 @@ public void embeddedServerWithWebAppContext() throws Exception { wac1.setContextPath("/app1"); // by default, null path info is not allowed and redirect (with added "/") is sent when requesting just // the context URL - wac1.setAllowNullPathInfo(false); wac1.setAllowNullPathInContext(false); // when we don't pass handler collection (or handler wrapper) in constructor, we have to add this // specialized context handler manually diff --git a/pax-web-jetty/src/test/java/org/ops4j/pax/web/service/jetty/internal/EmbeddedJettyWebSocketsTest.java b/pax-web-jetty/src/test/java/org/ops4j/pax/web/service/jetty/internal/EmbeddedJettyWebSocketsTest.java index ed632d5982..3298a34030 100644 --- a/pax-web-jetty/src/test/java/org/ops4j/pax/web/service/jetty/internal/EmbeddedJettyWebSocketsTest.java +++ b/pax-web-jetty/src/test/java/org/ops4j/pax/web/service/jetty/internal/EmbeddedJettyWebSocketsTest.java @@ -66,8 +66,8 @@ public void webSockets() throws Exception { ContextHandlerCollection chc = new ContextHandlerCollection(); - ServletContextHandler sch = new ServletContextHandler(null, "/", ServletContextHandler.NO_SESSIONS); - sch.setAllowNullPathInfo(true); + ServletContextHandler sch = new ServletContextHandler("/", ServletContextHandler.NO_SESSIONS); + sch.setAllowNullPathInContext(true); sch.addServlet(DefaultServlet.class, "/"); chc.addHandler(sch); diff --git a/pax-web-jetty/src/test/java/org/ops4j/pax/web/service/jetty/internal/UnifiedJettyTest.java b/pax-web-jetty/src/test/java/org/ops4j/pax/web/service/jetty/internal/UnifiedJettyTest.java index 5bbbbb459c..d1dd0e5df8 100644 --- a/pax-web-jetty/src/test/java/org/ops4j/pax/web/service/jetty/internal/UnifiedJettyTest.java +++ b/pax-web-jetty/src/test/java/org/ops4j/pax/web/service/jetty/internal/UnifiedJettyTest.java @@ -70,8 +70,7 @@ public void twoResourceServletsWithDifferentBases() throws Exception { server.setConnectors(new Connector[] { connector }); ContextHandlerCollection chc = new ContextHandlerCollection(); - ServletContextHandler handler1 = new ServletContextHandler(null, "/", ServletContextHandler.NO_SESSIONS); - handler1.setAllowNullPathInfo(true); + ServletContextHandler handler1 = new ServletContextHandler("/", ServletContextHandler.NO_SESSIONS); handler1.setAllowNullPathInContext(true); // in Jetty, DefaultServlet implements org.eclipse.jetty.util.resource.ResourceFactory used by the @@ -174,8 +173,8 @@ public void standardWelcomePages() throws Exception { server.setConnectors(new Connector[] { connector }); ContextHandlerCollection chc = new ContextHandlerCollection(); - ServletContextHandler handler1 = new ServletContextHandler(null, "/", ServletContextHandler.NO_SESSIONS); - handler1.setAllowNullPathInfo(true); + ServletContextHandler handler1 = new ServletContextHandler("/", ServletContextHandler.NO_SESSIONS); + handler1.setAllowNullPathInContext(true); // a bug when "false"? When mapped to "/" it doesn't matter, but fails // when mapped to "/x" resources would have to be under /x.... // handler1.setInitParameter(DefaultServlet.CONTEXT_INIT + "pathInfoOnly", "true"); @@ -231,8 +230,8 @@ public void standardWelcomePagesWithDifferentContext() throws Exception { server.setConnectors(new Connector[] { connector }); ContextHandlerCollection chc = new ContextHandlerCollection(); - ServletContextHandler handler1 = new ServletContextHandler(null, "/c", ServletContextHandler.NO_SESSIONS); - handler1.setAllowNullPathInfo(false); + ServletContextHandler handler1 = new ServletContextHandler("/c", ServletContextHandler.NO_SESSIONS); + handler1.setAllowNullPathInContext(false); // a bug when "false"? When mapped to "/" it doesn't matter, but fails // when mapped to "/x" resources would have to be under /x.... // handler1.setInitParameter(DefaultServlet.CONTEXT_INIT + "pathInfoOnly", "true"); @@ -297,8 +296,7 @@ public void resourceServletWithWelcomePages() throws Exception { server.setConnectors(new Connector[] { connector }); ContextHandlerCollection chc = new ContextHandlerCollection(); - ServletContextHandler handler1 = new ServletContextHandler(null, "/", ServletContextHandler.NO_SESSIONS); - handler1.setAllowNullPathInfo(true); + ServletContextHandler handler1 = new ServletContextHandler("/", ServletContextHandler.NO_SESSIONS); handler1.setAllowNullPathInContext(true); handler1.setWelcomeFiles(new String[] { "index.txt" }); @@ -367,8 +365,8 @@ public void paxWebWelcomePages() throws Exception { server.setConnectors(new Connector[] { connector }); ContextHandlerCollection chc = new ContextHandlerCollection(); - ServletContextHandler handler = new ServletContextHandler(null, "/", ServletContextHandler.NO_SESSIONS); - handler.setAllowNullPathInfo(true); + ServletContextHandler handler = new ServletContextHandler("/", ServletContextHandler.NO_SESSIONS); + handler.setAllowNullPathInContext(true); File b1 = new File("target/b1"); FileUtils.deleteDirectory(b1); @@ -693,8 +691,7 @@ public void paxWebWelcomePagesWithDifferentContext() throws Exception { server.setConnectors(new Connector[] { connector }); ContextHandlerCollection chc = new ContextHandlerCollection(); - ServletContextHandler handler = new ServletContextHandler(null, "/c", ServletContextHandler.NO_SESSIONS); - handler.setAllowNullPathInfo(false); + ServletContextHandler handler = new ServletContextHandler("/c", ServletContextHandler.NO_SESSIONS); handler.setAllowNullPathInContext(false); handler.setWelcomeFiles(new String[] { "index.y", "index.x" }); @@ -1020,8 +1017,8 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws } }; - ServletContextHandler rootHandler = new ServletContextHandler(chc, "/", ServletContextHandler.NO_SESSIONS); - rootHandler.setAllowNullPathInfo(true); + ServletContextHandler rootHandler = new ServletContextHandler("/", ServletContextHandler.NO_SESSIONS); + rootHandler.setAllowNullPathInContext(true); rootHandler.getServletHandler().addServlet(new ServletHolder("default-servlet", servlet)); map(rootHandler, "default-servlet", new String[] { "/p/*", @@ -1031,8 +1028,8 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws "/x" }); - ServletContextHandler otherHandler = new ServletContextHandler(chc, "/c1", ServletContextHandler.NO_SESSIONS); - otherHandler.setAllowNullPathInfo(true); + ServletContextHandler otherHandler = new ServletContextHandler("/c1", ServletContextHandler.NO_SESSIONS); + otherHandler.setAllowNullPathInContext(false); otherHandler.getServletHandler().addServlet(new ServletHolder("default-servlet", servlet)); map(otherHandler, "default-servlet", new String[] { "/p/*", @@ -1042,6 +1039,9 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws "/x" }); + chc.addHandler(rootHandler); + chc.addHandler(otherHandler); + server.setHandler(chc); server.start(); diff --git a/pax-web-jetty/src/test/resources/etc/jetty-webapp.xml b/pax-web-jetty/src/test/resources/etc/jetty-webapp.xml index 5985d1ee1c..1bc67acf1a 100644 --- a/pax-web-jetty/src/test/resources/etc/jetty-webapp.xml +++ b/pax-web-jetty/src/test/resources/etc/jetty-webapp.xml @@ -22,7 +22,7 @@ /app1 - false + false org.eclipse.jetty.ee10.webapp.WebXmlConfiguration