#9946 Stop passing Handler in constructor as a parent (#9948)

#9946 Stop passing Handler in constructor as a parent

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
Ludovic Orban 2023-06-23 14:44:12 +02:00 committed by GitHub
parent 840fd34525
commit 8f4a15c7da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
59 changed files with 263 additions and 259 deletions

View File

@ -78,7 +78,7 @@ public class SessionDocs
//tag:schsession[]
Server server = new Server();
ServletContextHandler context = new ServletContextHandler(server, "/foo", ServletContextHandler.SESSIONS);
ServletContextHandler context = new ServletContextHandler("/foo", ServletContextHandler.SESSIONS);
SessionHandler sessions = context.getSessionHandler();
//make idle sessions valid for only 5mins
sessions.setMaxInactiveInterval(300);

View File

@ -63,7 +63,7 @@ public class WebSocketServerDocs
Server server = new Server(8080);
// Create a ServletContextHandler with the given context path.
ServletContextHandler handler = new ServletContextHandler(server, "/ctx");
ServletContextHandler handler = new ServletContextHandler("/ctx");
server.setHandler(handler);
// Ensure that JavaxWebSocketServletContainerInitializer is initialized,
@ -82,7 +82,7 @@ public class WebSocketServerDocs
Server server = new Server(8080);
// Create a ServletContextHandler with the given context path.
ServletContextHandler handler = new ServletContextHandler(server, "/ctx");
ServletContextHandler handler = new ServletContextHandler("/ctx");
server.setHandler(handler);
// Ensure that JavaxWebSocketServletContainerInitializer is initialized,
@ -137,7 +137,7 @@ public class WebSocketServerDocs
Server server = new Server(8080);
// Create a ServletContextHandler with the given context path.
ServletContextHandler handler = new ServletContextHandler(server, "/ctx");
ServletContextHandler handler = new ServletContextHandler("/ctx");
server.setHandler(handler);
// Setup the ServerContainer and the WebSocket endpoints for this web application context.
@ -169,7 +169,7 @@ public class WebSocketServerDocs
Server server = new Server(8080);
// Create a ServletContextHandler with the given context path.
ServletContextHandler handler = new ServletContextHandler(server, "/ctx");
ServletContextHandler handler = new ServletContextHandler("/ctx");
server.setHandler(handler);
// Ensure that JettyWebSocketServletContainerInitializer is initialized,
@ -188,7 +188,7 @@ public class WebSocketServerDocs
Server server = new Server(8080);
// Create a ServletContextHandler with the given context path.
ServletContextHandler handler = new ServletContextHandler(server, "/ctx");
ServletContextHandler handler = new ServletContextHandler("/ctx");
server.setHandler(handler);
// Ensure that JettyWebSocketServletContainerInitializer is initialized,
@ -234,7 +234,7 @@ public class WebSocketServerDocs
Server server = new Server(8080);
// Create a ServletContextHandler with the given context path.
ServletContextHandler handler = new ServletContextHandler(server, "/ctx");
ServletContextHandler handler = new ServletContextHandler("/ctx");
server.setHandler(handler);
// Setup the JettyWebSocketServerContainer and the WebSocket endpoints for this web application context.
@ -301,7 +301,7 @@ public class WebSocketServerDocs
Server server = new Server(8080);
// Create a ServletContextHandler with the given context path.
ServletContextHandler handler = new ServletContextHandler(server, "/ctx");
ServletContextHandler handler = new ServletContextHandler("/ctx");
server.setHandler(handler);
// Setup the JettyWebSocketServerContainer to initialize WebSocket components.
@ -357,7 +357,8 @@ public class WebSocketServerDocs
Server server = new Server(8080);
// tag::uriTemplatePathSpec[]
ServletContextHandler handler = new ServletContextHandler(server, "/ctx");
ServletContextHandler handler = new ServletContextHandler("/ctx");
server.setHandler(handler);
// Configure the JettyWebSocketServerContainer.
JettyWebSocketServletContainerInitializer.configure(handler, (servletContext, container) ->

View File

@ -216,21 +216,6 @@ public interface Handler extends LifeCycle, Destroyable, Request.Handler
}
return null;
}
/**
* <p>Make a {@link Container} the parent of a {@link Handler}</p>
* @param parent The {@link Container} that will be the parent
* @param handler The {@link Handler} that will be the child
*/
static void setAsParent(Container parent, Handler handler)
{
if (parent instanceof Collection collection)
collection.addHandler(handler);
else if (parent instanceof Singleton wrapper)
wrapper.setHandler(handler);
else if (parent != null)
throw new IllegalArgumentException("Unknown parent type: " + parent);
}
}
/**

View File

@ -180,14 +180,6 @@ public class ContextHandler extends Handler.Wrapper implements Attributes, Alias
_classLoader = classLoader;
}
@Deprecated
public ContextHandler(Handler.Container parent, String contextPath)
{
this(contextPath);
Container.setAsParent(parent, this);
}
@Override
public void setServer(Server server)
{

View File

@ -18,7 +18,6 @@ import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.http.PreEncodedHttpField;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.util.Callback;
@ -42,13 +41,6 @@ public class MovedContextHandler extends ContextHandler
setAllowNullPathInContext(true);
}
public MovedContextHandler(Handler.Container parent, String contextPath, String redirectURI)
{
Handler.Container.setAsParent(parent, this);
setContextPath(contextPath);
setRedirectURI(redirectURI);
}
/**
* @return the redirect status code, by default 303
*/

View File

