mrpeachum
mrpeachum

Reputation: 11

How do I configure reactor-netty to use SSL?

I am trying to get familiar with Spring's Project Reactor (https://projectreactor.io/) and have built a small application to make REST calls to another service over SSL. I cannot find any way to configure the org.springframework.web.client.reactive.WebClient to make requests over SSL. There seems to be no documentation about this. I am using reactor-core 3.0.0.RC1 and reactor-netty 0.5.0.M3, and Spring Framework 5.0.0.M1. Does anyone know how to configure reactor-netty with SSL support?

Upvotes: 0

Views: 2199

Answers (1)

mrpeachum
mrpeachum

Reputation: 11

Update 2017-01-04:

This was corrected in the 5.0.0.M4 release of Spring Framework with this patch.

Original Answer:

I discovered that the solution is to create a new ClientHttpConnector implementation that respects SSL.

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() is required to make the client SSL-aware.

Upvotes: 1

Related Questions