Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use HandlerList instead of HandlerCollection #4757

Merged
merged 2 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
package org.eclipse.jetty.embedded;

import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.servlet.ServletContextHandler;

public class ExampleServer
Expand All @@ -41,9 +40,7 @@ public static Server createServer(int port)
context.addServlet(HelloServlet.class, "/hello");
context.addServlet(AsyncEchoServlet.class, "/echo/*");

HandlerCollection handlers = new HandlerCollection();
handlers.setHandlers(new Handler[]{context, new DefaultHandler()});
server.setHandler(handlers);
server.setHandler(new HandlerList(context, new DefaultHandler()));

return server;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HttpOutput;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
Expand Down Expand Up @@ -62,12 +61,9 @@ public static Server createServer(int port, File resourceBase)
{
Server server = new Server(port);

HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[]{
server.setHandler(new HandlerList(
new FastFileHandler(resourceBase),
new DefaultHandler()
});
server.setHandler(handlers);
new DefaultHandler()));
return server;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.nio.file.Path;
import java.nio.file.Paths;

import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
Expand Down Expand Up @@ -53,9 +52,7 @@ public static Server createServer(int port, Resource baseResource) throws Except
resourceHandler.setBaseResource(baseResource);

// Add the ResourceHandler to the server.
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[]{resourceHandler, new DefaultHandler()});
server.setHandler(handlers);
server.setHandler(new HandlerList(resourceHandler, new DefaultHandler()));

return server;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ public static Server createServer(int port) throws Exception
context.setBaseResource(base);
context.addServlet(new ServletHolder(new DefaultServlet()), "/");

