Skip to content

Commit a13ab72

Browse files
committed
Made HttpServerFactory an extension point
1 parent d2236f8 commit a13ab72

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

src/main/java/com/github/tomakehurst/wiremock/WireMockServer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ public WireMockServer(Options options) {
7171
wireMockApp = new WireMockApp(options, this);
7272

7373
this.stubRequestHandler = wireMockApp.buildStubRequestHandler();
74-
HttpServerFactory httpServerFactory = options.httpServerFactory();
74+
75+
HttpServerFactory httpServerFactory =
76+
wireMockApp.getExtensions().ofType(HttpServerFactory.class).values().stream()
77+
.findFirst()
78+
.orElse(options.httpServerFactory());
79+
7580
httpServer =
7681
httpServerFactory.buildHttpServer(
7782
options, wireMockApp.buildAdminRequestHandler(), stubRequestHandler);

src/main/java/com/github/tomakehurst/wiremock/core/WireMockApp.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,10 @@ public Options getOptions() {
483483
return options;
484484
}
485485

486+
public Extensions getExtensions() {
487+
return extensions;
488+
}
489+
486490
@Override
487491
public void shutdownServer() {
488492
stores.stop();

src/main/java/com/github/tomakehurst/wiremock/http/HttpServerFactory.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2014-2021 Thomas Akehurst
2+
* Copyright (C) 2014-2023 Thomas Akehurst
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,14 @@
1616
package com.github.tomakehurst.wiremock.http;
1717

1818
import com.github.tomakehurst.wiremock.core.Options;
19+
import com.github.tomakehurst.wiremock.extension.Extension;
1920

20-
public interface HttpServerFactory {
21+
public interface HttpServerFactory extends Extension {
22+
23+
@Override
24+
default String getName() {
25+
return "http-server-factory";
26+
}
2127

2228
HttpServer buildHttpServer(
2329
Options options,

src/main/java/com/github/tomakehurst/wiremock/jetty/JettyHttpServer.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ private ServletContextHandler addMockServiceContext(
334334
}
335335

336336
protected void decorateMockServiceContextBeforeConfig(ServletContextHandler mockServiceContext) {}
337+
337338
protected void decorateMockServiceContextAfterConfig(ServletContextHandler mockServiceContext) {}
338339

339340
private ServletContextHandler addAdminContext(
@@ -385,8 +386,11 @@ private ServletContextHandler addAdminContext(
385386
return adminContext;
386387
}
387388

388-
protected void decorateAdminServiceContextBeforeConfig(ServletContextHandler adminServiceContext) {}
389-
protected void decorateAdminServiceContextAfterConfig(ServletContextHandler adminServiceContext) {}
389+
protected void decorateAdminServiceContextBeforeConfig(
390+
ServletContextHandler adminServiceContext) {}
391+
392+
protected void decorateAdminServiceContextAfterConfig(
393+
ServletContextHandler adminServiceContext) {}
390394

391395
private void addCorsFilter(ServletContextHandler context) {
392396
context.addFilter(buildCorsFilter(), "/*", EnumSet.of(DispatcherType.REQUEST));

src/test/java/com/github/tomakehurst/wiremock/WireMockServerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void returnsOptionsWhenCallingGetOptions() {
6262

6363
@Test
6464
public void addFilenameTemplateAsOptionAndValidFormat() {
65-
Options options = options().filenameTemplate("{{{request.url}}}-{{{request.url}}}.json");
65+
Options options = options().dynamicPort().filenameTemplate("{{{request.url}}}-{{{request.url}}}.json");
6666
WireMockServer wireMockServer = new WireMockServer(options);
6767
wireMockServer.start();
6868
assertThat(wireMockServer.getOptions(), is(options));

0 commit comments

Comments
 (0)