diff options
Diffstat (limited to 'prh-app-server/src/main')
-rw-r--r-- | prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java | 2 | ||||
-rw-r--r-- | prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/PrhConfigurationProvider.java | 36 |
2 files changed, 14 insertions, 24 deletions
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java index 8b3cdcd9..3967dc0a 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java @@ -48,7 +48,7 @@ public class MainApp { } @Bean - Map<String, String> mdcContextMap(){ + Map<String, String> mdcContextMap() { MDC.put(REQUEST_ID, "SampleRequestID"); MDC.put(INVOCATION_ID, UUID.randomUUID().toString()); return MDC.getCopyOfContextMap(); diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/PrhConfigurationProvider.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/PrhConfigurationProvider.java index c80ecfaf..38b060e9 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/PrhConfigurationProvider.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/PrhConfigurationProvider.java @@ -22,12 +22,11 @@ package org.onap.dcaegen2.services.prh.service; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import java.net.URISyntaxException; -import org.apache.http.client.utils.URIBuilder; import org.onap.dcaegen2.services.prh.model.EnvProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; +import org.springframework.web.util.DefaultUriBuilderFactory; import reactor.core.publisher.Mono; @@ -57,16 +56,12 @@ public class PrhConfigurationProvider { private Mono<String> callConsulForConfigBindingServiceEndpoint(EnvProperties envProperties) { LOGGER.info("Retrieving Config Binding Service endpoint from Consul"); - try { - return httpGetClient.callHttpGet(getConsulUrl(envProperties), JsonArray.class) - .flatMap(jsonArray -> this.createConfigBindingServiceUrl(jsonArray, envProperties.appName())); - } catch (URISyntaxException e) { - LOGGER.warn("Malformed Consul uri", e); - return Mono.error(e); - } + return httpGetClient.callHttpGet(getConsulUrl(envProperties), JsonArray.class) + .flatMap(jsonArray -> this.createConfigBindingServiceUrl(jsonArray, envProperties.appName())); + } - private String getConsulUrl(EnvProperties envProperties) throws URISyntaxException { + private String getConsulUrl(EnvProperties envProperties) { return getUri(envProperties.consulHost(), envProperties.consulPort(), "/v1/catalog/service", envProperties.cbsName()); } @@ -83,13 +78,8 @@ public class PrhConfigurationProvider { } private Mono<String> buildConfigBindingServiceUrl(JsonObject jsonObject, String appName) { - try { - return Mono.just(getUri(jsonObject.get("ServiceAddress").getAsString(), - jsonObject.get("ServicePort").getAsInt(), "/service_component", appName)); - } catch (URISyntaxException e) { - LOGGER.warn("Malformed Config Binding Service uri", e); - return Mono.error(e); - } + return Mono.just(getUri(jsonObject.get("ServiceAddress").getAsString(), + jsonObject.get("ServicePort").getAsInt(), "/service_component", appName)); } private Mono<JsonObject> getConfigBindingObject(JsonArray jsonArray) { @@ -105,12 +95,12 @@ public class PrhConfigurationProvider { } } - private String getUri(String host, Integer port, String... paths) throws URISyntaxException { - return new URIBuilder() - .setScheme("http") - .setHost(host) - .setPort(port) - .setPath(String.join("/", paths)) + private String getUri(String host, Integer port, String... paths) { + return new DefaultUriBuilderFactory().builder() + .scheme("http") + .host(host) + .port(port) + .path(String.join("/", paths)) .build().toString(); } } |