aboutsummaryrefslogtreecommitdiffstats
path: root/rest-services/cbs-client/src/main/java/org
diff options
context:
space:
mode:
authorPiotr Jaszczyk <piotr.jaszczyk@nokia.com>2019-04-03 10:07:23 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-03 10:07:23 +0000
commitb216682dc03e696ce75231135fe72dec6ce4e166 (patch)
tree598065497269eedda8a7590a1ceb3334051a3ba8 /rest-services/cbs-client/src/main/java/org
parentbf0927e896ed703fc25367fe80a0c21dffdbee31 (diff)
parent4b56423d975c55652ad40720848f675c9947b192 (diff)
Merge "Replace CloudHttpClient with RxHttpClient in ReactiveCloudConfigurationProvider"
Diffstat (limited to 'rest-services/cbs-client/src/main/java/org')
-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));
}