Use ServerConnector to specify bind IP and idle timeout

This commit is contained in:
Simon Detheridge 2021-06-24 17:00:19 +01:00
parent cafa94fcba
commit d12b564ec3

View file

@ -2,6 +2,7 @@ package uk.ac.ic.wlgitbridge.server;
import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.*; import org.eclipse.jetty.server.handler.*;
import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletContextHandler;
@ -71,7 +72,7 @@ public class GitBridgeServer {
swapStore, swapStore,
snapshotApi snapshotApi
); );
jettyServer = new Server(port); jettyServer = new Server();
configureJettyServer(config, repoStore, snapshotApi); configureJettyServer(config, repoStore, snapshotApi);
apiBaseURL = config.getAPIBaseURL(); apiBaseURL = config.getAPIBaseURL();
SnapshotAPIRequest.setBaseURL(apiBaseURL); SnapshotAPIRequest.setBaseURL(apiBaseURL);
@ -113,6 +114,12 @@ public class GitBridgeServer {
RepoStore repoStore, RepoStore repoStore,
SnapshotApi snapshotApi SnapshotApi snapshotApi
) throws ServletException { ) throws ServletException {
ServerConnector connector = new ServerConnector(this.jettyServer);
connector.setPort(config.getPort());
connector.setHost(config.getBindIp());
connector.setIdleTimeout(config.getIdleTimeout());
this.jettyServer.addConnector(connector);
HandlerCollection handlers = new HandlerList(); HandlerCollection handlers = new HandlerList();
handlers.addHandler(initApiHandler()); handlers.addHandler(initApiHandler());
handlers.addHandler(initBaseHandler()); handlers.addHandler(initBaseHandler());