X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=enrichment-coordinator-service%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fenrichment%2Fclients%2FAsyncRestClient.java;h=1b8e0643b297c2bb76cfe491ea7f1e2fcbfe8cc9;hb=01b64b350211e0bfc16af343402dedc55020917b;hp=f0f6c4b1c4fae8d3add614b64963d919e34834e4;hpb=e1eebe59d712b5439b2813d69944a870be1e93ad;p=nonrtric.git diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/AsyncRestClient.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/AsyncRestClient.java index f0f6c4b1..1b8e0643 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/AsyncRestClient.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/AsyncRestClient.java @@ -42,9 +42,7 @@ import org.springframework.web.reactive.function.client.WebClientResponseExcepti import reactor.core.publisher.Mono; import reactor.netty.http.client.HttpClient; -import reactor.netty.resources.ConnectionProvider; -import reactor.netty.tcp.ProxyProvider.Proxy; -import reactor.netty.tcp.TcpClient; +import reactor.netty.transport.ProxyProvider; /** * Generic reactive REST client. @@ -200,32 +198,32 @@ public class AsyncRestClient { && !httpProxyConfig.httpProxyHost().isEmpty(); } - private TcpClient createTcpClient() { - TcpClient client = TcpClient.create(ConnectionProvider.newConnection()) // + private HttpClient buildHttpClient() { + HttpClient httpClient = HttpClient.create() // .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10_000) // .doOnConnected(connection -> { connection.addHandlerLast(new ReadTimeoutHandler(30)); connection.addHandlerLast(new WriteTimeoutHandler(30)); }); + if (this.sslContext != null) { - client = client.secure(c -> c.sslContext(sslContext)); + httpClient = httpClient.secure(ssl -> ssl.sslContext(sslContext)); } + if (isHttpProxyConfigured()) { - client = client.proxy(proxy -> proxy.type(Proxy.HTTP).host(httpProxyConfig.httpProxyHost()) - .port(httpProxyConfig.httpProxyPort())); + httpClient = httpClient.proxy(proxy -> proxy.type(ProxyProvider.Proxy.HTTP) + .host(httpProxyConfig.httpProxyHost()).port(httpProxyConfig.httpProxyPort())); } - return client; + return httpClient; } - private WebClient createWebClient(String baseUrl, TcpClient tcpClient) { - HttpClient httpClient = HttpClient.from(tcpClient); - - ReactorClientHttpConnector connector = new ReactorClientHttpConnector(httpClient); + private WebClient buildWebClient(String baseUrl) { + final HttpClient httpClient = buildHttpClient(); ExchangeStrategies exchangeStrategies = ExchangeStrategies.builder() // .codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(-1)) // .build(); return WebClient.builder() // - .clientConnector(connector) // + .clientConnector(new ReactorClientHttpConnector(httpClient)) // .baseUrl(baseUrl) // .exchangeStrategies(exchangeStrategies) // .build(); @@ -233,15 +231,9 @@ public class AsyncRestClient { private Mono getWebClient() { if (this.webClient == null) { - try { - TcpClient tcpClient = createTcpClient(); - this.webClient = createWebClient(this.baseUrl, tcpClient); - } catch (Exception e) { - logger.error("Could not create WebClient {}", e.getMessage()); - return Mono.error(e); - } + this.webClient = buildWebClient(baseUrl); } - return Mono.just(this.webClient); + return Mono.just(buildWebClient(baseUrl)); } }