@ -44,6 +44,7 @@ import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.endsWith;
@ -92,7 +93,7 @@ public class StopTest
}
catch (Exception e)
{
e.printStackTrace();
throw new RuntimeException(e);
}
});
stopper.start();
@ -107,10 +108,7 @@ public class StopTest
).getBytes());
client.getOutputStream().flush();
while (!connector.isShutdown())
{
Thread.sleep(10);
}
await().atMost(10, TimeUnit.SECONDS).until(connector::isShutdown);
handler.latchB.countDown();
@ -280,11 +278,9 @@ public class StopTest
LocalConnector connector = new LocalConnector(server);
server.addConnector(connector);
StatisticsHandler stats = new StatisticsHandler();
server.setHandler(stats);
ContextHandler context = new ContextHandler("/");
stats.setHandler(context);
StatisticsHandler stats = new StatisticsHandler(context);
server.setHandler(stats);
Exchanger<Void> exchanger0 = new Exchanger<>();
Exchanger<Void> exchanger1 = new Exchanger<>();
@ -314,53 +310,51 @@ public class StopTest
server.setStopTimeout(1000);
server.start();
LocalEndPoint endp = connector.executeRequest(
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"\r\n"
);
exchanger0.exchange(null);
exchanger1.exchange(null);
String response = endp.getResponse();
assertThat(response, containsString("200 OK"));
assertThat(response, Matchers.not(containsString("Connection: close")));
endp.addInputAndExecute(BufferUtil.toBuffer("GET / HTTP/1.1\r\nHost:localhost\r\n\r\n"));
exchanger0.exchange(null);
FutureCallback stopped = new FutureCallback();
new Thread(() ->
try (LocalEndPoint endp = connector.executeRequest(
"""
GET / HTTP/1.1\r
Host: localhost\r
\r
"""
))
{
try
{
server.stop();
stopped.succeeded();
}
catch (Throwable e)
{
stopped.failed(e);
}
}).start();
exchanger0.exchange(null);
exchanger1.exchange(null);
long start = NanoTime.now();
while (!connector.isShutdown())
{
assertThat(NanoTime.secondsSince(start), lessThan(10L));
Thread.sleep(10);
String response = endp.getResponse();
assertThat(response, containsString("200 OK"));
assertThat(response, Matchers.not(containsString("Connection: close")));
endp.addInputAndExecute(BufferUtil.toBuffer("GET / HTTP/1.1\r\nHost:localhost\r\n\r\n"));
exchanger0.exchange(null);
FutureCallback stopped = new FutureCallback();
new Thread(() ->
{
try
{
server.stop();
stopped.succeeded();
}
catch (Throwable e)
{
stopped.failed(e);
}
}).start();
await().atMost(10, TimeUnit.SECONDS).until(connector::isShutdown);
// Check new connections rejected!
assertThrows(IllegalStateException.class, () -> connector.getResponse("GET / HTTP/1.1\r\nHost:localhost\r\n\r\n"));
// Check completed 200 has close
exchanger1.exchange(null);
response = endp.getResponse();
assertThat(response, containsString("200 OK"));
assertThat(response, Matchers.containsString("Connection: close"));
stopped.get(10, TimeUnit.SECONDS);
}
// Check new connections rejected!
assertThrows(IllegalStateException.class, () -> connector.getResponse("GET / HTTP/1.1\r\nHost:localhost\r\n\r\n"));
// Check completed 200 has close
exchanger1.exchange(null);
response = endp.getResponse();
assertThat(response, containsString("200 OK"));
assertThat(response, Matchers.containsString("Connection: close"));
stopped.get(10, TimeUnit.SECONDS);
}
@Test
@ -373,7 +367,6 @@ public class StopTest
ContextHandler context = new ContextHandler("/");
server.setHandler(context);
StatisticsHandler stats = new StatisticsHandler();
context.setHandler(stats);
@ -402,50 +395,51 @@ public class StopTest
server.start();
LocalEndPoint endp = connector.executeRequest(
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"\r\n"
);
exchanger0.exchange(null);
exchanger1.exchange(null);
String response = endp.getResponse();
assertThat(response, containsString("200 OK"));
assertThat(response, Matchers.not(containsString("Connection: close")));
endp.addInputAndExecute(BufferUtil.toBuffer("GET / HTTP/1.1\r\nHost:localhost\r\n\r\n"));
exchanger0.exchange(null);
CountDownLatch latch = new CountDownLatch(1);
new Thread(() ->
try (LocalEndPoint endp = connector.executeRequest(
"""
GET / HTTP/1.1\r
Host: localhost\r
\r
"""
))
{
try
exchanger0.exchange(null);
exchanger1.exchange(null);
String response = endp.getResponse();
assertThat(response, containsString("200 OK"));
assertThat(response, Matchers.not(containsString("Connection: close")));
endp.addInputAndExecute(BufferUtil.toBuffer("GET / HTTP/1.1\r\nHost:localhost\r\n\r\n"));
exchanger0.exchange(null);
CountDownLatch latch = new CountDownLatch(1);
new Thread(() ->
{
context.stop();
latch.countDown();
}
catch (Exception e)
{
e.printStackTrace();
}
}).start();
while (context.isStarted())
{
Thread.sleep(10);
try
{
context.stop();
latch.countDown();
}
catch (Exception e)
{
e.printStackTrace();
}
}).start();
await().atMost(10, TimeUnit.SECONDS).until(context::isStopped);
// Check new connections accepted, but don't find context!
String unavailable = connector.getResponse("GET / HTTP/1.1\r\nHost:localhost\r\n\r\n");
assertThat(unavailable, containsString(" 404 Not Found"));
// Check completed 200 does not have close
exchanger1.exchange(null);
response = endp.getResponse();
assertThat(response, containsString("200 OK"));
assertThat(response, Matchers.not(Matchers.containsString("Connection: close")));
assertTrue(latch.await(10, TimeUnit.SECONDS));
}
// Check new connections accepted, but don't find context!
String unavailable = connector.getResponse("GET / HTTP/1.1\r\nHost:localhost\r\n\r\n");
assertThat(unavailable, containsString(" 404 Not Found"));
// Check completed 200 does not have close
exchanger1.exchange(null);
response = endp.getResponse();
assertThat(response, containsString("200 OK"));
assertThat(response, Matchers.not(Matchers.containsString("Connection: close")));
assertTrue(latch.await(10, TimeUnit.SECONDS));
}
@Test
@ -479,12 +473,12 @@ public class StopTest
ContextHandler context2 = new ContextHandler("/two")
{
@Override
protected void doStart() throws Exception
protected void doStart()
{
context2Started.set(true);
}
};
contexts.setHandlers(new Handler[]{context0, context1, context2});
contexts.setHandlers(context0, context1, context2);
try
{

View File

@ -69,7 +69,7 @@ public class TestJettyJspServlet
_server = new Server();
_connector = new LocalConnector(_server);
_server.addConnector(_connector);
ServletContextHandler context = new ServletContextHandler(_server, "/context", true, false);
ServletContextHandler context = new ServletContextHandler("/context", true, false);
_server.setHandler(context);
context.setClassLoader(new URLClassLoader(new URL[0], Thread.currentThread().getContextClassLoader()));
ServletHolder jspHolder = context.addServlet(JettyJspServlet.class, "/*");

View File

@ -70,7 +70,7 @@ public class Http2Server
server.addBean(LoggerFactory.getILoggerFactory());
ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
ServletContextHandler context = new ServletContextHandler("/", ServletContextHandler.SESSIONS);
Path docroot = Paths.get("src/main/resources/docroot");
if (!Files.exists(docroot))
throw new FileNotFoundException(docroot.toString());

View File

@ -38,16 +38,17 @@ public class ManyServletContexts
server.setHandler(contexts);
// Configure context "/" (root) for servlets
ServletContextHandler root = new ServletContextHandler(contexts, "/",
ServletContextHandler root = new ServletContextHandler("/",
ServletContextHandler.SESSIONS);
contexts.addHandler(root);
// Add servlets to root context
root.addServlet(new ServletHolder(new HelloServlet("Hello")), "/");
root.addServlet(new ServletHolder(new HelloServlet("Ciao")), "/it/*");
root.addServlet(new ServletHolder(new HelloServlet("Bonjour")), "/fr/*");
// Configure context "/other" for servlets
ServletContextHandler other = new ServletContextHandler(contexts,
"/other", ServletContextHandler.SESSIONS);
ServletContextHandler other = new ServletContextHandler("/other", ServletContextHandler.SESSIONS);
contexts.addHandler(other);
// Add servlets to /other context
other.addServlet(DefaultServlet.class.getCanonicalName(), "/");
other.addServlet(new ServletHolder(new HelloServlet("YO!")), "*.yo");

View File

@ -36,8 +36,9 @@ public class ProxyServer
server.setHandler(proxy);
// Setup proxy servlet
ServletContextHandler context = new ServletContextHandler(proxy, "/",
ServletContextHandler context = new ServletContextHandler("/",
ServletContextHandler.SESSIONS);
proxy.setHandler(context);
ServletHolder proxyServlet = new ServletHolder(ProxyServlet.class);
proxyServlet.setInitParameter("blackList", "www.eclipse.org");
context.addServlet(proxyServlet, "/*");

View File

@ -36,7 +36,8 @@ public class ChatServletTest
server = new Server();
connector = new LocalConnector(server);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler(server, "/");
ServletContextHandler context = new ServletContextHandler("/");
server.setHandler(context);
ServletHolder dispatch = context.addServlet(ChatServlet.class, "/chat/*");
dispatch.setInitParameter("asyncTimeout", "500");
server.start();

View File

@ -44,7 +44,8 @@ public class DispatchServletTest
server = new Server();
connector = new LocalConnector(server);
server.addConnector(connector);
context = new ServletContextHandler(server, "/tests");
context = new ServletContextHandler("/tests");
server.setHandler(context);
server.start();
}

View File

@ -55,7 +55,8 @@ public class TryFilesFilterTest
sslConnector = new ServerConnector(server, serverSslContextFactory);
server.addConnector(sslConnector);
ServletContextHandler context = new ServletContextHandler(server, "/");
ServletContextHandler context = new ServletContextHandler("/");
server.setHandler(context);
FilterHolder filterHolder = context.addFilter(TryFilesFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
forwardPath = "/index.php";

View File

@ -109,7 +109,8 @@ public class AsyncMiddleManServletTest
serverConnector = new ServerConnector(server);
server.addConnector(serverConnector);
ServletContextHandler appCtx = new ServletContextHandler(server, "/", true, false);
ServletContextHandler appCtx = new ServletContextHandler("/", true, false);
server.setHandler(appCtx);
ServletHolder appServletHolder = new ServletHolder(servlet);
appCtx.addServlet(appServletHolder, "/*");
@ -136,7 +137,8 @@ public class AsyncMiddleManServletTest
proxyConnector = new ServerConnector(proxy, new HttpConnectionFactory(configuration));
proxy.addConnector(proxyConnector);
ServletContextHandler proxyContext = new ServletContextHandler(proxy, "/", true, false);
ServletContextHandler proxyContext = new ServletContextHandler("/", true, false);
proxy.setHandler(proxyContext);
this.proxyServlet = proxyServlet;
ServletHolder proxyServletHolder = new ServletHolder(proxyServlet);
proxyServletHolder.setInitParameters(initParams);

View File

@ -93,7 +93,8 @@ public class BalancerServletTest
ServerConnector connector = new ServerConnector(server);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler(server, CONTEXT_PATH, ServletContextHandler.SESSIONS);
ServletContextHandler context = new ServletContextHandler(CONTEXT_PATH, ServletContextHandler.SESSIONS);
server.setHandler(context);
context.addServlet(servletHolder, SERVLET_PATH + "/*");
if (nodeName != null)

View File

@ -177,7 +177,7 @@ public class ClientAuthProxyTest
proxyConnector = new ServerConnector(proxy, 1, 1, ssl, http);
proxy.addConnector(proxyConnector);
ServletContextHandler context = new ServletContextHandler(proxy, "/");
ServletContextHandler context = new ServletContextHandler("/");
context.addServlet(new ServletHolder(servlet), "/*");
proxy.setHandler(context);

View File

@ -109,7 +109,8 @@ public class ForwardProxyServerTest
connectHandler.setConnectTimeout(1000);
proxy.setHandler(connectHandler);
ServletContextHandler proxyHandler = new ServletContextHandler(connectHandler, "/");
ServletContextHandler proxyHandler = new ServletContextHandler("/");
connectHandler.setHandler(proxyHandler);
proxyHandler.addServlet(new ServletHolder(proxyServlet), "/*");
proxy.start();

View File

@ -35,7 +35,8 @@ public class ProxyServer
server.setHandler(proxy);
// Setup proxy servlet
ServletContextHandler context = new ServletContextHandler(proxy, "/", ServletContextHandler.SESSIONS);
ServletContextHandler context = new ServletContextHandler("/", ServletContextHandler.SESSIONS);
proxy.setHandler(context);
ServletHolder proxyServlet = new ServletHolder(ProxyServlet.class);
// proxyServlet.setInitParameter("whiteList", "google.com, www.eclipse.org, localhost");
// proxyServlet.setInitParameter("blackList", "google.com/calendar/*, www.eclipse.org/committers/");

View File

@ -99,7 +99,8 @@ public class ProxyServletFailureTest
proxy.addConnector(proxyConnector);
proxyConnector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().setDelayDispatchUntilContent(false);
ServletContextHandler proxyCtx = new ServletContextHandler(proxy, "/", true, false);
ServletContextHandler proxyCtx = new ServletContextHandler("/", true, false);
proxy.setHandler(proxyCtx);
ServletHolder proxyServletHolder = new ServletHolder(proxyServlet);
proxyServletHolder.setInitParameters(initParams);
@ -129,7 +130,8 @@ public class ProxyServletFailureTest
serverConnector = new ServerConnector(server);
server.addConnector(serverConnector);
ServletContextHandler appCtx = new ServletContextHandler(server, "/", true, false);
ServletContextHandler appCtx = new ServletContextHandler("/", true, false);
server.setHandler(appCtx);
ServletHolder appServletHolder = new ServletHolder(servlet);
appCtx.addServlet(appServletHolder, "/*");

View File

@ -77,7 +77,8 @@ public class ProxyServletLoadTest
serverConnector = new ServerConnector(server);
server.addConnector(serverConnector);
ServletContextHandler appCtx = new ServletContextHandler(server, "/", true, false);
ServletContextHandler appCtx = new ServletContextHandler("/", true, false);
server.setHandler(appCtx);
ServletHolder appServletHolder = new ServletHolder(servlet);
appCtx.addServlet(appServletHolder, "/*");
@ -96,7 +97,8 @@ public class ProxyServletLoadTest
proxyConnector = new ServerConnector(proxy, new HttpConnectionFactory(configuration));
proxy.addConnector(proxyConnector);
ServletContextHandler proxyContext = new ServletContextHandler(proxy, "/", true, false);
ServletContextHandler proxyContext = new ServletContextHandler("/", true, false);
proxy.setHandler(proxyContext);
ServletHolder proxyServletHolder = new ServletHolder(proxyServlet);
proxyContext.addServlet(proxyServletHolder, "/*");

View File

@ -152,7 +152,8 @@ public class ProxyServletTest
new HttpConnectionFactory());
server.addConnector(tlsServerConnector);
ServletContextHandler appCtx = new ServletContextHandler(server, "/", true, false);
ServletContextHandler appCtx = new ServletContextHandler("/", true, false);
server.setHandler(appCtx);
ServletHolder appServletHolder = new ServletHolder(servlet);
appCtx.addServlet(appServletHolder, "/*");
@ -184,7 +185,8 @@ public class ProxyServletTest
proxyConnector = new ServerConnector(proxy, new HttpConnectionFactory(configuration));
proxy.addConnector(proxyConnector);
proxyContext = new ServletContextHandler(proxy, "/", true, false);
proxyContext = new ServletContextHandler("/", true, false);
proxy.setHandler(proxyContext);
this.proxyServlet = proxyServlet;
ServletHolder proxyServletHolder = new ServletHolder(proxyServlet);
proxyServletHolder.setInitParameters(initParams);

View File

@ -49,7 +49,8 @@ public class ReverseProxyTest
serverConnector = new ServerConnector(server);
server.addConnector(serverConnector);
ServletContextHandler appCtx = new ServletContextHandler(server, "/", true, false);
ServletContextHandler appCtx = new ServletContextHandler("/", true, false);
server.setHandler(appCtx);
ServletHolder appServletHolder = new ServletHolder(servlet);
appCtx.addServlet(appServletHolder, "/*");
@ -66,7 +67,8 @@ public class ReverseProxyTest
proxyConnector = new ServerConnector(proxy, new HttpConnectionFactory(configuration));
proxy.addConnector(proxyConnector);
ServletContextHandler proxyContext = new ServletContextHandler(proxy, "/", true, false);
ServletContextHandler proxyContext = new ServletContextHandler("/", true, false);
proxy.setHandler(proxyContext);
ServletHolder proxyServletHolder = new ServletHolder(new AsyncMiddleManServlet()
{
@Override

View File

@ -358,8 +358,9 @@ public class Runner
statsHandler.setHandler(oldHandler);
_server.setHandler(statsHandler);
ServletContextHandler statsContext = new ServletContextHandler(_contexts, "/stats");
ServletContextHandler statsContext = new ServletContextHandler("/stats");
statsContext.setSessionHandler(new SessionHandler());
_contexts.addHandler(statsContext);
if (_statsPropFile != null)
{
ResourceFactory resourceFactory = ResourceFactory.of(statsContext);
@ -457,10 +458,11 @@ public class Runner
else
{
// assume it is a WAR file
WebAppContext webapp = new WebAppContext(_contexts, ctx.toString(), contextPath);
WebAppContext webapp = new WebAppContext(ctx.toString(), contextPath);
webapp.setConfigurationClasses(PLUS_CONFIGURATION_CLASSES);
webapp.setAttribute(MetaInfConfiguration.CONTAINER_JAR_PATTERN,
CONTAINER_INCLUDE_JAR_PATTERN);
_contexts.addHandler(webapp);
}
//reset

View File

@ -240,46 +240,40 @@ public class ServletContextHandler extends ContextHandler
public ServletContextHandler(String contextPath)
{
this(null, contextPath);
this(contextPath, null, null, null, null);
}
public ServletContextHandler(int options)
{
this(null, null, options);
this(null, options);
}
public ServletContextHandler(Container parent, String contextPath)
public ServletContextHandler(String contextPath, int options)
{
this(parent, contextPath, null, null, null, null);
this(contextPath, null, null, null, null, options);
}
public ServletContextHandler(Container parent, String contextPath, int options)
public ServletContextHandler(String contextPath, boolean sessions, boolean security)
{
this(parent, contextPath, null, null, null, null, options);
this(contextPath, (sessions ? SESSIONS : 0) | (security ? SECURITY : 0));
}
public ServletContextHandler(Container parent, String contextPath, boolean sessions, boolean security)
public ServletContextHandler(SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler)
{
this(parent, contextPath, (sessions ? SESSIONS : 0) | (security ? SECURITY : 0));
this(null, sessionHandler, securityHandler, servletHandler, errorHandler);
}
public ServletContextHandler(Container parent, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler)
public ServletContextHandler(String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler)
{
this(parent, null, sessionHandler, securityHandler, servletHandler, errorHandler);
this(contextPath, sessionHandler, securityHandler, servletHandler, errorHandler, 0);
}
public ServletContextHandler(Container parent, String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler)
{
this(parent, contextPath, sessionHandler, securityHandler, servletHandler, errorHandler, 0);
}
public ServletContextHandler(Container parent, String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler, int options)
public ServletContextHandler(String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler, int options)
{
_servletContext = newServletContextApi();
if (contextPath != null)
setContextPath(contextPath);
Container.setAsParent(parent, this);
_options = options;
_sessionHandler = sessionHandler;

View File

@ -217,7 +217,8 @@ public class ServletTester extends ContainerLifeCycle
public ServletTester(String contextPath, int options)
{
_context = new ServletContextHandler(_server, contextPath, options);
_context = new ServletContextHandler(contextPath, options);
_server.setHandler(_context);
_server.setConnectors(new Connector[]{_connector});
addBean(_server);
}

View File

@ -47,8 +47,9 @@ public class AsyncContextListenersTest
_connector = new ServerConnector(_server);
_server.addConnector(_connector);
ServletContextHandler context = new ServletContextHandler(_server, "/", false, false);
ServletContextHandler context = new ServletContextHandler("/", false, false);
context.addServlet(new ServletHolder(servlet), path);
_server.setHandler(context);
_server.start();
}

View File

@ -47,7 +47,8 @@ public class AsyncServletLongPollTest
connector = new ServerConnector(server);
server.addConnector(connector);
String contextPath = "/context";
context = new ServletContextHandler(server, contextPath, ServletContextHandler.NO_SESSIONS);
context = new ServletContextHandler(contextPath, ServletContextHandler.NO_SESSIONS);
server.setHandler(context);
ServletHolder servletHolder = new ServletHolder(servlet);
String servletPath = "/path";
context.addServlet(servletHolder, servletPath);

View File

@ -3188,7 +3188,7 @@ public class DefaultServletTest
@Test
public void testPathInfoOnly() throws Exception
{
ServletContextHandler context = new ServletContextHandler(null, "/c1", ServletContextHandler.NO_SESSIONS);
ServletContextHandler context = new ServletContextHandler("/c1", ServletContextHandler.NO_SESSIONS);
context.setWelcomeFiles(new String[]{"index.y", "index.x"});
ServletHolder indexServlet = new ServletHolder("index-servlet", new HttpServlet()
{

View File

@ -50,9 +50,10 @@ public class DispatcherForwardTest
connector = new LocalConnector(server);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler(server, "/");
ServletContextHandler context = new ServletContextHandler("/");
context.addServlet(new ServletHolder(servlet1), "/one");
context.addServlet(new ServletHolder(servlet2), "/two");
server.setHandler(context);
server.start();
}

View File

@ -63,9 +63,10 @@ public class FormTest
connector = new ServerConnector(server, 1, 1);
server.addConnector(connector);
ServletContextHandler handler = new ServletContextHandler(server, contextPath);
ServletContextHandler handler = new ServletContextHandler(contextPath);
HttpServlet servlet = config.apply(handler);
handler.addServlet(new ServletHolder(servlet), servletPath + "/*");
server.setHandler(handler);
server.start();
}

View File

@ -55,7 +55,7 @@ public class GzipHandlerBreakEvenSizeTest
GzipHandler gzipHandler = new GzipHandler();
ServletContextHandler context = new ServletContextHandler(gzipHandler, "/");
ServletContextHandler context = new ServletContextHandler("/");
context.addServlet(VeryCompressibleContentServlet.class, "/content");
gzipHandler.setHandler(context);
server.setHandler(gzipHandler);

View File

@ -125,7 +125,7 @@ public class GzipHandlerTest
_server.setHandler(gzipHandler);
gzipHandler.setHandler(context);
}
_server.start();
}

View File

@ -90,7 +90,7 @@ public class InitServletTest
public void testServletInitialization() throws Exception
{
Server server = new Server(0);
ServletContextHandler context = new ServletContextHandler(server, "/");
ServletContextHandler context = new ServletContextHandler("/");
server.setHandler(context);
// Add a lazily instantiated servlet.
context.addServlet(new ServletHolder(DemoServlet.class), "/*");

View File

@ -109,7 +109,7 @@ public class MultiPartServletTest
connector = new ServerConnector(server);
server.addConnector(connector);
ServletContextHandler contextHandler = new ServletContextHandler(server, "/");
ServletContextHandler contextHandler = new ServletContextHandler("/");
ServletHolder servletHolder = new ServletHolder(servlet);
servletHolder.getRegistration().setMultipartConfig(config);
contextHandler.addServlet(servletHolder, "/");

View File

@ -41,7 +41,7 @@ public class RegexServletTest
_server = new Server();
_connector = new LocalConnector(_server);
_servletContextHandler = new ServletContextHandler(_server, "/ctx");
_servletContextHandler = new ServletContextHandler("/ctx");
_servletContextHandler.setServletHandler(new ServletHandler()
{
@Override

View File

@ -177,7 +177,8 @@ public class SSLAsyncIOServletTest
server.addConnector(connector);
contextPath = "/context";
ServletContextHandler context = new ServletContextHandler(server, contextPath, true, false);
ServletContextHandler context = new ServletContextHandler(contextPath, true, false);
server.setHandler(context);
servletPath = "/servlet";
context.addServlet(new ServletHolder(servlet), servletPath);
@ -225,7 +226,8 @@ public class SSLAsyncIOServletTest
server.addConnector(connector);
contextPath = "/context";
ServletContextHandler context = new ServletContextHandler(server, contextPath, true, false);
ServletContextHandler context = new ServletContextHandler(contextPath, true, false);
server.setHandler(context);
servletPath = "/servlet";
context.addServlet(new ServletHolder(servlet), servletPath);

View File

@ -689,7 +689,7 @@ public class ServletContextHandlerTest
public void testInitParams() throws Exception
{
//Test get/setInitParam with null throws NPE
ServletContextHandler root = new ServletContextHandler(_server, "/", ServletContextHandler.SESSIONS);
ServletContextHandler root = new ServletContextHandler("/", ServletContextHandler.SESSIONS);
_server.setHandler(root);
ListenerHolder initialListener = new ListenerHolder();
initialListener.setListener(new ServletContextListener()
@ -782,7 +782,8 @@ public class ServletContextHandlerTest
int startMin = 7;
Integer timeout = Integer.valueOf(100);
ServletContextHandler root = new ServletContextHandler(contexts, "/", ServletContextHandler.SESSIONS);
ServletContextHandler root = new ServletContextHandler("/", ServletContextHandler.SESSIONS);
contexts.addHandler(root);
root.getSessionHandler().setMaxInactiveInterval((int)TimeUnit.MINUTES.toSeconds(startMin));
root.addBean(new MySCIStarter(root.getContext(), new MySCI(true, timeout.intValue())), true);
_server.start();
@ -806,7 +807,8 @@ public class ServletContextHandlerTest
ContextHandlerCollection contexts = new ContextHandlerCollection();
_server.setHandler(contexts);
ServletContextHandler root = new ServletContextHandler(contexts, "/", ServletContextHandler.SESSIONS);
ServletContextHandler root = new ServletContextHandler("/", ServletContextHandler.SESSIONS);
contexts.addHandler(root);
ListenerHolder listenerHolder = new ListenerHolder();
StopTestListener stopTestListener = new StopTestListener();
listenerHolder.setListener(stopTestListener);
@ -837,7 +839,8 @@ public class ServletContextHandlerTest
ContextHandlerCollection contexts = new ContextHandlerCollection();
_server.setHandler(contexts);
ServletContextHandler root = new ServletContextHandler(contexts, "/", ServletContextHandler.SESSIONS);
ServletContextHandler root = new ServletContextHandler("/", ServletContextHandler.SESSIONS);
contexts.addHandler(root);
MySessionHandler sessions = new MySessionHandler();
root.setSessionHandler(sessions);
@ -855,7 +858,8 @@ public class ServletContextHandlerTest
ContextHandlerCollection contexts = new ContextHandlerCollection();
_server.setHandler(contexts);
ServletContextHandler root = new ServletContextHandler(contexts, "/");
ServletContextHandler root = new ServletContextHandler("/");
contexts.addHandler(root);
root.addBean(new MySCIStarter(root.getContext(), new MySCI()), true);
_server.start();
assertTrue((Boolean)root.getServletContext().getAttribute("MySCI.startup"));
@ -876,7 +880,8 @@ public class ServletContextHandlerTest
ContextHandlerCollection contexts = new ContextHandlerCollection();
server.setHandler(contexts);
ServletContextHandler root = new ServletContextHandler(contexts, "/");
ServletContextHandler root = new ServletContextHandler("/");
contexts.addHandler(root);
class TestServletContextListener implements ServletContextListener
{
public int initialized = 0;
@ -910,7 +915,8 @@ public class ServletContextHandlerTest
ContextHandlerCollection contexts = new ContextHandlerCollection();
_server.setHandler(contexts);
ServletContextHandler root = new ServletContextHandler(contexts, "/", ServletContextHandler.SESSIONS);
ServletContextHandler root = new ServletContextHandler("/", ServletContextHandler.SESSIONS);
contexts.addHandler(root);
root.getSessionHandler().setSessionDomain("testing");
ListenerHolder initialListener = new ListenerHolder();
initialListener.setListener(new InitialListener());
@ -1022,7 +1028,8 @@ public class ServletContextHandlerTest
ContextHandlerCollection contexts = new ContextHandlerCollection();
_server.setHandler(contexts);
ServletContextHandler root = new ServletContextHandler(contexts, "/", ServletContextHandler.SESSIONS);
ServletContextHandler root = new ServletContextHandler("/", ServletContextHandler.SESSIONS);
contexts.addHandler(root);
SessionHandler session = root.getSessionHandler();
ServletHandler servlet = root.getServletHandler();
@ -1107,7 +1114,8 @@ public class ServletContextHandlerTest
ContextHandlerCollection contexts = new ContextHandlerCollection();
_server.setHandler(contexts);
ServletContextHandler root = new ServletContextHandler(contexts, "/");
ServletContextHandler root = new ServletContextHandler("/");
contexts.addHandler(root);
class FilterCreatingSCI implements ServletContainerInitializer
{
@Override
@ -1153,7 +1161,8 @@ public class ServletContextHandlerTest
ContextHandlerCollection contexts = new ContextHandlerCollection();
_server.setHandler(contexts);
ServletContextHandler root = new ServletContextHandler(contexts, "/");
ServletContextHandler root = new ServletContextHandler("/");
contexts.addHandler(root);
class ListenerCreatingSCI implements ServletContainerInitializer
{
@Override
@ -1345,7 +1354,8 @@ public class ServletContextHandlerTest
ContextHandlerCollection contexts = new ContextHandlerCollection();
_server.setHandler(contexts);
ServletContextHandler root = new ServletContextHandler(contexts, "/");
ServletContextHandler root = new ServletContextHandler("/");
contexts.addHandler(root);
class ServletAddingSCI implements ServletContainerInitializer
{
@Override
@ -1378,7 +1388,8 @@ public class ServletContextHandlerTest
ContextHandlerCollection contexts = new ContextHandlerCollection();
_server.setHandler(contexts);
ServletContextHandler root = new ServletContextHandler(contexts, "/");
ServletContextHandler root = new ServletContextHandler("/");
contexts.addHandler(root);
ServletHolder jspServlet = new ServletHolder();
jspServlet.setName("jsp");
jspServlet.setHeldClass(FakeJspServlet.class);
@ -1416,7 +1427,8 @@ public class ServletContextHandlerTest
ContextHandlerCollection contexts = new ContextHandlerCollection();
_server.setHandler(contexts);
ServletContextHandler root = new ServletContextHandler(contexts, "/");
ServletContextHandler root = new ServletContextHandler("/");
contexts.addHandler(root);
ServletHolder jspServlet = new ServletHolder();
jspServlet.setName("jsp");
jspServlet.setHeldClass(FakeJspServlet.class);
@ -1453,7 +1465,8 @@ public class ServletContextHandlerTest
ContextHandlerCollection contexts = new ContextHandlerCollection();
_server.setHandler(contexts);
ServletContextHandler root = new ServletContextHandler(contexts, "/");
ServletContextHandler root = new ServletContextHandler("/");
contexts.addHandler(root);
ServletHolder jspServlet = new ServletHolder();
jspServlet.setName("jsp");
jspServlet.setHeldClass(FakeJspServlet.class);
@ -1897,7 +1910,8 @@ public class ServletContextHandlerTest
Handler.Sequence list = new Handler.Sequence();
_server.setHandler(list);
ServletContextHandler root = new ServletContextHandler(list, "/", ServletContextHandler.SESSIONS);
ServletContextHandler root = new ServletContextHandler("/", ServletContextHandler.SESSIONS);
list.addHandler(root);
ServletHandler servlet = root.getServletHandler();
servlet.setEnsureDefaultServlet(false);
@ -2435,7 +2449,7 @@ public class ServletContextHandlerTest
@Test
public void testEmptyPathInfo() throws Exception
{
ServletContextHandler context = new ServletContextHandler(null, "/c1", ServletContextHandler.NO_SESSIONS);
ServletContextHandler context = new ServletContextHandler("/c1", ServletContextHandler.NO_SESSIONS);
context.setAllowNullPathInContext(true);
context.addServlet(new ServletHolder("default-servlet", new HttpServlet()
{

View File

@ -51,7 +51,8 @@ public class ServletLifeCycleTest
LocalConnector connector = new LocalConnector(server);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler(server, "/");
ServletContextHandler context = new ServletContextHandler("/");
server.setHandler(context);
context.getObjectFactory().addDecorator(new TestDecorator());

View File

@ -60,7 +60,8 @@ public abstract class AbstractDoSFilterTest
_server = new Server();
_connector = new ServerConnector(_server);
_server.addConnector(_connector);
ServletContextHandler context = new ServletContextHandler(_server, "/ctx", true, false);
ServletContextHandler context = new ServletContextHandler("/ctx", true, false);
_server.setHandler(context);
DefaultSessionCache sessionCache = new DefaultSessionCache(context.getSessionHandler());
FileSessionDataStore fileStore = new FileSessionDataStore();

View File

@ -58,7 +58,8 @@ public class CrossOriginFilterTest
server = new Server();
connector = new LocalConnector(server);
server.addConnector(connector);
context = new ServletContextHandler(server, "/");
context = new ServletContextHandler("/");
server.setHandler(context);
server.start();
}

View File

@ -48,7 +48,8 @@ public class DoSFilterJMXTest
Connector connector = new ServerConnector(server);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
ServletContextHandler context = new ServletContextHandler("/", ServletContextHandler.SESSIONS);
server.setHandler(context);
DoSFilter filter = new DoSFilter();
FilterHolder holder = new FilterHolder(filter);
String name = "dos";

View File

@ -51,7 +51,8 @@ public class EventSourceServletTest
connector = (NetworkConnector)server.getConnectors()[0];
String contextPath = "/test";
context = new ServletContextHandler(server, contextPath, ServletContextHandler.SESSIONS);
context = new ServletContextHandler(contextPath, ServletContextHandler.SESSIONS);
server.setHandler(context);
server.start();
}

View File

@ -50,8 +50,9 @@ public class HeaderFilterTest
_server = new Server();
_connector = new LocalConnector(_server);
_server.addConnector(_connector);
_context = new ServletContextHandler(_server, "/context");
_context = new ServletContextHandler("/context");
_context.addServlet(NullServlet.class, "/test/*");
_server.setHandler(_context);
_server.start();
}

View File

@ -51,7 +51,8 @@ public class IncludeExcludeBasedFilterTest
_server = new Server();
_connector = new LocalConnector(_server);
_server.addConnector(_connector);
_context = new ServletContextHandler(_server, "/context");
_context = new ServletContextHandler("/context");
_server.setHandler(_context);
_context.addServlet(NullServlet.class, "/test/*");
_server.start();
}

View File

@ -64,7 +64,8 @@ public class QoSFilterTest
public void setUp() throws Exception
{
server = new Server();
context = new ServletContextHandler(server, "/context");
context = new ServletContextHandler("/context");
server.setHandler(context);
context.addServlet(TestServlet.class, "/test");
TestServlet.__maxSleepers = 0;
TestServlet.__sleepers = 0;

View File

@ -104,7 +104,7 @@ public class ThreadStarvationTest
connector.setIdleTimeout(Long.MAX_VALUE);
_server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler(_server, "/");
ServletContextHandler context = new ServletContextHandler("/");
context.setBaseResourceAsPath(directory.toPath());
//TODO: Uses DefaultServlet, currently all commented out

View File

@ -118,7 +118,8 @@ public class HttpInputIntegrationTest
http2.setIdleTimeout(5000);
__server.addConnector(http2);
ServletContextHandler context = new ServletContextHandler(__server, "/ctx");
ServletContextHandler context = new ServletContextHandler("/ctx");
__server.setHandler(context);
ServletHolder holder = new ServletHolder(new TestServlet());
holder.setAsyncSupported(true);
context.addServlet(holder, "/*");

View File

@ -120,7 +120,8 @@ public class SessionTestSupport
public ServletContextHandler addContext(String contextPath) throws Exception
{
ServletContextHandler context = new ServletContextHandler(_contexts, contextPath);
ServletContextHandler context = new ServletContextHandler(contextPath);
_contexts.addHandler(context);
SessionHandler sessionHandler = newSessionHandler();
sessionHandler.setSessionIdManager(_sessionIdManager);
sessionHandler.setMaxInactiveInterval(_maxInactivePeriod);

View File

@ -56,7 +56,8 @@ public class RequestDispatchedSessionTest
ContextHandlerCollection handlers = new ContextHandlerCollection();
// Default session behavior
ServletContextHandler contextHandler = new ServletContextHandler(handlers, "/", ServletContextHandler.SESSIONS);
ServletContextHandler contextHandler = new ServletContextHandler("/", ServletContextHandler.SESSIONS);
handlers.addHandler(contextHandler);
contextHandler.addServlet(LoginServlet.class, "/login");
contextHandler.addServlet(ShowUserServlet.class, "/user");
contextHandler.addServlet(DefaultServlet.class, "/");

View File

@ -49,7 +49,6 @@ import org.eclipse.jetty.ee10.servlet.security.ConstraintSecurityHandler;
import org.eclipse.jetty.security.SecurityHandler;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Deployable;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.ExceptionUtil;
import org.eclipse.jetty.util.IO;
@ -150,7 +149,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
public WebAppContext()
{
this(null, null, null, null, null, new ErrorPageErrorHandler(), SESSIONS | SECURITY);
this(null, null, null, null, new ErrorPageErrorHandler(), SESSIONS | SECURITY);
}
/**
@ -159,7 +158,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
*/
public WebAppContext(String webApp, String contextPath)
{
this(null, contextPath, null, null, null, new ErrorPageErrorHandler(), SESSIONS | SECURITY);
this(contextPath, null, null, null, new ErrorPageErrorHandler(), SESSIONS | SECURITY);
setWar(webApp);
}
@ -169,29 +168,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
*/
public WebAppContext(Resource webApp, String contextPath)
{
this(null, contextPath, null, null, null, new ErrorPageErrorHandler(), SESSIONS | SECURITY);
setWarResource(webApp);
}
/**
* @param parent The parent container.
* @param contextPath The context path
* @param webApp The URL or filename of the webapp directory or war file.
*/
public WebAppContext(Container parent, String webApp, String contextPath)
{
this(parent, contextPath, null, null, null, new ErrorPageErrorHandler(), SESSIONS | SECURITY);
setWar(webApp);
}
/**
* @param parent The parent container.
* @param contextPath The context path
* @param webApp The webapp directory or war file.
*/
public WebAppContext(Container parent, Resource webApp, String contextPath)
{
this(parent, contextPath, null, null, null, new ErrorPageErrorHandler(), SESSIONS | SECURITY);
this(contextPath, null, null, null, new ErrorPageErrorHandler(), SESSIONS | SECURITY);
setWarResource(webApp);
}
@ -203,11 +180,10 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
*/
public WebAppContext(SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler)
{
this(null, null, sessionHandler, securityHandler, servletHandler, errorHandler, 0);
this(null, sessionHandler, securityHandler, servletHandler, errorHandler, 0);
}
/**
* @param parent the parent container
* @param contextPath the context path
* @param sessionHandler SessionHandler for this web app
* @param securityHandler SecurityHandler for this web app
@ -215,14 +191,13 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
* @param errorHandler ErrorHandler for this web app
* @param options the options ({@link ServletContextHandler#SESSIONS} and/or {@link ServletContextHandler#SECURITY})
*/
public WebAppContext(Container parent, String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler, int options)
public WebAppContext(String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler, int options)
{
// always pass parent as null and then set below, so that any resulting setServer call
// is done after this instance is constructed.
super(null, contextPath, sessionHandler, securityHandler, servletHandler, errorHandler, options);
super(contextPath, sessionHandler, securityHandler, servletHandler, errorHandler, options);
setErrorHandler(errorHandler != null ? errorHandler : new ErrorPageErrorHandler());
setProtectedTargets(__dftProtectedTargets);
Handler.Container.setAsParent(parent, this);
}
@Override

View File

@ -440,7 +440,7 @@ public class WebAppContextTest
Server server = newServer();
ContextHandlerCollection contexts = new ContextHandlerCollection();
WebAppContext context = new WebAppContext(null, null, null, null, null, new ErrorPageErrorHandler(),
WebAppContext context = new WebAppContext(null, null, null, null, new ErrorPageErrorHandler(),
ServletContextHandler.NO_SESSIONS | ServletContextHandler.NO_SECURITY);
context.setContextPath("/");

View File

@ -86,7 +86,7 @@ public class WebAppDefaultServletTest
output.write("standard hash dir welcome".getBytes(StandardCharsets.UTF_8));
}
WebAppContext context = new WebAppContext(server, directoryPath.toString(), "/");
WebAppContext context = new WebAppContext(directoryPath.toString(), "/");
server.setHandler(context);
server.start();

View File

@ -161,7 +161,8 @@ public class LocalServer extends ContainerLifeCycle implements LocalFuzzer.Provi
protected Handler createRootHandler(Server server) throws Exception
{
servletContextHandler = new ServletContextHandler(server, "/", true, false);
servletContextHandler = new ServletContextHandler("/", true, false);
server.setHandler(servletContextHandler);
servletContextHandler.setContextPath("/");
JakartaWebSocketServletContainerInitializer.configure(servletContextHandler, (context, container) ->
((JakartaWebSocketServerContainer)container).addSessionListener(trackingListener));

View File

@ -72,7 +72,8 @@ public class MemoryUsageTest
connector = new ServerConnector(server);
server.addConnector(connector);
ServletContextHandler contextHandler = new ServletContextHandler(server, "/", true, false);
ServletContextHandler contextHandler = new ServletContextHandler("/", true, false);
server.setHandler(contextHandler);
JakartaWebSocketServletContainerInitializer.configure(contextHandler, (context, container) ->
{
ServerEndpointConfig config = ServerEndpointConfig.Builder.create(BasicEndpoint.class, "/").build();

View File

@ -103,7 +103,7 @@ public class ServerDecoderTest
server = new Server();
ServerConnector serverConnector = new ServerConnector(server);
server.addConnector(serverConnector);
ServletContextHandler servletContextHandler = new ServletContextHandler(null, "/");
ServletContextHandler servletContextHandler = new ServletContextHandler("/");
server.setHandler(servletContextHandler);
JakartaWebSocketServletContainerInitializer.configure(servletContextHandler, ((servletContext, serverContainer) ->

View File

@ -121,7 +121,8 @@ public class WebSocketOverHTTP2Test
tlsConnector = new ServerConnector(server, 1, 1, ssl, alpn, h1s, h2s);
server.addConnector(tlsConnector);
context = new ServletContextHandler(server, "/");
context = new ServletContextHandler("/");
server.setHandler(context);
context.addServlet(new ServletHolder(servlet), "/ws/*");
JettyWebSocketServletContainerInitializer.configure(context, null);

View File

@ -248,7 +248,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Supplie
_initParams = new HashMap<>();
if (contextPath != null)
setContextPath(contextPath);
Handler.Container.setAsParent(parent, _coreContextHandler);
HandlerWrapper.setAsParent(parent, _coreContextHandler);
}
@Override

View File

@ -138,4 +138,19 @@ public class HandlerWrapper extends AbstractHandlerContainer
}
super.destroy();
}
/**
* <p>Make a {@link org.eclipse.jetty.server.Handler.Container} the parent of a {@link org.eclipse.jetty.server.Handler}</p>
* @param parent The {@link org.eclipse.jetty.server.Handler.Container} that will be the parent
* @param handler The {@link org.eclipse.jetty.server.Handler} that will be the child
*/
public static void setAsParent(org.eclipse.jetty.server.Handler.Container parent, org.eclipse.jetty.server.Handler handler)
{
if (parent instanceof org.eclipse.jetty.server.Handler.Collection collection)
collection.addHandler(handler);
else if (parent instanceof org.eclipse.jetty.server.Handler.Singleton wrapper)
wrapper.setHandler(handler);
else if (parent != null)
throw new IllegalArgumentException("Unknown parent type: " + parent);
}
}

View File

@ -42,6 +42,7 @@ import jakarta.servlet.http.HttpSessionIdListener;
import jakarta.servlet.http.HttpSessionListener;
import org.eclipse.jetty.ee9.nested.ContextHandler;
import org.eclipse.jetty.ee9.nested.ErrorHandler;
import org.eclipse.jetty.ee9.nested.HandlerWrapper;
import org.eclipse.jetty.ee9.nested.SessionHandler;
import org.eclipse.jetty.ee9.security.ConstraintAware;
import org.eclipse.jetty.ee9.security.ConstraintMapping;
@ -234,7 +235,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
_apiContext = new Context();
setErrorHandler(errorHandler != null ? errorHandler : new ErrorPageErrorHandler());
setProtectedTargets(__dftProtectedTargets);
Handler.Container.setAsParent(parent, this.get());
HandlerWrapper.setAsParent(parent, this.get());
}
@Override