diff options
Diffstat (limited to 'prh-aai-client')
3 files changed, 21 insertions, 18 deletions
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIClientImpl.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIClientImpl.java index 5e938528..04652020 100644 --- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIClientImpl.java +++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIClientImpl.java @@ -41,7 +41,7 @@ import java.security.NoSuchAlgorithmException; public class AAIClientImpl implements AAIClient { - private Logger logger = LoggerFactory.getLogger(AAIClientImpl.class); + private final Logger logger = LoggerFactory.getLogger(this.getClass()); private AAIClientConfiguration aaiClientConfig; @@ -62,10 +62,10 @@ public class AAIClientImpl implements AAIClient { try { logger.info("Setting SSL Context for AAI HTTP Client"); httpClientBuilder.setSSLContext(new SSLContextBuilder() - .loadTrustMaterial(null, acceptingTrustStrategy) - .build()); + .loadTrustMaterial(null, acceptingTrustStrategy) + .build()); - } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e ) { + } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { logger.error("Exception while setting SSL Context for AAI HTTP Client: {}", e); } diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIConsumerClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIConsumerClient.java index dfacc6b1..fafe6e04 100644 --- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIConsumerClient.java +++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIConsumerClient.java @@ -42,7 +42,7 @@ import java.util.Optional; public class AAIConsumerClient { - private Logger logger = LoggerFactory.getLogger(AAIConsumerClient.class); + private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final CloseableHttpClient closeableHttpClient; private final String aaiHost; diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIProducerClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIProducerClient.java index f85ac8aa..0c2a12a3 100644 --- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIProducerClient.java +++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIProducerClient.java @@ -20,6 +20,7 @@ package org.onap.dcaegen2.services.prh.service; +import java.util.function.Predicate; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPatch; @@ -46,14 +47,14 @@ import java.util.Optional; public class AAIProducerClient implements AAIExtendedHttpClient { private static final String EXCEPTION_MESSAGE = "Exception while executing http client: "; - private Logger logger = LoggerFactory.getLogger(AAIProducerClient.class); - + private static Predicate<String> isEmpty = String::isEmpty; + private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final CloseableHttpClient closeableHttpClient; private final String aaiHost; private final String aaiProtocol; private final Integer aaiHostPortNumber; private final String aaiPath; - private final Map<String,String> aaiHeaders; + private final Map<String, String> aaiHeaders; private final String aaiUserName; private final String aaiUserPassword; @@ -96,19 +97,21 @@ public class AAIProducerClient implements AAIExtendedHttpClient { } Optional<HttpRequestBase> createHttpRequest(URI extendedURI, ConsumerDmaapModel consumerDmaapModel) { - return Optional.ofNullable(CommonFunctions.createJsonBody(consumerDmaapModel)).filter(x-> !x.isEmpty()).flatMap(myJson -> { - try { - return Optional.of(createHttpPatch(extendedURI, myJson)); - } catch (UnsupportedEncodingException e) { - logger.warn(EXCEPTION_MESSAGE, e); - } - return Optional.empty(); - }); + return Optional.ofNullable(CommonFunctions.createJsonBody(consumerDmaapModel)).filter(isEmpty.negate()) + .flatMap(myJson -> { + try { + logger.info("AAI: sending json {}", myJson); + return Optional.of(createHttpPatch(extendedURI, myJson)); + } catch (UnsupportedEncodingException e) { + logger.warn(EXCEPTION_MESSAGE, e); + } + return Optional.empty(); + }); } HttpPatch createHttpPatch(URI extendedURI, String jsonBody) throws UnsupportedEncodingException { HttpPatch httpPatch = new HttpPatch(extendedURI); - httpPatch.setEntity( new StringEntity(jsonBody)); + httpPatch.setEntity(new StringEntity(jsonBody)); aaiHeaders.forEach(httpPatch::addHeader); httpPatch.addHeader("Content-Type", "application/merge-patch+json"); httpPatch.addHeader("Authorization", "Basic " + encode()); @@ -117,7 +120,7 @@ public class AAIProducerClient implements AAIExtendedHttpClient { String encode() throws UnsupportedEncodingException { return Base64.getEncoder().encodeToString((this.aaiUserName + ":" + this.aaiUserPassword) - .getBytes("UTF-8")); + .getBytes("UTF-8")); } Optional<Integer> handleResponse(HttpResponse response) throws IOException { |