【发布时间】:2019-09-01 02:54:06
【问题描述】:
我一直使用 RestTemplate 并决定切换到 WebClient。
在发送请求之前,我使用私钥签署请求正文,客户端使用公钥检查请求。
我的拦截器:
private static class SignatureClientHttpRequestInterceptor implements ClientHttpRequestInterceptor {
private final PrivateKey privateKey;
private SignatureClientHttpRequestInterceptor(String privateKeyLocation) {
this.privateKey = PemUtils.getPrivateKey(Paths.get(privateKeyLocation));
}
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
if (request.getMethod() == HttpMethod.POST) {
request.getHeaders().add("X-Signature", Base64.getEncoder().encodeToString(PemUtils.signData(privateKey, SignatureAlgorithm.RS256.getJcaName(), body)));
}
return execution.execute(request, body);
}
}
但在 WebClient,我没有在 ExchangeFilterFunction 中找到这样的机会。
有没有办法在 WebClient 中执行此操作,还是我必须在发送之前手动签署请求正文?
【问题讨论】:
-
嘿,伙计@Peter。面临类似情况。你可以在哪里工作?如果是这样,请分享
-
@Enoobong 不幸的是,我无法解决它
标签: java spring spring-webflux