3

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.

2
  • 1
    I guess you are using the Java version from WireMock? Commented Jul 9, 2020 at 8:25
  • @StefHeyenrath Yes. I am using the Java version of WireMock-standalone.
    – Mansour.M
    Commented Jul 9, 2020 at 18:17

1 Answer 1

2

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?

2
  • 1
    In production the servers are separate. In test, each server is a container on a separate port and they are on the same system. So what should be the data server is a data container and the authentication server is the authentication container. It is just how it has been designed and changing it is way too much work. I am using the java version of wiremock-standalone/ I have tried having two instances but not having two separate directories. I shall give it a try. Thanks!
    – Mansour.M
    Commented Jul 9, 2020 at 18:13
  • 2
    For whoever may need it, mocking two ports in the code is possible by creating two server objects. In this answer the servers are created using the jar file. In the code you create new instances of the server.
    – Mansour.M
    Commented Aug 17, 2020 at 15:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.