From bcb6bc0dae94f05c1f1fb6b71e025dba015d8a91 Mon Sep 17 00:00:00 2001 From: nikhilsingh <nikhilsingh@microsoft.com> Date: Tue, 20 Jul 2021 14:06:29 +0530 Subject: [PATCH] Commit 9 Contents: 1-Review Comments addressed --- .../osdu/notification/api/PubsubEndpoint.java | 2 +- .../opengroup/osdu/notification/auth/GsaAuth.java | 1 - .../opengroup/osdu/notification/auth/HmacAuth.java | 1 - .../notification/auth/factory/AuthFactory.java | 14 +++++++++----- .../notification/service/NotificationHandler.java | 11 ++++++----- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/api/PubsubEndpoint.java b/notification-core/src/main/java/org/opengroup/osdu/notification/api/PubsubEndpoint.java index 22b02bef1..33ea6281a 100644 --- a/notification-core/src/main/java/org/opengroup/osdu/notification/api/PubsubEndpoint.java +++ b/notification-core/src/main/java/org/opengroup/osdu/notification/api/PubsubEndpoint.java @@ -54,7 +54,7 @@ public class PubsubEndpoint { Map<String, String> headerAttributes = this.pubsubRequestBodyExtractor.extractAttributesFromRequestBody(); HttpResponse response = notificationHandler.notifySubscriber(notificationId, pubsubMessage, headerAttributes); if (!response.isSuccessCode()) { - this.log.error(NOT_ACKNOWLEDGE); + this.log.error(NOT_ACKNOWLEDGE + response.getBody()); return new ResponseEntity<String>(NOT_ACKNOWLEDGE, HttpStatus.valueOf(response.getResponseCode())); } this.log.debug(ACKNOWLEDGE); diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/GsaAuth.java b/notification-core/src/main/java/org/opengroup/osdu/notification/auth/GsaAuth.java index 4ff98310b..565c66358 100644 --- a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/GsaAuth.java +++ b/notification-core/src/main/java/org/opengroup/osdu/notification/auth/GsaAuth.java @@ -30,7 +30,6 @@ import java.util.HashMap; import java.util.Map; @Component -@RequestScope public class GsaAuth implements SecretAuth { @Autowired private IGoogleServiceAccount gsaTokenProvider; diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/HmacAuth.java b/notification-core/src/main/java/org/opengroup/osdu/notification/auth/HmacAuth.java index 3c5303d3f..625204397 100644 --- a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/HmacAuth.java +++ b/notification-core/src/main/java/org/opengroup/osdu/notification/auth/HmacAuth.java @@ -27,7 +27,6 @@ import java.util.HashMap; import java.util.Map; @Component -@RequestScope public class HmacAuth implements SecretAuth { @Autowired private ISignatureService signatureService; diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/factory/AuthFactory.java b/notification-core/src/main/java/org/opengroup/osdu/notification/auth/factory/AuthFactory.java index acfe98026..5cedb532d 100644 --- a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/factory/AuthFactory.java +++ b/notification-core/src/main/java/org/opengroup/osdu/notification/auth/factory/AuthFactory.java @@ -16,6 +16,7 @@ package org.opengroup.osdu.notification.auth.factory; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.notification.auth.GsaAuth; import org.opengroup.osdu.notification.auth.HmacAuth; import org.opengroup.osdu.notification.auth.interfaces.SecretAuth; @@ -25,6 +26,9 @@ import org.springframework.web.context.annotation.RequestScope; @Component public class AuthFactory { + private final String HMAC_TYPE = "HMAC"; + private final String GSA_TYPE = "GSA"; + @Autowired private HmacAuth hmacAuth; @Autowired @@ -33,13 +37,13 @@ public class AuthFactory { private JaxRsDpsLog log; public SecretAuth getSecretAuth(String secretType) { - switch (secretType) { - case "HMAC": + switch (secretType.toUpperCase()) { + case HMAC_TYPE: return hmacAuth; - case "GSA": + case GSA_TYPE: return gsaAuth; + default: + throw new AppException(404, "Secret Type Not Found", "Unrecognised secret type encountered :" + secretType); } - log.error("Unrecognized Secret Type."); - return null; } } diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/service/NotificationHandler.java b/notification-core/src/main/java/org/opengroup/osdu/notification/service/NotificationHandler.java index ecff8661d..9ba4a823a 100644 --- a/notification-core/src/main/java/org/opengroup/osdu/notification/service/NotificationHandler.java +++ b/notification-core/src/main/java/org/opengroup/osdu/notification/service/NotificationHandler.java @@ -24,6 +24,8 @@ import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.notification.*; import org.opengroup.osdu.notification.auth.factory.AuthFactory; import org.opengroup.osdu.notification.auth.interfaces.SecretAuth; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -34,8 +36,7 @@ import java.util.Map; @Component public class NotificationHandler { - @Autowired - private JaxRsDpsLog log; + private final static Logger LOGGER = LoggerFactory.getLogger(NotificationHandler.class); @Autowired private HttpClient httpClient; @Autowired @@ -43,7 +44,7 @@ public class NotificationHandler { @Autowired private AuthFactory authFactory; @Value("${app.waitingTime:30000}") - private int WAITING_TIME ; + private int WAITING_TIME; public HttpResponse notifySubscriber(String notificationId, String pubsubMessage, Map<String, String> headerAttributes) throws Exception { Subscription subscription = subscriptionHandler.getSubscriptionFromCache(notificationId); @@ -51,7 +52,7 @@ public class NotificationHandler { String endpoint = subscription.getPushEndpoint(); String secretType = secret.getSecretType(); String pushUrl = ""; - Map<String, String> requestHeader = new HashMap<String,String>(); + Map<String, String> requestHeader = new HashMap<String, String>(); // Authentication Secret SecretAuth secretAuth = authFactory.getSecretAuth(secretType); @@ -65,7 +66,7 @@ public class NotificationHandler { HttpRequest request = HttpRequest.post().url(pushUrl).headers(requestHeader).body(pubsubMessage).connectionTimeout(WAITING_TIME).build(); HttpResponse response = httpClient.send(request); - this.log.info("sending out notification to endpoint: " + endpoint); + this.LOGGER.debug("Sending out notification to endpoint: " + endpoint); return response; } } -- GitLab