summaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/main/java
diff options
context:
space:
mode:
authorPatrikBuhr <patrik.buhr@est.tech>2021-08-09 10:20:55 +0200
committerPatrikBuhr <patrik.buhr@est.tech>2021-08-18 10:01:22 +0200
commite7f0355378e636261ad960626d2eb92f317b3f16 (patch)
tree086163ee6b8e975d584f2b1341da6a9498dd82d5 /a1-policy-management/src/main/java
parentf8d4f42ed21463a636b8217b9882b90b4c3468a3 (diff)
Update springboot version of the Policy Management Service (version 2.5)
This required some changes due to not backwards compatible changes. - The API to springboot WebClient is changed, which is wrapped in class AsyncRestClient. - The validation of trusted certs is made more strict. The Owner field of the peer cert must contain the name ofthe using host. The uniitest tests this, so the cert in config is updated (Owner is "localhost"). Change-Id: Ia954b0ee5942884cd4b9fd82769bc8089dc35c53 Issue-ID: CCSDK-3421 Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Diffstat (limited to 'a1-policy-management/src/main/java')
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClient.java36
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClientFactory.java3
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1Client.java2
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion1.java2
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java2
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/Consts.java2
6 files changed, 19 insertions, 28 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClient.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClient.java
index 2b8c4fa6..ad2e221f 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClient.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/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<WebClient> 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));
}
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClientFactory.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClientFactory.java
index db3834a9..cde6647a 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClientFactory.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClientFactory.java
@@ -72,7 +72,7 @@ public class AsyncRestClientFactory {
return createRestClient(baseUrl, false);
}
- public AsyncRestClient createRestClient(String baseUrl) {
+ public AsyncRestClient createRestClientUseHttpProxy(String baseUrl) {
return createRestClient(baseUrl, true);
}
@@ -190,5 +190,4 @@ public class AsyncRestClientFactory {
}
}
-
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1Client.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1Client.java
index 7ded8ac9..78a418ab 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1Client.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1Client.java
@@ -120,7 +120,7 @@ public class OscA1Client implements A1Client {
private final UriBuilder uri;
public OscA1Client(RicConfig ricConfig, AsyncRestClientFactory restClientFactory) {
- this(ricConfig, restClientFactory.createRestClient(""));
+ this(ricConfig, restClientFactory.createRestClientUseHttpProxy(""));
}
public OscA1Client(RicConfig ricConfig, AsyncRestClient restClient) {
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion1.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion1.java
index 130f5500..b158ad25 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion1.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion1.java
@@ -97,7 +97,7 @@ public class StdA1ClientVersion1 implements A1Client {
private final UriBuilder uri;
public StdA1ClientVersion1(RicConfig ricConfig, AsyncRestClientFactory restClientFactory) {
- this(restClientFactory.createRestClient(""), ricConfig);
+ this(restClientFactory.createRestClientUseHttpProxy(""), ricConfig);
}
public StdA1ClientVersion1(AsyncRestClient restClient, RicConfig ricConfig) {
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java
index d79b2e72..d0f4da28 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java
@@ -124,7 +124,7 @@ public class StdA1ClientVersion2 implements A1Client {
private final OranV2UriBuilder uriBuiler;
public StdA1ClientVersion2(RicConfig ricConfig, AsyncRestClientFactory restClientFactory) {
- this(ricConfig, restClientFactory.createRestClient(""));
+ this(ricConfig, restClientFactory.createRestClientUseHttpProxy(""));
}
public StdA1ClientVersion2(RicConfig ricConfig, AsyncRestClient restClient) {
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/Consts.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/Consts.java
index c3eff84a..3e6bda72 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/Consts.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/Consts.java
@@ -28,7 +28,7 @@ public class Consts {
public static final String TRANSIENT_PARAM = "transient";
public static final String MANAGED_ELEMENT_ID_PARAM = "managed_element_id";
- public static final String V2_API_ROOT = "a1-policy/v2";
+ public static final String V2_API_ROOT = "/a1-policy/v2";
public static final String V2_API_SERVICE_CALLBACKS_NAME = "Callbacks";
public static final String V2_API_SERVICE_CALLBACKS_DESCRIPTION = "";