javaspringdockerwebhookswiremock

How to block a request using wiremock - Webhooks in a Docker container?


There is a problem, I ask for help, I need it.

(+) if this has already been done.

  1. Raise wiremock in a docker container. (+)
  2. Add an extension to it so that it can use not json but java classes with custom logic as mocks by downloading the jar from the documentation site and adding it to the extensions folder and adding the launch argument "--extensions org.wiremock.webhooks.Webhooks" (+)
  3. Write your own mock (+) but I wrote it but I’m not sure that it will work, according to the doc I understand it should be like this.
class WireMockStub: ResponseDefinitionTransformerV2 {

    override fun getName(): String {
        return "WireMockStub"
    }

    override fun transform(serveEvent: ServeEvent): ResponseDefinition {
        return if (serveEvent.request.url == "/api/webhook/test") {
            ResponseDefinitionBuilder
                .responseDefinition()
                .withStatus(200)
                .withBody("{\"testField\": true }")
                .build()
        } else {
            ResponseDefinition()
        }
    }
}

This is Kotlin but I think javiists will understand

  1. Build this class in a jar with meta information and so on (+)
  2. Put this jarnik either in the extensions package or in the mappings package, I still didn’t understand from the docs? there are 2 options, but I tried both, and both do not work (+)(-)
  3. Make a request to wiremock in Docker, so that it gives the mock (-) I make a request and depending on where I put the file and what launch settings I set, it either did not see the mock or does not start with an error.

The behavior is as follows. if you do this

WIREMOCK_OPTIONS: "-cp my_jarnik.jar:wiremock-webhooks-extension-3.4.0.jar --extensions org.wiremock.webhooks.Webhooks"

where the 2nd jarnik is an extension in the extension package for the mock classes to work, which I downloaded from the documentation site, and my jarnik with the extension is in the same package, then the wiremock does not start with the error mentioned above, but if you do this

WIREMOCK_OPTIONS: "--extensions org.wiremock.webhooks.Webhooks, ru.rubbles.gap.wiremock.webhook.WireMockStub"

The first argument in the dock is needed to enable the wiremock hook so that everything works, and the 2nd is my extension with the path to the class, I found this elsewhere in the documentation, then the wiremock rises but we don’t see the mock.

404 No response could be served as there are no stub mappings in this WireMock instance.

In general, both options do not work differently....


Solution

  • In the end, everything turned out to be simple, I compiled the required jar on JAVA_17, but it was necessary to compile on JAVA_11, if you compile on 17 it gives an error about version mismatch, and the error was not visible since the project was in Kotlin. As soon as I created a separate repository on JAVA_11, everything worked.