Currently, I am using Wiremock 3.12 version.I am trying to load wiremock-state-extension from local folder to container folder.So, According to official documentation: https://github.com/wiremock/wiremock-state-extension?tab=readme-ov-file
I have tried whatever is mentioned and I am getting :
Exception in thread "main" java.util.ServiceConfigurationError: com.github.tomakehurst.wiremock.extension.ExtensionFactory: Provider org.wiremock.extensions.state.StandaloneStateExtension could not be instantiated
at java.base/java.util.ServiceLoader.fail(Unknown Source)
at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(Unknown Source)
at java.base/java.util.ServiceLoader$ProviderImpl.get(Unknown Source)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.base/java.util.ServiceLoader$ProviderSpliterator.tryAdvance(Unknown Source)
at java.base/java.util.Spliterator.forEachRemaining(Unknown Source)
at java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(Unknown Source)
at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Unknown Source)
at java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
at java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.base/java.util.stream.ReferencePipeline.collect(Unknown Source)
at com.github.tomakehurst.wiremock.extension.Extensions.load(Extensions.java:111)
at com.github.tomakehurst.wiremock.core.WireMockApp.<init>(WireMockApp.java:108)
at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:68)
at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.run(WireMockServerRunner.java:71)
at wiremock.Run.main(Run.java:23)
Caused by: java.lang.NoSuchMethodError: 'void com.github.tomakehurst.wiremock.extension.responsetemplating.TemplateEngine.<init>(java.util.Map, java.lang.Long, java.util.Set, boolean)'
at org.wiremock.extensions.state.StateExtension.<init>(StateExtension.java:60)
at org.wiremock.extensions.state.StandaloneStateExtension.<init>(StandaloneStateExtension.java:28)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
Here is my Docker file:
# Use the official WireMock image as base
FROM wiremock/wiremock:3x
# Copy mapping files into the correct directory inside the container
COPY mappings /home/wiremock/mappings
# Ensure the correct directory for extensions exists
RUN mkdir -p /var/wiremock/extensions
# Copy the WireMock State Extension JAR into the correct directory
COPY extensions/wiremock-state-extension-standalone-0.4.0.jar /var/wiremock/extensions/
# Set WireMock to load extensions and enable response templating
CMD ["--global-response-templating"]
Is it possible to use Wiremock extension with a Docker container?
There are a couple of things I would take a look at. The Docker image you are referencing is:
# Use the official WireMock image as base
FROM wiremock/wiremock:3x
On Docker Hub, this tag comes under the Deprecated and experimental tags
section. Although this shouldn't make a difference to the outcome, I would probably reference the latest
tag instead if you can.
The second thing is the version of the state extension you are using:
# Copy the WireMock State Extension JAR into the correct directory
COPY extensions/wiremock-state-extension-standalone-0.4.0.jar /var/wiremock/extensions/
0.4.0
is a very old version of the state extension and if you look at the compatibility matrix on the extension repository you can see that version is not compatible with the latest version of WireMock. Would try using the latest version of the extension (currently 0.8.2
) and I think that will solve your problem.
To check that it should all work I have added the latest state extension to my WireMock Docker example repo. The jar has been added to the extensions
directory here. That directory is then mapped in the volumes
section of the docker compose file here. When the container starts, you can see the extensions are loaded:
██ ██ ██ ██████ ███████ ███ ███ ██████ ██████ ██ ██
██ ██ ██ ██ ██ ██ ████ ████ ██ ██ ██ ██ ██
██ █ ██ ██ ██████ █████ ██ ████ ██ ██ ██ ██ █████
██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
███ ███ ██ ██ ██ ███████ ██ ██ ██████ ██████ ██ ██
----------------------------------------------------------------
| Cloud: https://wiremock.io/cloud |
| |
| Slack: https://slack.wiremock.org |
----------------------------------------------------------------
version: 3.12.0
port: 8080
enable-browser-proxying: false
disable-banner: false
no-request-journal: false
verbose: true
extensions: faker-helper,stateTransaction,state-matcher,state,recordState,deleteState,response-template,webhook