Skip to content

Commit 813721e

Browse files
authored
Configure the StatisticsHandler correctly (#2)
* Fixes #1 * Used the following code snippet from Jetty as a reference: https://github.com/eclipse/jetty.project/blob/aa52d67dbf8b46f393988cbd3ee65a8172c8e380/jetty-runner/src/main/java/org/eclipse/jetty/runner/Runner.java#L362
1 parent 2663d9f commit 813721e

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

programmatic/src/main/java/dgroomes/wiremock/App.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
public class App {
1414

1515
private static final Logger log = LoggerFactory.getLogger(App.class);
16-
public static final int SLEEP_SECONDS = 1;
16+
public static final int SLEEP_SECONDS = 5;
1717

1818
public static void main(String[] args) throws InterruptedException {
1919
WireMockConfiguration options = WireMockUtil.shutdownGracefully(new WireMockConfiguration());

programmatic/src/main/java/dgroomes/wiremock/WireMockUtil.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import com.github.tomakehurst.wiremock.http.StubRequestHandler;
88
import com.github.tomakehurst.wiremock.jetty9.JettyHttpServerFactory;
99
import com.github.tomakehurst.wiremock.jetty94.Jetty94HttpServer;
10-
import org.eclipse.jetty.server.Handler;
10+
import org.eclipse.jetty.server.handler.HandlerCollection;
1111
import org.eclipse.jetty.server.handler.StatisticsHandler;
1212

1313
/**
@@ -37,8 +37,15 @@ public HttpServer buildHttpServer(Options options, AdminRequestHandler adminRequ
3737
return new Jetty94HttpServer(options, adminRequestHandler, stubRequestHandler) {
3838

3939
@Override
40-
protected Handler[] extensionHandlers() {
41-
return new Handler[]{new StatisticsHandler()};
40+
protected HandlerCollection createHandler(Options options, AdminRequestHandler adminRequestHandler, StubRequestHandler stubRequestHandler) {
41+
var handlers = super.createHandler(options, adminRequestHandler, stubRequestHandler);
42+
var statisticsHandler = new StatisticsHandler();
43+
statisticsHandler.setHandler(handlers);
44+
// Unfortunately, the statisticsHandler needs to be wrapped in a HandlerCollection because the
45+
// super method must return the type "HandlerCollection", but really the method can afford to
46+
// return the more generic type "Handler". So we must accommodate the unnecessarily specific
47+
// type signature.
48+
return new HandlerCollection(statisticsHandler);
4249
}
4350
};
4451
}

0 commit comments

Comments
 (0)