aboutsummaryrefslogtreecommitdiffstats
path: root/rest-services/cbs-client/src/main
diff options
context:
space:
mode:
authorIzabela Zawadzka <izabela.zawadzka@nokia.com>2019-04-03 09:21:44 +0200
committerIzabela Zawadzka <izabela.zawadzka@nokia.com>2019-04-03 11:20:48 +0200
commit4b56423d975c55652ad40720848f675c9947b192 (patch)
treeb718274a4c8f8fcaeb53deac811b16b78c3938cb /rest-services/cbs-client/src/main
parent07636bbe415099175afcbf55c8f08a24e5c357b5 (diff)
Replace CloudHttpClient with RxHttpClient in ReactiveCloudConfigurationProvider
Change-Id: I319622dce34999e637553ffbd0d31e91110cc3c3 Signed-off-by: Izabela Zawadzka <izabela.zawadzka@nokia.com> Issue-ID: DCAEGEN2-1383
Diffstat (limited to 'rest-services/cbs-client/src/main')
-rw-r--r--rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/streams/gson/GsonUtils.java5
-rw-r--r--rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/ReactiveCloudConfigurationProvider.java35
2 files changed, 30 insertions, 10 deletions
diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/streams/gson/GsonUtils.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/streams/gson/GsonUtils.java
index 7776a1ef..0881c082 100644
--- a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/streams/gson/GsonUtils.java
+++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/streams/gson/GsonUtils.java
@@ -22,6 +22,7 @@ package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl.streams.gso
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
+import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
@@ -86,6 +87,10 @@ public final class GsonUtils {
return readFromResource(resource).getAsJsonObject();
}
+ public static JsonArray readObjectArrayFromResource(String resource) throws IOException{
+ return readFromResource(resource).getAsJsonArray();
+ }
+
public static JsonElement readFromResource(String resource) throws IOException {
try (Reader reader = new InputStreamReader(GsonUtils.class.getResourceAsStream(resource))) {
return new JsonParser().parse(reader);
diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/ReactiveCloudConfigurationProvider.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/ReactiveCloudConfigurationProvider.java
index b7507884..27d36583 100644
--- a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/ReactiveCloudConfigurationProvider.java
+++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/providers/ReactiveCloudConfigurationProvider.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* DCAEGEN2-SERVICES-SDK
* ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 NOKIA Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,10 @@ package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
-import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.ImmutableHttpRequest;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties;
import org.onap.dcaegen2.services.sdk.rest.services.uri.URI;
import org.slf4j.Logger;
@@ -38,15 +41,14 @@ public final class ReactiveCloudConfigurationProvider implements CloudConfigurat
private static final Logger LOGGER = LoggerFactory.getLogger(ReactiveCloudConfigurationProvider.class);
private static final String EXCEPTION_MESSAGE = "Unsupported method call: ";
- private final CloudHttpClient cloudHttpClient;
+ private final RxHttpClient rxHttpClient;
public ReactiveCloudConfigurationProvider() {
- this(new CloudHttpClient());
+ this(RxHttpClient.create());
}
- ReactiveCloudConfigurationProvider(
- CloudHttpClient cloudHttpClient) {
- this.cloudHttpClient = cloudHttpClient;
+ ReactiveCloudConfigurationProvider(RxHttpClient rxHttpClient) {
+ this.rxHttpClient = rxHttpClient;
}
@Override
@@ -73,8 +75,17 @@ public final class ReactiveCloudConfigurationProvider implements CloudConfigurat
private Mono<String> callConsulForConfigBindingServiceEndpoint(EnvProperties envProperties) {
LOGGER.info("Retrieving Config Binding Service endpoint from Consul");
- return cloudHttpClient.get(getConsulUrl(envProperties), JsonArray.class)
- .flatMap(jsonArray -> this.createConfigBindingServiceUrl(jsonArray, envProperties.appName()));
+
+ HttpRequest httpRequest = ImmutableHttpRequest.builder()
+ .url(getConsulUrl(envProperties)).method(HttpMethod.GET).build();
+
+ return rxHttpClient.call(httpRequest)
+ .map(resp -> resp.bodyAsJson(JsonArray.class))
+ .flatMap(jsonArray ->
+ this.createConfigBindingServiceUrl(
+ jsonArray,
+ envProperties.appName())
+ );
}
private String getConsulUrl(EnvProperties envProperties) {
@@ -84,7 +95,11 @@ public final class ReactiveCloudConfigurationProvider implements CloudConfigurat
private Mono<JsonObject> callConfigBindingServiceForConfiguration(String configBindingServiceUri) {
LOGGER.info("Retrieving configuration");
- return cloudHttpClient.get(configBindingServiceUri, JsonObject.class);
+ HttpRequest httpRequest = ImmutableHttpRequest.builder()
+ .url(configBindingServiceUri).method(HttpMethod.GET).build();
+
+ return rxHttpClient.call(httpRequest)
+ .map(httpResponse -> httpResponse.bodyAsJson(JsonObject.class));
}