In my Spring Boot application, I was using RestTemplate
to call a WS for which the body HMAC signature should be provided as HTTP header. To do this I was using a ClientHttpRequestInterceptor
. Basically, I did:
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
try {
String hmac = Hmac.calculateRFC2104HMAC(body, key);
request.getHeaders().add("X-Hub-Signature", "sha1=" + hmac);
return execution.execute(request, body);
}
catch (NoSuchAlgorithmException | InvalidKeyException e) {
throw new IOException(e);
}
}
Now I want to use WebClient
for a better integration in my reactive application. But I'm lost in this new reactive API. How can I achieve this using ExchangeFilterFunction
or BodyInserter
? The difficulty is to retrieve the body, to perform the signature computation and to update the request consequently.
Thank you for your support.