Hello. I've got a wiremock server runing via java ...
# help
b
Hello. I've got a wiremock server runing via java spring aplication in intellij. With some Transformers, and many (dozens) stubmappings in src/files/stub as .json files. Everything runs ok, but I would like, if posible, the log of runing wiremock returns some info about the file that originated the response to each request. Using a class that extends ResponseDefinitionTransformerV2 I am able to log the request, response, and even the uuid of the stub; but I would like to log the file.json that contains that stubmapping. I saw that JsonFileMappingsSource in loadMappingsInto method it loads all json files, asign each stubmap an uuid , and even store the file and uuid of the stub in a "StubMappingFileMetadata" I would like to access that StubMappingFileMetadata in a Transformer (or something like that, or in a EventListener). Or access the JsonFileMappingsSource in Transformer, via autowired maybe. Any idea would be apreciated. Sorry if question is silly or confusing. Thanks in advance
t
If you’re looking just to log things (without modifying them) then generally a
ServeEventListener
is the best way to go. Having said that, in either extension type you have access to a response definition, which has a
bodyFilePath
attribute. Is this not giving you what you need?
🙏 1
b
Hello. In the serveEevent there is a responseDefinition, that includes a Bodyfilename, but that is filled only if the json with the map(s) points to antoher file. In my cases, normally the json contains the request and the response json. I have just done a workaroun, althought it may not be perfect: I wrote a ResponseTransformer (probably a ServeEventlistener would also work). The ServeEvent contains some info I log. But also, I added it via autowired a WireMockServer reference. Using Reflection -because they are all private fields-, I acces inside the wiremockserver, the WiremockApp. Inside it, the JsonFileMappinsSource. And with that, I recover a Map<UUID, fileNameEntry> and finally the String Path. To fix circular dependency I had to add to spring some configuration line "...allow=true" It works. Any other ideas welcome. Thanks all !