Hi, I try to create a Wiremock stub which uses a ...
# wiremock-java
u
Hi, I try to create a Wiremock stub which uses a response body that originates from an InputStream. The InputStream will be generated on the fly by the tests and will be large - eventually up into the gigabyte range. However, I have not found a way to achieve this without actually buffering the whole thing. Looking at StubResponseRenderer#renderDirectly(ServeEvent serveEvent), I can see two possible sources for the response body: an InputStreamSource originating from filesBlobStore (which, as far as I see this, can only render files), and a ByteBody that needs the full byte array. I don't want to store the body as a file, and I don't want to buffer it as the full byte array. It would be nice if there'd be a way to define a response that originates in an arbitrary InputStream. I think what we need here is not just a response body definition specifying an InputStream directly, but rather something like an InputStream supplier, otherwise the stub would be a one-shot stub. Is there anything I missed? Preferably of course another way to achieve this without requiring lots of disk space or memory?
t
I can definitely see the utility in this and there may be a way to achieve it in the short term by creating a custom
BlobStore
implementation and returning it from
Stores.getFilesBlobStore()
👍 1
We’re going to re-work the model for bodies (request, response and webhook) in 4.0 so I’ll give some thought as to how we can support programmatic streams more simply.
u
(By now I have migrated those tests of mine that work with the huge bodies to a plain Jetty server instead of Wiremock, so it's not urgent for me anymore. However, the Jetty server of course misses the comfortable verify and request parameter/body evaluation that Wiremock allows)
t
Fair enough. Please shout if you do decide to attempt the BlobStore approach as I’d be interested to know how that goes.
u
I guess I won't be able to do that for now. I have looked into the code last week, however I got stuck a bit in the BlobStore code (just reading it, not hacking around my problem yet...)
t
Totally understand. Never enough time for these things.