Claudio Waldvogel
04/30/2025, 9:58 PMpublic class WebhookSigningExtension implements WebhookTransformer {
@Override
public WebhookDefinition transform(ServeEvent serveEvent, WebhookDefinition webhookDefinition) {
System.out.println("WebhookSigningExtension: transform called");
return webhookDefinition;
}
@Override
public String getName() {
return "webhook-signer";
}
}
Code to test the transformer:
public class Main {
public static void main(String[] args) {
WireMockServer wireMockServer = new WireMockServer(
WireMockConfiguration.options().port(8080).extensions(new WebhookSigningExtension())
);
wireMockServer.start();
wireMockServer.stubFor(<http://WireMock.post|WireMock.post>(WireMock.urlPathEqualTo("/webhook"))
.willReturn(WireMock.ok())
.withServeEventListener("webhook", Webhooks.webhook()
.withMethod(<http://RequestMethod.POST|RequestMethod.POST>)
.withUrl("<http://localhost:9898/webhook/test>")
.withHeader("Content-Type", "application/json")
.withBody("{ \"result\": \"SUCCESS\" }"))
);
}
}
Do I have to implement the logic to enabled/disable the transformer by passing custom parameter?
Thanks in advance,
ClaudioTom
05/01/2025, 5:47 AMserveEvent.getStubMapping()
so you could put some conditional logic in there based on the ID/name/whatever from that.Andrew Paton
05/02/2025, 9:03 AMif (webhookDefinition.getOtherFields().get("transformers").toString().contains("my-extension-name")) {
blah
}
and adding this to the mapping
"transformers": ["my-extension-name"]
Claudio Waldvogel
05/05/2025, 7:21 AM