Search code examples
wiremockwiremock-standalone

Is it possible to mock two ports using Java version of Wiremock-standalone?


I have an app which fetches some data from a url on port 8085. processes the data, then sends it to another url on port 8080 for another process, then processes the response from port 8080 again. Is it possible to have either wiremock or wiremock standalone work on both these ports? I can't find any solution for this in the docs but it seems to me it should be possible somehow. I have created a json file to handle the two URLs but I can't figure out a way to handle two ports. Any solution would be highly appreciated.


Solution

  • My understanding is that this is possible, by having two separate WireMock servers running on the two ports. This can be done either through the java WireMock or standalone WireMock. You'll simply need to specify the port.

    java -jar wiremock-jre8-standalone-2.26.3.jar --port 8085 --rootdir /path/to/dir1
    
    java -jar wiremock-jre8-standalone-2.26.3.jar --port 8080 --rootdir /path/to/dir2
    

    The main thing to watch out for is that you'll need to have the servers looking to separate data folders. I've specified this in the CLI via the --rootdir flag. This can be set in java with .usingFilesUnderDirectory()

    The part I'm curious about is why you have to have the data sent to a separate port. Could you not accomplish the same workflow by processing the data, sending it to a different endpoint, and then re-processing the data?