Issue
I'm trying to find examples of WebClient use.
My goal is to use Spring 5 WebClient to query a REST service using https and self signed certificate
Any example?
Solution
See example of use href="https://netty.io/4.0/api/io/netty/handler/ssl/util/InsecureTrustManagerFactory.html" rel="noreferrer">insecure TrustManagerFactory that trusts all X.509 certificates (including self-signed) without any verification. The important note from documentation:
Never use this TrustManagerFactory in production. It is purely for testing purposes, and thus it is very insecure.
@Bean
public WebClient createWebClient() throws SSLException {
SslContext sslContext = SslContextBuilder
.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.build();
ClientHttpConnector httpConnector = HttpClient.create().secure(t -> t.sslContext(sslContext) )
return WebClient.builder().clientConnector(httpConnector).build();
}
Answered By - Venelin
Answer Checked By - Katrina (JavaFixing Volunteer)