:wave: Hello, team! My name is Kamil Rozbicki and...
# help
k
👋 Hello, team! My name is Kamil Rozbicki and I work for Mastercard in Dublin, Ireland. Oleg Nenashev has pointed me to this group as I was trying to get some advise from him on a challenge I have with the Wiremock. While trying to find a solution to a challenge I have, I stumbled upon one of the applications Maciej Walkowiak wrote: https://github.com/maciejwalkowiak/wiremock-spring-boot He confirmed my impression this would be strictly for @SpringBootTest and would not help with what I want to achieve. In my team in Mastercard, we are making heavy use of various Microservice API mocks that use Wiremock under the hood. We deploy them to Pivotal Cloud Foundry, as SpringBoot apps, in order to facilitate execution of post-deployment tests on our new microservices, without the need of having their dependant services in place, in the development environment. (Of course, we later integrate these services and do test them together as well). A while ago, it's become a requirement for us to use mutual-TLS security between our apps, based on server/client policies. This is all proprietary libraries, so won't go much into details. Long story short: I need to make Wiremock work inside a SpringBoot application, preferably sharing same TCP port (8080). I've used this idea (1st answer): https://stackoverflow.com/questions/58273451/run-wiremock-server-as-a-springboot-application However, this solution requires disabling Web Application (seting it to 'none'), but this in turn disables our security libraries performing policy-based authorization. Without setting this option to 'none', I can only make the application to run on 2 separate ports, for example: 8080 for SpringBoot and 8081 for Wiremock, or have 'port in use' exception thrown by Spring Boot on the startup, when I set bot to use same port. Can you think of any other way to make a Wiremock instance, with all its great functionalities, work inside SpringBoot application, on same port? Thank you again for your time. Any help welcomed.
t
Hi @Kamil Rozbicki have you tried using the Spring framework’s own WireMock integration? https://cloud.spring.io/spring-cloud-static/spring-cloud-contract/1.1.4.RELEASE/multi/multi__spring_cloud_contract_wiremock.html This I believe will use the same web container as Spring for WireMock rather than starting a separate one.
k
Hi @Tom Thank you for pointing me to this direction - will give it a go and message here afterwards.
Hi @Tom Sorry for long time it took me to actually try solution you rcommended. I could not get it to work, and from the context of this document it seems its more about @SpringBootTest, not the @SpringBootApplication On the examples I see WebEnvironment.NONE being used, which I cannot do - still need Spring Boot Web (on post 8080) and Wiremock, on same port (8080). Is this possible? I'm starting to consider adding some programmatic solution for TCP port forwarding proxy, but not sure if it will work, until I try. But know already it would not be pretty. Any help welcomed. Thank you for all your time ;)
t
I’m pretty sure there’s a way to get WireMock to share the same web container as Spring, but I’m not an expert on this module as it’s maintained by the Spring Cloud team. Might be worth jumping on their one of their support channels and asking if you can’t find the solution in the docs.
k
Thank you, @Tom - I'll scratch it a little more, and if still no luck, will reach-out to Spring Cloud team. Thanks again for your time.
Hi @Tom Just an FYI, I managed to workaround this issue in an alternative way. Instead of still 'fighting' with SringBoot and trying to make it work on same TCP port as Wiremock, I upgraded Wiremock to version 3.0.1 and utilized one of it's interceptors: StubRequestFilter by implementing my own authentication/authorisation mechanism within it. So now, based on on presence and content of Athorozation header on the received request, I can either do RequestFilterAction.continueWith(request) when all looks good, or serve Unauthorised response with RequestFilterAction.stopWith(generateUnauthorisedResponse()) Thank you again for all your time ;)
t
Great, glad you managed to find a solution! BTW, I would definitely suggest upgrading to 3.3.1. Lots of bug fixes and improvements since 3.0.1.
k
Thank you, will do. Used 'com.github.tomakehurst : wiremock-jre8-standalone : 3.0.1', but will move to 'org.wiremock : wiremock : 3.3.1'. Thanks again and have a nice day!
👍 1