我正在尝试熟悉Spring的项目反应堆(https://projectreactor.io/),并构建了一个小型应用程序,通过SSL对另一个服务进行REST调用。我找不到任何方法来配置org.springframework.web.client.reactive.WebClient来通过SSL发出请求。似乎没有这方面的文件。我使用的是reactor-core 3.0.0.RC1和reactor-netty 0.5.0.M3以及SpringFramework5.0.0.M1。有人知道如何配置带有SSL支持的reactor-netty吗?
发布于 2016-08-16 09:52:25
更新2017-01-04:
在用https://github.com/spring-projects/spring-framework/commit/64bc0ca744781af2bf96412ced0f439fc98ee00d发布的Spring的5.0.0.M4版本中纠正了这一点。
原始答案:
我发现解决方案是创建一个尊重SSL的新ClientHttpConnector实现。
public class ReactorClientHttpsAwareConnector implements ClientHttpConnector {
@Override
public Mono<ClientHttpResponse> connect(HttpMethod method, URI uri,
Function<? super ClientHttpRequest, Mono<Void>> requestCallback) {
return reactor.ipc.netty.http.HttpClient.create()
.request(io.netty.handler.codec.http.HttpMethod.valueOf(method.name()),
uri.toString(),
httpClientRequest -> requestCallback
.apply(new ReactorClientHttpRequest(method, uri, httpClientRequest)))
.cast(HttpInbound.class)
.otherwise(HttpException.class, exc -> Mono.just(exc.getChannel()))
.map(ReactorClientHttpResponse::new);
}
}需要HttpClient.create()来使客户端了解SSL。
https://stackoverflow.com/questions/38958165
复制相似问题