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

feat: WireMock 3.10.0 #601

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
64 changes: 64 additions & 0 deletions .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Publish Snapshots

on:
push:
branches: [ master ]

jobs:
publish-core-snapshot:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v3

- uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'

- uses: gradle/actions/setup-gradle@v3
with:
validate-wrappers: true

- name: Set snapshot version
run: ./gradlew set-snapshot-version --stacktrace

- name: Publish core package
id: publish_package
run: ./gradlew :publishMavenJavaPublicationToGitHubPackagesRepository --stacktrace

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish-jetty12-snapshot:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v3

- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- uses: gradle/actions/setup-gradle@v3
with:
validate-wrappers: true

- name: Set snapshot version
run: ./gradlew set-snapshot-version --stacktrace

- name: Publish Jetty 12 package
id: publish_package
run: ./gradlew :wiremock-jetty12:publishMavenJavaPublicationToGitHubPackagesRepository --stacktrace

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22
39 changes: 20 additions & 19 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ plugins {
id 'project-report'
id 'com.diffplug.spotless' version '6.25.0'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id "org.sonarqube" version "5.0.0.4638"
id "org.sonarqube" version "6.0.1.5171"
id 'jacoco'
id "me.champeau.jmh" version "0.7.2"
id 'com.dorongold.task-tree' version '4.0.0'
Expand All @@ -34,12 +34,12 @@ group = 'org.wiremock'
project.ext {
versions = [
handlebars : '4.3.1',
jetty : '11.0.20',
guava : '33.2.1-jre',
jackson : '2.17.2',
jetty : '11.0.24',
guava : '33.3.1-jre',
jackson : '2.18.2',
xmlUnit : '2.10.0',
jsonUnit : '2.40.0',
junitJupiter : '5.10.3'
jsonUnit : '2.40.1',
junitJupiter : '5.11.3'
]
}

Expand Down Expand Up @@ -76,7 +76,7 @@ dependencies {
"com.fasterxml.jackson.core:jackson-annotations",
"com.fasterxml.jackson.core:jackson-databind",
"com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
api "org.apache.httpcomponents.client5:httpclient5:5.3.1"
api "org.apache.httpcomponents.client5:httpclient5:5.4.1"
api "org.xmlunit:xmlunit-core:$versions.xmlUnit"
api "org.xmlunit:xmlunit-legacy:$versions.xmlUnit", {
exclude group: 'junit', module: 'junit'
Expand Down Expand Up @@ -108,26 +108,26 @@ dependencies {

api 'commons-fileupload:commons-fileupload:1.5'

api 'com.networknt:json-schema-validator:1.5.0'
api 'com.networknt:json-schema-validator:1.5.4'

testFixturesApi("org.junit.jupiter:junit-jupiter:$versions.junitJupiter")
testFixturesApi("org.junit.platform:junit-platform-testkit")
testFixturesApi("org.junit.platform:junit-platform-launcher")
testFixturesApi("org.junit.jupiter:junit-jupiter-params")
testFixturesApi('org.junit-pioneer:junit-pioneer:2.2.0')
testFixturesApi "org.hamcrest:hamcrest-core:2.2"
testFixturesApi "org.hamcrest:hamcrest-library:2.2"
testFixturesApi 'org.mockito:mockito-core:5.12.0'
testFixturesApi 'org.mockito:mockito-junit-jupiter:5.12.0'
testFixturesApi('org.junit-pioneer:junit-pioneer:2.3.0')
testFixturesApi "org.hamcrest:hamcrest-core:3.0"
testFixturesApi "org.hamcrest:hamcrest-library:3.0"
testFixturesApi 'org.mockito:mockito-core:5.14.2'
testFixturesApi 'org.mockito:mockito-junit-jupiter:5.14.2'
testFixturesApi "net.javacrumbs.json-unit:json-unit:$versions.jsonUnit"
testFixturesApi "org.skyscreamer:jsonassert:1.5.1"
testFixturesApi 'com.toomuchcoding.jsonassert:jsonassert:0.8.0'
testFixturesApi 'org.awaitility:awaitility:4.2.1'
testFixturesApi "commons-io:commons-io:2.16.1"
testFixturesApi 'org.awaitility:awaitility:4.2.2'
testFixturesApi "commons-io:commons-io:2.18.0"

testImplementation "junit:junit:4.13.2"
testRuntimeOnly("org.junit.vintage:junit-vintage-engine")
testImplementation 'org.scala-lang:scala-library:2.13.14'
testImplementation 'org.scala-lang:scala-library:2.13.15'
testImplementation 'com.tngtech.archunit:archunit-junit5:0.23.1'

testImplementation "org.eclipse.jetty:jetty-client"
Expand Down Expand Up @@ -167,7 +167,7 @@ allprojects {
}
json {
target 'src/**/*.json'
targetExclude '**/tmp*.json', 'src/test/resources/sample.json', 'src/main/resources/swagger/*.json', 'src/test/resources/filesource/subdir/deepfile.json', 'src/test/resources/schema-validation/*.json', 'src/test/resources/test-file-root/mappings/testjsonmapping.json'
targetExclude '**/tmp*.json', 'src/test/resources/sample.json', 'src/main/resources/swagger/*.json', 'src/test/resources/filesource/subdir/deepfile.json', 'src/test/resources/schema-validation/*.json', 'src/test/resources/test-file-root/mappings/testjsonmapping.json', 'src/main/resources/assets/swagger-ui/swagger-ui-dist/package.json'
simple().indentWithSpaces(2)
}
}
Expand All @@ -180,7 +180,7 @@ allprojects {
ext {
runningOnCI = System.getenv('CI') == 'true'

repoUser = this.hasProperty('sonatypeUser') ? sonatypeUser : 'default'
repoUser = this.hasProperty('sonatypeUser') ? sonatypeUser : 'default'
repoPassword = this.hasProperty('sonatypePassword') ? sonatypePassword : 'default'

pomInfo = {
Expand Down Expand Up @@ -338,6 +338,7 @@ shadowJar {
exclude 'META-INF/maven/**'
exclude 'META-INF/versions/17/**'
exclude 'META-INF/versions/21/**'
exclude 'META-INF/versions/22/**'
exclude 'module-info.class'
exclude 'handlebars-*.js'
}
Expand Down Expand Up @@ -560,7 +561,7 @@ tasks.withType(JavaCompile) {

eclipse.classpath.file {
whenMerged {
entries.find { it.path ==~ '.*JRE_CONTAINER.*' }.each {
entries.find{ it.path ==~ '.*JRE_CONTAINER.*' }.each {
it.entryAttributes['module'] = true
it.entryAttributes['add-exports'] = 'java.base/sun.security.x509=ALL-UNNAMED'
}
Expand Down
40 changes: 10 additions & 30 deletions src/main/java/com/github/tomakehurst/wiremock/WireMockServer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2011-2024 Thomas Akehurst
* Copyright (C) 2011-2025 Thomas Akehurst
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,12 +28,8 @@
import com.github.tomakehurst.wiremock.core.Container;
import com.github.tomakehurst.wiremock.core.Options;
import com.github.tomakehurst.wiremock.core.WireMockApp;
import com.github.tomakehurst.wiremock.extension.Extension;
import com.github.tomakehurst.wiremock.global.GlobalSettings;
import com.github.tomakehurst.wiremock.http.HttpServer;
import com.github.tomakehurst.wiremock.http.HttpServerFactory;
import com.github.tomakehurst.wiremock.http.RequestListener;
import com.github.tomakehurst.wiremock.http.StubRequestHandler;
import com.github.tomakehurst.wiremock.http.*;
import com.github.tomakehurst.wiremock.junit.Stubbing;
import com.github.tomakehurst.wiremock.matching.RequestPattern;
import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder;
Expand All @@ -50,10 +46,8 @@
import com.github.tomakehurst.wiremock.stubbing.StubMappingJsonRecorder;
import com.github.tomakehurst.wiremock.verification.*;
import java.util.List;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.UUID;
import org.eclipse.jetty.util.Jetty;

public class WireMockServer implements Container, Stubbing, Admin {

Expand Down Expand Up @@ -81,32 +75,18 @@ public WireMockServer(Options options) {
httpServerFactory.buildHttpServer(
options, wireMockApp.buildAdminRequestHandler(), stubRequestHandler);

notifier.info("Using HTTP server impl: " + httpServer.getClass().getSimpleName());

client = new WireMock(wireMockApp);
}

private HttpServerFactory getHttpServerFactory() {
if (!options.isExtensionScanningEnabled() && !isJetty11()) {
return ServiceLoader.load(Extension.class).stream()
.filter(extension -> HttpServerFactory.class.isAssignableFrom(extension.type()))
.findFirst()
.map(e -> (HttpServerFactory) e.get())
.orElseThrow(
() ->
new FatalStartupException(
"Jetty 11 is not present and no suitable HttpServerFactory extension was found. Please ensure that the classpath includes a WireMock extension that provides an HttpServerFactory implementation. See http://wiremock.org/docs/extending-wiremock/ for more information."));
}

return wireMockApp.getExtensions().ofType(HttpServerFactory.class).values().stream()
.findFirst()
.orElseGet(options::httpServerFactory);
}

private static boolean isJetty11() {
try {
return Jetty.VERSION.startsWith("11");
} catch (Throwable e) {
return false;
}
return new HttpServerFactoryLoader(
options,
wireMockApp.getExtensions(),
HttpServerFactoryLoader.systemServiceLoader(),
HttpServerFactoryLoader.isJetty11())
.load();
}

public WireMockServer(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2024 Thomas Akehurst
* Copyright (C) 2013-2025 Thomas Akehurst
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -103,6 +103,8 @@ enum ChunkedEncodingPolicy {

HttpServerFactory httpServerFactory();

boolean hasDefaultHttpServerFactory();

HttpClientFactory httpClientFactory();

ThreadPoolFactory threadPoolFactory();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2012-2024 Thomas Akehurst
* Copyright (C) 2012-2025 Thomas Akehurst
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -292,9 +292,8 @@ private List<RequestFilterV2> getV2StubRequestFilters() {

private void loadDefaultMappings() {
loadMappingsUsing(defaultMappingsLoader);
if (mappingsLoaderExtensions != null) {
if (mappingsLoaderExtensions != null)
mappingsLoaderExtensions.values().forEach(e -> loadMappingsUsing(e));
}
}

public void loadMappingsUsing(final MappingsLoader mappingsLoader) {
Expand Down Expand Up @@ -604,21 +603,21 @@ public SnapshotRecordResult snapshotRecord(RecordSpec recordSpec) {
}

@Override
public void startRecording(final String targetBaseUrl) {
public void startRecording(String targetBaseUrl) {
recorder.startRecording(RecordSpec.forBaseUrl(targetBaseUrl));

WebSocketEndpoint.broadcast(Message.RECORDING);
}

@Override
public void startRecording(final RecordSpec recordSpec) {
public void startRecording(RecordSpec recordSpec) {
recorder.startRecording(recordSpec);

WebSocketEndpoint.broadcast(Message.RECORDING);
}

@Override
public void startRecording(final RecordSpecBuilder recordSpec) {
public void startRecording(RecordSpecBuilder recordSpec) {
recorder.startRecording(recordSpec.build());

WebSocketEndpoint.broadcast(Message.RECORDING);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2024 Thomas Akehurst
* Copyright (C) 2013-2025 Thomas Akehurst
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,7 +41,6 @@
import com.github.tomakehurst.wiremock.http.trafficlistener.DoNothingWiremockNetworkTrafficListener;
import com.github.tomakehurst.wiremock.http.trafficlistener.WiremockNetworkTrafficListener;
import com.github.tomakehurst.wiremock.jetty.JettyHttpServerFactory;
import com.github.tomakehurst.wiremock.jetty.QueuedThreadPoolFactory;
import com.github.tomakehurst.wiremock.security.Authenticator;
import com.github.tomakehurst.wiremock.security.BasicAuthenticator;
import com.github.tomakehurst.wiremock.security.NoAuthenticator;
Expand Down Expand Up @@ -105,7 +104,7 @@ public class WireMockConfiguration implements Options {
private String proxyHostHeader;
private HttpServerFactory httpServerFactory = new JettyHttpServerFactory();
private HttpClientFactory httpClientFactory = new ApacheHttpClientFactory();
private ThreadPoolFactory threadPoolFactory = new QueuedThreadPoolFactory();
private ThreadPoolFactory threadPoolFactory;
private Integer jettyAcceptors;
private Integer jettyAcceptQueueSize;
private Integer jettyHeaderBufferSize;
Expand Down Expand Up @@ -428,6 +427,10 @@ public WireMockConfiguration extensions(Extension... extensionInstances) {
return this;
}

public WireMockConfiguration extensionFactories(ExtensionFactory... extensionFactories) {
return extensions(extensionFactories);
}

public WireMockConfiguration extensions(ExtensionFactory... extensionFactories) {
extensions.add(extensionFactories);
return this;
Expand All @@ -438,6 +441,12 @@ public WireMockConfiguration extensions(Class<? extends Extension>... classes) {
return this;
}

public WireMockConfiguration extensionFactories(
Class<? extends ExtensionFactory>... factoryClasses) {
extensions.addFactories(factoryClasses);
return this;
}

public WireMockConfiguration extensionScanningEnabled(boolean enabled) {
this.extensionScanningEnabled = enabled;
return this;
Expand Down Expand Up @@ -715,6 +724,11 @@ public HttpServerFactory httpServerFactory() {
return httpServerFactory;
}

@Override
public boolean hasDefaultHttpServerFactory() {
return httpServerFactory.getClass().equals(JettyHttpServerFactory.class);
}

@Override
public HttpClientFactory httpClientFactory() {
return httpClientFactory;
Expand Down
Loading
Loading