Hello! Is there a way to serve a default bodyfile ...
# help
h
Hello! Is there a way to serve a default bodyfile if the requested file does not exist? I saw Tom’s answer on stackoverflow, but that requires creating an extension. Is it still the only possible solution? I’m currently using wiremock-standalone-3.0.0
o
Just to double check, do you mean emulating a response when the file doesn't exist, or missing the configuration file on WireMock itself? In the prior case it can be done via request stubs and priorities, or just an inverting request filter
h
@Oleg Nenashev the prior. I’m basically pulling in a 9 digit string from the request body and finding the file which has the 9 digit string as its name. I have around 900 such files, so it’s kind of impossible to list all the file names and filter it out during request matching
I currently have a regex which ensures that a 9 digit number is present in the body. If I’m not wrong, the regex in the higher priority mapping will match, even if I have a lower priority mapping to return a default file.
o
Yup
h
So extension is the only way?
o
Or code-generating the configuration on startup
h
Oh interesting, any docs for this? Did you mean extending wiremock with my specifics and then packaging to run as stand-alone?
o
It is the one of the options, though you can easily achieve the same with the extension and bundling dependencies
h
Thanks but can you please elaborate on this “Or code-generating the configuration on startup”. Didn’t quite get what you meant
o
It can be done in Java code using extension or a startup wrapper code. You can also write a short script that would generate the stubs definition JSON that would return responses for existing files, and then add a lower-priority matcher for the remaining requests.
It's with work, but IMHO an extension would be preferable
h
Ah I see, I will be going ahead with extension. Thank you!