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

WireMock 3 ResponseDefinitionTransformer FileSource#getPath returns empty string, breaking existing extension #2388

Closed
tpearsonbray opened this issue Sep 20, 2023 · 3 comments
Labels

Comments

@tpearsonbray
Copy link

tpearsonbray commented Sep 20, 2023

Proposal

Using WIreMock 3.0 the FileSource implementation provided to ResponseDefinitionTransformer is BlobStoreFileSource which returns an empty string for getPath.

Use case in WireMock 2

We manually proxy unmatched SOAP requests. When proxying a request we need to update the WSA:To value in the request body. We do this in a ResponseDefinitionTransformer which:

  1. Is triggered by a catch-all stub mapping
  2. Creates a modified request with an updated body
  3. Makes a request
  4. Stores a new stub mapping for the response

To do (4), we use the path from the FileSource to find the root directory containing __files and mappings, in order to save our new stub mapping JSON file to mappings

Issue in WireMock 3

In WireMock 3.0, we can access the root directory by constructing our extension through ExtensionFactory. However, wiremock-standalone doesn't load ExtensionFactory implementations. (It loads the --extensions parameter into ExtensionDeclarations as Extension class names)

We can load an ExtensionFactory via a service provider, but this means that the extension is always enabled.

Possible resolutions

To resolve this issue we need any of:

  • The WireMock 2 behaviour to be restored to getPath in ResponseDefinitionTransformer
  • ExtensionFactory support in wiremock-standalone
  • A mechanism for disabling SPI ExtensionFacctory loading in wiremock-standalone
  • A transformer interface which would allow us to transform a request body before proxying (using the built in proxy mechanism)

Reproduction steps

  1. ExtendResponseDefinitionTransformer and register it
  2. Access FileSource#getPath in ResponseDefinitionTransformer#transform

References

No response

@tomakehurst
Copy link
Member

I think #2396 fixes it, but would appreciate a review before I merge it.

@tpearsonbray
Copy link
Author

@tomakehurst Thanks, I've built #2396 locally and confirmed that it's returning the path as expected.

Following up on the use within wiremock-standalone - I presume that ResponseDefinitionTransformer will be removed in WireMock 4.0, is there a feature planned for loading extensions in wiremock-standalone via ExtensionFactory?

@tomakehurst
Copy link
Member

I think ResponseDefinitionTransformer will most likely be removed in 4.0, but it depends how quickly we get to it. The v2 version is quite similar so porting your extension shouldn't take more than an hour.

If you include a service definition file in your extension JAR for the factory class it'll be scanned and loaded automatically by standalone. That's the recommended way to do it.

tomakehurst added a commit that referenced this issue Sep 27, 2023
Fixed #2388 - empty getPath() returned from new FileStore implementation passed to transformers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

2 participants