HandlerList handlers = new HandlerList();
handlers.addHandler(context);
handlers.addHandler(new DefaultHandler());
server.setHandler(handlers);
server.setHandler(new HandlerList(context, new DefaultHandler()));
return server;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.eclipse.jetty.server.AsyncRequestLogWriter;
import org.eclipse.jetty.server.CustomRequestLog;
import org.eclipse.jetty.server.DebugListener;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.LowResourceMonitor;
Expand All @@ -51,7 +50,7 @@
import org.eclipse.jetty.server.SslConnectionFactory;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.StatisticsHandler;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
Expand Down Expand Up @@ -105,10 +104,8 @@ public static Server createServer(int port, int securePort, boolean addDebugList
// httpConfig.addCustomizer(new ForwardedRequestCustomizer());

// Handler Structure
HandlerCollection handlers = new HandlerCollection();
ContextHandlerCollection contexts = new ContextHandlerCollection();
handlers.setHandlers(new Handler[]{contexts, new DefaultHandler()});
server.setHandler(handlers);
server.setHandler(new HandlerList(contexts, new DefaultHandler()));

// === jetty-jmx.xml ===
MBeanContainer mbContainer = new MBeanContainer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static Server createServer(int port) throws IOException
CustomRequestLog ncsaLog = new CustomRequestLog(requestLogFile.getAbsolutePath());
server.setRequestLog(ncsaLog);

// create the handler collections
// create the handlers list
HandlerList handlers = new HandlerList();

// wrap contexts around specific handlers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,8 @@ public static Server createServer(int port)
{
Server server = new Server(port);

HandlerList handlers = new HandlerList();

ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
handlers.addHandler(context);

// Enable javax.websocket configuration for the context
JavaxWebSocketServletContainerInitializer.configure(context,
Expand All @@ -65,8 +62,7 @@ public static Server createServer(int port)
}
);

handlers.addHandler(new DefaultHandler());
server.setHandler(handlers);
server.setHandler(new HandlerList(context, new DefaultHandler()));
gregw marked this conversation as resolved.
Show resolved Hide resolved

return server;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/embedded/src/main/resources/exampleserver.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</New>

<Set name="handler">
<New class="org.eclipse.jetty.server.handler.HandlerCollection">
<New class="org.eclipse.jetty.server.handler.HandlerList">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<Item>
Expand Down
2 changes: 1 addition & 1 deletion examples/embedded/src/main/resources/jetty-otherserver.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<Configure id="OtherServer" class="org.eclipse.jetty.server.Server">
<Set name="handler">
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerList">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<Item>
Expand Down
16 changes: 4 additions & 12 deletions jetty-ant/src/main/java/org/eclipse/jetty/ant/ServerProxyImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.eclipse.jetty.ant.utils.ServerProxy;
import org.eclipse.jetty.ant.utils.TaskLog;
import org.eclipse.jetty.security.LoginService;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.RequestLog;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
Expand All @@ -39,6 +38,7 @@
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.util.Scanner;
import org.eclipse.jetty.util.resource.PathResource;
import org.eclipse.jetty.util.resource.Resource;
Expand Down Expand Up @@ -406,23 +406,15 @@ private void configureHandlers()
if (requestLog != null)
server.setRequestLog(requestLog);

contexts = (ContextHandlerCollection)server
.getChildHandlerByClass(ContextHandlerCollection.class);
contexts = server.getChildHandlerByClass(ContextHandlerCollection.class);
if (contexts == null)
{
contexts = new ContextHandlerCollection();
HandlerCollection handlers = (HandlerCollection)server
.getChildHandlerByClass(HandlerCollection.class);
HandlerCollection handlers = server.getChildHandlerByClass(HandlerCollection.class);
if (handlers == null)
{
handlers = new HandlerCollection();
server.setHandler(handlers);
handlers.setHandlers(new Handler[]{contexts, new DefaultHandler()});
}
server.setHandler(new HandlerList(contexts, new DefaultHandler()));
else
{
handlers.addHandler(contexts);
}
}

//if there are any extra contexts to deploy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
Expand Down Expand Up @@ -69,7 +69,7 @@ public void testBadAppThrowOnUnavailableTrueXmlOrder() throws Exception
It is important that this Order be maintained for an accurate test case.
### BEAN: QueuedThreadPool[qtp1327763628]@4f2410ac{STOPPED,8<=0<=200,i=0,r=-1,q=0}[NO_TRY]
### BEAN: ServerConnector@16f65612{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
### BEAN: HandlerCollection@5f150435{STOPPED}
### BEAN: HandlerList@5f150435{STOPPED}
### BEAN: DeploymentManager@1c53fd30{STOPPED}
*/

Expand All @@ -79,10 +79,8 @@ public void testBadAppThrowOnUnavailableTrueXmlOrder() throws Exception
server.addConnector(connector);

ContextHandlerCollection contexts = new ContextHandlerCollection();
HandlerCollection handlers = new HandlerCollection();
handlers.addHandler(contexts);
handlers.addHandler(new DefaultHandler());
server.setHandler(handlers); // this should be done before addBean(deploymentManager)
// this should be done before addBean(deploymentManager)
server.setHandler(new HandlerList(contexts, new DefaultHandler()));

DeploymentManager deploymentManager = new DeploymentManager();
deploymentManager.setContexts(contexts);
Expand Down Expand Up @@ -121,7 +119,7 @@ public void testBadAppThrowOnUnavailableTrueEmbeddedOrder() throws Exception
### BEAN: QueuedThreadPool[qtp1530388690]@5b37e0d2{STOPPED,8<=0<=200,i=0,r=-1,q=0}[NO_TRY]
### BEAN: ServerConnector@5e265ba4{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
### BEAN: DeploymentManager@3419866c{STOPPED}
### BEAN: HandlerCollection@63e31ee{STOPPED}
### BEAN: HandlerList@63e31ee{STOPPED}
*/

server = new Server();
Expand All @@ -146,12 +144,11 @@ public void testBadAppThrowOnUnavailableTrueEmbeddedOrder() throws Exception
webAppProvider.setMonitoredDirName(webappsDir.toString());
webAppProvider.setScanInterval(1);

server.addBean(deploymentManager); // this should be done before setHandler(handlers)
// this must be done before setHandler(handlers)
server.addBean(deploymentManager);

HandlerCollection handlers = new HandlerCollection();
handlers.addHandler(contexts);
handlers.addHandler(new DefaultHandler());
server.setHandler(handlers); // this should be done after addBean(deploymentManager)
// this must be done after addBean(deploymentManager)
server.setHandler(new HandlerList(contexts, new DefaultHandler()));

assertTimeoutPreemptively(ofSeconds(10), () ->
{
Expand Down
2 changes: 1 addition & 1 deletion jetty-deploy/src/test/resources/jetty.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<!-- RequestLogHandler after the default handler -->
<!-- =========================================================== -->
<Set name="handler">
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerList">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<Item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsServer;
import com.sun.net.httpserver.spi.HttpServerProvider;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.util.thread.ThreadPool;

Expand Down Expand Up @@ -57,8 +56,7 @@ public HttpServer createHttpServer(InetSocketAddress addr, int backlog)
ThreadPool threadPool = new DelegatingThreadPool(new QueuedThreadPool());
server = new Server(threadPool);

HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.setHandlers(new Handler[]{new ContextHandlerCollection(), new DefaultHandler()});
HandlerList handlerCollection = new HandlerList(new ContextHandlerCollection(), new DefaultHandler());
server.setHandler(handlerCollection);

shared = false;
Expand Down

This file was deleted.

Loading