diff options
Diffstat (limited to 'prh-aai-client/src/main')
-rw-r--r-- | prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/config/AaiClientConfiguration.java (renamed from prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/config/AAIClientConfiguration.java) | 10 | ||||
-rw-r--r-- | prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiClient.java (renamed from prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIClient.java) | 6 | ||||
-rw-r--r-- | prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiClientImpl.java (renamed from prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIClientImpl.java) | 23 | ||||
-rw-r--r-- | prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiConsumerClient.java (renamed from prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIConsumerClient.java) | 74 | ||||
-rw-r--r-- | prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiExtendedHttpClient.java (renamed from prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIExtendedHttpClient.java) | 10 | ||||
-rw-r--r-- | prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiProducerClient.java (renamed from prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIProducerClient.java) | 40 |
6 files changed, 89 insertions, 74 deletions
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/config/AAIClientConfiguration.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/config/AaiClientConfiguration.java index d652ccb7..c9d7820c 100644 --- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/config/AAIClientConfiguration.java +++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/config/AaiClientConfiguration.java @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ @@ -20,8 +20,8 @@ package org.onap.dcaegen2.services.prh.config; - import java.io.Serializable; + import java.util.Map; import org.immutables.gson.Gson; @@ -33,7 +33,7 @@ import org.springframework.stereotype.Component; @Value.Immutable(prehash = true) @Value.Style(builder = "new") @Gson.TypeAdapters -public abstract class AAIClientConfiguration implements Serializable { +public abstract class AaiClientConfiguration implements Serializable { private static final long serialVersionUID = 1L; @@ -53,7 +53,7 @@ public abstract class AAIClientConfiguration implements Serializable { public abstract String aaiUserPassword(); @Value.Parameter - public abstract Boolean aaiIgnoreSSLCertificateErrors(); + public abstract Boolean aaiIgnoreSslCertificateErrors(); @Value.Parameter public abstract String aaiBasePath(); @@ -62,6 +62,6 @@ public abstract class AAIClientConfiguration implements Serializable { public abstract String aaiPnfPath(); @Value.Parameter - public abstract Map<String,String> aaiHeaders(); + public abstract Map<String, String> aaiHeaders(); } diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiClient.java index 09d7f6ae..2d0f9eca 100644 --- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIClient.java +++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiClient.java @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ @@ -23,7 +23,7 @@ package org.onap.dcaegen2.services.prh.service; import org.apache.http.impl.client.CloseableHttpClient; @FunctionalInterface -public interface AAIClient { - CloseableHttpClient getAAIHttpClient(); +public interface AaiClient { + CloseableHttpClient getAaiHttpClient(); } 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 04652020..f9252578 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 @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ @@ -20,6 +20,10 @@ package org.onap.dcaegen2.services.prh.service; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; + import org.apache.http.auth.AuthScope; import org.apache.http.auth.Credentials; import org.apache.http.auth.UsernamePasswordCredentials; @@ -31,34 +35,31 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContextBuilder; import org.apache.http.ssl.TrustStrategy; -import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration; +import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -public class AAIClientImpl implements AAIClient { +public class AaiClientImpl implements AaiClient { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - private AAIClientConfiguration aaiClientConfig; + private AaiClientConfiguration aaiClientConfig; - public AAIClientImpl(AAIClientConfiguration aaiClientConfiguration) { + AaiClientImpl(AaiClientConfiguration aaiClientConfiguration) { this.aaiClientConfig = aaiClientConfiguration; } @Override - public CloseableHttpClient getAAIHttpClient() { + public CloseableHttpClient getAaiHttpClient() { final HttpClientBuilder httpClientBuilder = HttpClients.custom().useSystemProperties(); - final boolean aaiIgnoreSSLCertificateErrors = aaiClientConfig.aaiIgnoreSSLCertificateErrors(); + final boolean aaiIgnoreSslCertificateErrors = aaiClientConfig.aaiIgnoreSslCertificateErrors(); TrustStrategy acceptingTrustStrategy = (cert, authType) -> true; - if (aaiIgnoreSSLCertificateErrors) { + if (aaiIgnoreSslCertificateErrors) { try { logger.info("Setting SSL Context for AAI HTTP Client"); httpClientBuilder.setSSLContext(new SSLContextBuilder() 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 fafe6e04..0a00048b 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 @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ @@ -20,6 +20,13 @@ package org.onap.dcaegen2.services.prh.service; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + import org.apache.http.HttpEntity; import org.apache.http.client.ResponseHandler; import org.apache.http.client.methods.HttpGet; @@ -27,20 +34,14 @@ import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.client.utils.URIBuilder; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.util.EntityUtils; -import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration; +import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.model.utils.HttpUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -public class AAIConsumerClient { +public class AaiConsumerClient { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -49,11 +50,15 @@ public class AAIConsumerClient { private final String aaiProtocol; private final Integer aaiHostPortNumber; private final String aaiPath; - private final Map<String,String> aaiHeaders; - - - public AAIConsumerClient(AAIClientConfiguration aaiClientConfiguration) { - closeableHttpClient = new AAIClientImpl(aaiClientConfiguration).getAAIHttpClient(); + private final Map<String, String> aaiHeaders; + + /** + * AAI client for consuming data. + * + * @param aaiClientConfiguration - client config + */ + public AaiConsumerClient(AaiClientConfiguration aaiClientConfiguration) { + closeableHttpClient = new AaiClientImpl(aaiClientConfiguration).getAaiHttpClient(); aaiHost = aaiClientConfiguration.aaiHost(); aaiProtocol = aaiClientConfiguration.aaiProtocol(); aaiHostPortNumber = aaiClientConfiguration.aaiHostPortNumber(); @@ -61,6 +66,13 @@ public class AAIConsumerClient { aaiHeaders = aaiClientConfiguration.aaiHeaders(); } + /** + * Function which call http client for getting object from AAI. + * + * @param consumerDmaapModel - helper object for uri generation + * @return - status code of operation + * @throws IOException - Apache HTTP client exception + */ public Optional<String> getHttpResponse(ConsumerDmaapModel consumerDmaapModel) throws IOException { Optional<HttpRequestBase> request = createRequest(consumerDmaapModel); try { @@ -71,33 +83,33 @@ public class AAIConsumerClient { } } - private URI createAAIExtendedURI(String pnfName) { + private URI createAaiExtendedUri(String pnfName) { - URI extendedURI = null; + URI extendedUri = null; final URIBuilder uriBuilder = new URIBuilder() - .setScheme(aaiProtocol) - .setHost(aaiHost) - .setPort(aaiHostPortNumber) - .setPath(aaiPath + "/" + pnfName); + .setScheme(aaiProtocol) + .setHost(aaiHost) + .setPort(aaiHostPortNumber) + .setPath(aaiPath + "/" + pnfName); try { - extendedURI = uriBuilder.build(); - logger.trace("Building extended URI: {}", extendedURI); + extendedUri = uriBuilder.build(); + logger.trace("Building extended URI: {}", extendedUri); } catch (URISyntaxException e) { logger.warn("Exception while building extended URI: {}", e); } - return extendedURI; + return extendedUri; } private ResponseHandler<Optional<String>> aaiResponseHandler() { - return httpResponse -> { + return httpResponse -> { final int responseCode = httpResponse.getStatusLine().getStatusCode(); logger.info("Status code of operation: {}", responseCode); final HttpEntity responseEntity = httpResponse.getEntity(); - if (HttpUtils.isSuccessfulResponseCode(responseCode) ) { + if (HttpUtils.isSuccessfulResponseCode(responseCode)) { logger.trace("HTTP response successful."); final String aaiResponse = EntityUtils.toString(responseEntity); return Optional.of(aaiResponse); @@ -109,17 +121,17 @@ public class AAIConsumerClient { }; } - private HttpRequestBase createHttpRequest(URI extendedURI) { - return isExtendedURINotNull(extendedURI) ? new HttpGet(extendedURI) : null; + private HttpRequestBase createHttpRequest(URI extendedUri) { + return isExtendedUriNotNull(extendedUri) ? new HttpGet(extendedUri) : null; } - private Boolean isExtendedURINotNull(URI extendedURI) { - return extendedURI != null; + private Boolean isExtendedUriNotNull(URI extendedUri) { + return extendedUri != null; } private Optional<HttpRequestBase> createRequest(ConsumerDmaapModel consumerDmaapModel) { - final URI extendedURI = createAAIExtendedURI(consumerDmaapModel.getPnfName()); - HttpRequestBase request = createHttpRequest(extendedURI); + final URI extendedUri = createAaiExtendedUri(consumerDmaapModel.getPnfName()); + HttpRequestBase request = createHttpRequest(extendedUri); aaiHeaders.forEach(Objects.requireNonNull(request)::addHeader); Objects.requireNonNull(request).addHeader("Content-Type", "application/json"); return Optional.of(request); diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIExtendedHttpClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiExtendedHttpClient.java index 14c7e8f3..8e424fe6 100644 --- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIExtendedHttpClient.java +++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AaiExtendedHttpClient.java @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ @@ -17,15 +17,17 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.dcaegen2.services.prh.service; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; +package org.onap.dcaegen2.services.prh.service; import java.net.URISyntaxException; import java.util.Optional; +import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; + @FunctionalInterface -public interface AAIExtendedHttpClient { +public interface AaiExtendedHttpClient { + Optional<Integer> getHttpResponse(ConsumerDmaapModel consumerDmaapModel) throws URISyntaxException; } 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 0c2a12a3..f4301f6b 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 @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ @@ -20,6 +20,14 @@ package org.onap.dcaegen2.services.prh.service; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Base64; +import java.util.Map; +import java.util.Optional; + import java.util.function.Predicate; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; @@ -29,22 +37,14 @@ import org.apache.http.client.utils.URIBuilder; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.util.EntityUtils; -import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration; +import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration; import org.onap.dcaegen2.services.prh.model.CommonFunctions; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.model.utils.HttpUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Base64; -import java.util.Map; -import java.util.Optional; - -public class AAIProducerClient implements AAIExtendedHttpClient { +public class AaiProducerClient implements AaiExtendedHttpClient { private static final String EXCEPTION_MESSAGE = "Exception while executing http client: "; private static Predicate<String> isEmpty = String::isEmpty; @@ -59,8 +59,8 @@ public class AAIProducerClient implements AAIExtendedHttpClient { private final String aaiUserPassword; - public AAIProducerClient(AAIClientConfiguration aaiClientConfiguration) { - closeableHttpClient = new AAIClientImpl(aaiClientConfiguration).getAAIHttpClient(); + public AaiProducerClient(AaiClientConfiguration aaiClientConfiguration) { + closeableHttpClient = new AaiClientImpl(aaiClientConfiguration).getAaiHttpClient(); aaiHost = aaiClientConfiguration.aaiHost(); aaiProtocol = aaiClientConfiguration.aaiProtocol(); aaiHostPortNumber = aaiClientConfiguration.aaiHostPortNumber(); @@ -84,11 +84,11 @@ public class AAIProducerClient implements AAIExtendedHttpClient { } private Optional<HttpRequestBase> createRequest(ConsumerDmaapModel consumerDmaapModel) throws URISyntaxException { - final URI extendedURI = createAAIExtendedURI(consumerDmaapModel.getPnfName()); - return createHttpRequest(extendedURI, consumerDmaapModel); + final URI extendedUri = createAaiExtendedUri(consumerDmaapModel.getPnfName()); + return createHttpRequest(extendedUri, consumerDmaapModel); } - private URI createAAIExtendedURI(final String pnfName) throws URISyntaxException { + private URI createAaiExtendedUri(final String pnfName) throws URISyntaxException { return new URIBuilder() .setScheme(aaiProtocol) .setHost(aaiHost) @@ -96,12 +96,12 @@ public class AAIProducerClient implements AAIExtendedHttpClient { .setPath(aaiPath + "/" + pnfName).build(); } - Optional<HttpRequestBase> createHttpRequest(URI extendedURI, ConsumerDmaapModel consumerDmaapModel) { + private Optional<HttpRequestBase> createHttpRequest(URI extendedUri, ConsumerDmaapModel consumerDmaapModel) { return Optional.ofNullable(CommonFunctions.createJsonBody(consumerDmaapModel)).filter(isEmpty.negate()) .flatMap(myJson -> { try { logger.info("AAI: sending json {}", myJson); - return Optional.of(createHttpPatch(extendedURI, myJson)); + return Optional.of(createHttpPatch(extendedUri, myJson)); } catch (UnsupportedEncodingException e) { logger.warn(EXCEPTION_MESSAGE, e); } @@ -109,8 +109,8 @@ public class AAIProducerClient implements AAIExtendedHttpClient { }); } - HttpPatch createHttpPatch(URI extendedURI, String jsonBody) throws UnsupportedEncodingException { - HttpPatch httpPatch = new HttpPatch(extendedURI); + HttpPatch createHttpPatch(URI extendedUri, String jsonBody) throws UnsupportedEncodingException { + HttpPatch httpPatch = new HttpPatch(extendedUri); httpPatch.setEntity(new StringEntity(jsonBody)); aaiHeaders.forEach(httpPatch::addHeader); httpPatch.addHeader("Content-Type", "application/merge-patch+json"); |