Olá pessoal estou consumindo uma api externa com Webflux e em alguns momentos recebo algumas exceções abaixo:
WebClientRequestException : General SSLEngine problem; nested exception is javax.net.ssl.SSLHandshakeException: General SSLEngine problem
SSLHandshakeException : The connection observed an error javax.net.ssl.SSLHandshakeException: General SSLEngine problem
Criei o webclient desta forma:
@Bean
public WebClient createWebClient2() {
return WebClient.builder()
.baseUrl("https://myapiconsume")
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.build();
}
e faço a chamada assim:
this.webClientConfiguration
.createWebClient2()
.post()
.uri(uri)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, "Basic "+basicAuthHeader)
.header(HttpHeaders.CACHE_CONTROL, "no-cache")
.body(Mono.just(request),SmsRequestHeaderDto.class)
.retrieve()
.bodyToMono(SmsResponseHeaderDto.class)
.block();
para tentar evitar este problema tentei criar o webclient conforme abaixo mas ainda recebo estas exceções
@Bean
public WebClient createWebClient2() {
HttpClient httpClient = HttpClient.create().secure(spec ->
{
try {
spec.sslContext(SslContextBuilder.forClient().build());
} catch (SSLException e) {
log.error("Erro em sslContext "+e.getMessage()+"\n");
e.printStackTrace();
}
});
//https://github.com/reactor/reactor-netty/issues/1774
ConnectionProvider provider = ConnectionProvider.builder("fixed")
.maxConnections(500)
.maxIdleTime(Duration.ofSeconds(20))
.maxLifeTime(Duration.ofSeconds(60))
.pendingAcquireTimeout(Duration.ofSeconds(60))
.evictInBackground(Duration.ofSeconds(120)).build();
return WebClient
.builder()
.clientConnector(new ReactorClientHttpConnector(httpClient.create(provider)))
.baseUrl("https://myapiconsume")
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.build();
}
Exsite alguma forma de contornar isso usando o webclient?