diff options
author | wasala <przemyslaw.wasala@nokia.com> | 2018-05-23 09:53:41 +0200 |
---|---|---|
committer | wasala <przemyslaw.wasala@nokia.com> | 2018-05-23 12:02:13 +0200 |
commit | b6bc8925a354825545b8527879e0f687b0dbab3a (patch) | |
tree | 9325bbf073594ad411576a969efec5212ce9d9d7 /prh-aai-client | |
parent | e6f50c671627adc43e3aeeb3f3656dc8dfc584dd (diff) |
Fix sonar issues
Change-Id: I61155448422f0084ac08f294452ac90f5b3454aa
Issue-ID: DCAEGEN2-396
Signed-off-by: wasala <przemyslaw.wasala@nokia.com>
Diffstat (limited to 'prh-aai-client')
2 files changed, 29 insertions, 31 deletions
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 99a4a8b2..aa4630b5 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 @@ -94,7 +94,7 @@ public class AAIConsumerClient { private ResponseHandler<Optional<String>> aaiResponseHandler() { return httpResponse -> { final int responseCode = httpResponse.getStatusLine().getStatusCode(); - logger.trace("Status code of operation: {}", responseCode); + logger.info("Status code of operation: {}", responseCode); final HttpEntity responseEntity = httpResponse.getEntity(); if (HttpUtils.isSuccessfulResponseCode(responseCode) ) { 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 4f48c1c3..bb4d145e 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 @@ -44,6 +44,8 @@ import java.util.Map; 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 final CloseableHttpClient closeableHttpClient; @@ -51,7 +53,7 @@ public class AAIProducerClient implements AAIExtendedHttpClient { private final String aaiProtocol; private final Integer aaiHostPortNumber; private final String aaiPath; - private final Map<String,String> aaiHeaders; + private final Map<String, String> aaiHeaders; public AAIProducerClient(AAIClientConfiguration aaiClientConfiguration) { @@ -66,20 +68,15 @@ public class AAIProducerClient implements AAIExtendedHttpClient { @Override public Optional<Integer> getHttpResponse(ConsumerDmaapModel consumerDmaapModel) throws - URISyntaxException { - try { - return createRequest(consumerDmaapModel).flatMap(x->{ - try { - return closeableHttpClient.execute(x, aaiResponseHandler()); - } catch (IOException e) { - logger.warn("Exception while executing http client: ", e); - return Optional.empty(); - } - }); - } catch (URISyntaxException e ) { - logger.warn("Exception while executing http client: ", e); - throw e; - } + URISyntaxException { + return createRequest(consumerDmaapModel).flatMap(x -> { + try { + return closeableHttpClient.execute(x, aaiResponseHandler()); + } catch (IOException e) { + logger.warn(EXCEPTION_MESSAGE, e); + return Optional.empty(); + } + }); } private Optional<HttpRequestBase> createRequest(ConsumerDmaapModel consumerDmaapModel) throws URISyntaxException { @@ -89,16 +86,16 @@ public class AAIProducerClient implements AAIExtendedHttpClient { private URI createAAIExtendedURI(final String pnfName) throws URISyntaxException { return new URIBuilder() - .setScheme(aaiProtocol) - .setHost(aaiHost) - .setPort(aaiHostPortNumber) - .setPath(aaiPath + "/" + pnfName).build(); + .setScheme(aaiProtocol) + .setHost(aaiHost) + .setPort(aaiHostPortNumber) + .setPath(aaiPath + "/" + pnfName).build(); } private ResponseHandler<Optional<Integer>> aaiResponseHandler() { - return (HttpResponse httpResponse) -> { + return (HttpResponse httpResponse) -> { final Integer responseCode = httpResponse.getStatusLine().getStatusCode(); - logger.trace("Status code of operation: {}", responseCode); + logger.info("Status code of operation: {}", responseCode); final HttpEntity responseEntity = httpResponse.getEntity(); if (HttpUtils.isSuccessfulResponseCode(responseCode)) { @@ -113,19 +110,20 @@ public class AAIProducerClient implements AAIExtendedHttpClient { } private 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 while executing http client: ", e); - } - return Optional.empty(); - }); + 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(); + }); } private 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"); return httpPatch; |