2

I am trying to setup wiremock under an application path.

I have wiremock dockerized and running under some path https://local.wiremock/ and that works fine, so I can access the admin like this https://local.wiremock/__admin/docs

However when I deploy to aws it needs to be under a path like this: https://aws-server.wiremock/simulator/__admin/docs

And the addition of the application path /simulator breaks everything.

So I want to set it up locally so that it runs under: https://local.wiremock/simulator/__admin/docs

I have been going through documentation and there's nothing there for standalone server configuration. There is a mappedUnder xml field that could be useful but it cannot be set via docker.

Any ideas how to achieve that?

Nick
  • 2,877
  • 2
  • 33
  • 62

1 Answers1

0

I think you could do this by adding a Request Wrapper. The idea behind the Request Wrapper is that it intercepts the request and allows you to modify it before sending the request on. I think your solution would look something like...

public static class removeSimulatorPath extends StubRequestFilter {

    @Override
    public RequestFilterAction filter(Request request) {
        Request wrappedRequest = RequestWrapper.create()
                // lambda to replace the current URL with one without `/simulator`
                .transformAbsoluteUrl(url -> url.replace("/simulator", "")
                .wrap(request);

        return RequestFilterAction.continueWith(wrappedRequest);
    }

    @Override
    public String getName() {
        return "remove-simulator-path";
    }
}
agoff
  • 5,818
  • 1
  • 7
  • 20
  • what if you have an image with wiremock? this is weird from their side not allowing for such a config – Eugene Apr 12 '22 at 14:34
  • I don't understand your question. – agoff Apr 12 '22 at 14:39
  • suppose you download and use a [docker image](https://hub.docker.com/r/wiremock/wiremock) of wiremock, you can't edit the code. I was expecting for an environment variable to be available to be used in such cases - to allow starting the wiremock server on a different context path. – Eugene Apr 12 '22 at 14:43
  • I haven't used WireMock with a docker image, but there is information in the link you listed about registering extensions, and RequestFilters are extensions. If you're struggling to find your answers, I'd recommend asking a separate question, as this question is ~2 years old and is completely separate from the issue you're experiencing. – agoff Apr 12 '22 at 15:00