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 22b02bef1581f4d9242b05e988b0a5f75fa0303e..33ea6281af557e5f028bd599e05f83779ccfe805 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 4ff98310b10fa909e477300cc741f20775624649..565c6635802339ffafe8499da66974e8ad164c0e 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 3c5303d3f3e6bb100047c0df70d25730f22b3d5e..6252043970c7e03fd0d3c1a6ae21f4d40adb61d5 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 acfe9802646ceb778dffa3d678098390a612fed7..5cedb532daabcf4806eb30dfffbbd97878b38750 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 ecff8661d140e74d1cc435df6cc4f6a7d51a96d4..9ba4a823ab5d54fa97e5f79ffa8bc2a926ed09cb 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; } }