Description
On Wiremock 2.23.2.
When creating a standalone server, the WireMockApp constructor sets up stub mappings and passes in collections of ResponseDefinitionTransformer
s and StubLifecycleListener
s. These are created by asking the options class to get extensionsOfType
for the relevant class.
In the case of CommandLineOptions
this entails constructing an instance of these classes based on what was passed on the command line - whether that's an explicit extension class or the switches for global/local response templating.
Unfortunately, these two collections are built independently of each other. If you have an extension that implements both ResponseDefinitionTransformer
and StubLifecycleListener
, you will get two copies, one for each collection. For stateless extensions this isn't a big a deal, but if your extension has state - and especially if that state should be managed according to the stub lifecycle - this will not behave as expected. The built-in ResponseTemplateTransformer
, for example, has an internal cache that should be reset when stubs are reset or removed - and this will not be happening correctly in the Standalone version of wiremock because the instance that gets called for the stub lifecycle events is not the same instance that actually performs the response transformations.
I think the cleanest way to do this would be to have CommandLineOptions maintain an internal collection of extensions and check it when asked for extensions implementing an interface rather than constructing them on demand when asked for extensionsOfType