https://linen.dev logo
#help
Title
# help
h

Hari Krishnan

09/14/2023, 6:55 AM
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

Oleg Nenashev

09/14/2023, 10:03 AM
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

Hari Krishnan

09/14/2023, 10:11 AM
@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

Oleg Nenashev

09/14/2023, 10:14 AM
Yup
h

Hari Krishnan

09/14/2023, 10:15 AM
So extension is the only way?
o

Oleg Nenashev

09/14/2023, 10:18 AM
Or code-generating the configuration on startup
h

Hari Krishnan

09/14/2023, 10:20 AM
Oh interesting, any docs for this? Did you mean extending wiremock with my specifics and then packaging to run as stand-alone?
o

Oleg Nenashev

09/14/2023, 10:57 AM
It is the one of the options, though you can easily achieve the same with the extension and bundling dependencies
h

Hari Krishnan

09/14/2023, 10:58 AM
Thanks but can you please elaborate on this “Or code-generating the configuration on startup”. Didn’t quite get what you meant
o

Oleg Nenashev

09/14/2023, 11:01 AM
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

Hari Krishnan

09/14/2023, 11:03 AM
Ah I see, I will be going ahead with extension. Thank you!