hi, I have been able to successfuly extend Respons...
# help
a
hi, I have been able to successfuly extend ResponseTransformerV2 to add an encrypted header to the response, but have been unable to extend a webhook to do a similar thing. Does anyone have a working example of an java extension class and the associated mapping showing how this is done?
l
I don't think we have a way to extend the webhook via an extension. I am wondering if this could be done via a
TemplateHelperProviderExtension
. The header values in webhooks are templatable so maybe you could write a template helper to provide the encrypted value you need ? https://wiremock.org/docs/extensibility/adding-template-helpers/
a
I've actually just managed to get my extension to be actioned by
Copy code
public class exampleExtension implements WebhookTransformer {

  @Override
  public WebhookDefinition transform(ServeEvent serveEvent, WebhookDefinition webhookDefinition) {
....
           String dataToHash = webhookDefinition.getBody();
....
      webhookDefinition.withHeader("cko-signature", hmac);
      return webhookDefinition;
}

}
the only problem now is that the webhookDefinition.getBody() returns the body before handlebar substitution, and I need it after the substitution has taken place
l
Nice, I hadn't seen that before. Just spotted the info at the bottom of the page - https://wiremock.org/docs/webhooks-and-callbacks/#extending-webhooks
I might be able to take a look later to see if there is any way around this
a
thanks ... I'll post back here if I solve it. All I need now is the webhookDefinition body after {{xxx}} substitution has occurred
been unable to get hold of the response post-substitution. However can use the serveEvent and do my own substitution in my extension ... not ideal, a bit messy, but should work! :-( however, when the mapping is declared with :
Copy code
"serveEventListeners" : [
  {
    "name" : "webhook",
    "parameters" : {
      "method" : "POST",
      "url" : "<http://mywebhook.url>",
      "headers" : {
        "Content-Type" : "application/json",
        "Authorization" : "complexAuthKey"
      },
      "body" : "{\"id\":\"blah\"}",
      "delay" : {
        "type" : "fixed",
        "milliseconds" : 2000
      },
      "transformers": ["A"]
    }
  }
if 'A' is set as the name of an extension of ResponseTransformerV2 it is ignored and 'B' is used (which is an extension of WebhookTransformer) despite 'B' not being listed in transformers I presume that is because there is no way of overriding applying it globally!