Skip to content
Snippets Groups Projects
Commit bcb6bc0d authored by Nikhil Singh[MicroSoft]'s avatar Nikhil Singh[MicroSoft]
Browse files

Commit 9 Contents:

1-Review Comments addressed
parent e5546143
No related branches found
No related tags found
2 merge requests!100Commit 2 contents:,!87Notification Service Refactoring
Pipeline #53052 failed
...@@ -54,7 +54,7 @@ public class PubsubEndpoint { ...@@ -54,7 +54,7 @@ public class PubsubEndpoint {
Map<String, String> headerAttributes = this.pubsubRequestBodyExtractor.extractAttributesFromRequestBody(); Map<String, String> headerAttributes = this.pubsubRequestBodyExtractor.extractAttributesFromRequestBody();
HttpResponse response = notificationHandler.notifySubscriber(notificationId, pubsubMessage, headerAttributes); HttpResponse response = notificationHandler.notifySubscriber(notificationId, pubsubMessage, headerAttributes);
if (!response.isSuccessCode()) { 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())); return new ResponseEntity<String>(NOT_ACKNOWLEDGE, HttpStatus.valueOf(response.getResponseCode()));
} }
this.log.debug(ACKNOWLEDGE); this.log.debug(ACKNOWLEDGE);
......
...@@ -30,7 +30,6 @@ import java.util.HashMap; ...@@ -30,7 +30,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
@Component @Component
@RequestScope
public class GsaAuth implements SecretAuth { public class GsaAuth implements SecretAuth {
@Autowired @Autowired
private IGoogleServiceAccount gsaTokenProvider; private IGoogleServiceAccount gsaTokenProvider;
......
...@@ -27,7 +27,6 @@ import java.util.HashMap; ...@@ -27,7 +27,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
@Component @Component
@RequestScope
public class HmacAuth implements SecretAuth { public class HmacAuth implements SecretAuth {
@Autowired @Autowired
private ISignatureService signatureService; private ISignatureService signatureService;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package org.opengroup.osdu.notification.auth.factory; package org.opengroup.osdu.notification.auth.factory;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; 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.GsaAuth;
import org.opengroup.osdu.notification.auth.HmacAuth; import org.opengroup.osdu.notification.auth.HmacAuth;
import org.opengroup.osdu.notification.auth.interfaces.SecretAuth; import org.opengroup.osdu.notification.auth.interfaces.SecretAuth;
...@@ -25,6 +26,9 @@ import org.springframework.web.context.annotation.RequestScope; ...@@ -25,6 +26,9 @@ import org.springframework.web.context.annotation.RequestScope;
@Component @Component
public class AuthFactory { public class AuthFactory {
private final String HMAC_TYPE = "HMAC";
private final String GSA_TYPE = "GSA";
@Autowired @Autowired
private HmacAuth hmacAuth; private HmacAuth hmacAuth;
@Autowired @Autowired
...@@ -33,13 +37,13 @@ public class AuthFactory { ...@@ -33,13 +37,13 @@ public class AuthFactory {
private JaxRsDpsLog log; private JaxRsDpsLog log;
public SecretAuth getSecretAuth(String secretType) { public SecretAuth getSecretAuth(String secretType) {
switch (secretType) { switch (secretType.toUpperCase()) {
case "HMAC": case HMAC_TYPE:
return hmacAuth; return hmacAuth;
case "GSA": case GSA_TYPE:
return gsaAuth; return gsaAuth;
default:
throw new AppException(404, "Secret Type Not Found", "Unrecognised secret type encountered :" + secretType);
} }
log.error("Unrecognized Secret Type.");
return null;
} }
} }
...@@ -24,6 +24,8 @@ import org.opengroup.osdu.core.common.model.http.DpsHeaders; ...@@ -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.core.common.model.notification.*;
import org.opengroup.osdu.notification.auth.factory.AuthFactory; import org.opengroup.osdu.notification.auth.factory.AuthFactory;
import org.opengroup.osdu.notification.auth.interfaces.SecretAuth; 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.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -34,8 +36,7 @@ import java.util.Map; ...@@ -34,8 +36,7 @@ import java.util.Map;
@Component @Component
public class NotificationHandler { public class NotificationHandler {
@Autowired private final static Logger LOGGER = LoggerFactory.getLogger(NotificationHandler.class);
private JaxRsDpsLog log;
@Autowired @Autowired
private HttpClient httpClient; private HttpClient httpClient;
@Autowired @Autowired
...@@ -43,7 +44,7 @@ public class NotificationHandler { ...@@ -43,7 +44,7 @@ public class NotificationHandler {
@Autowired @Autowired
private AuthFactory authFactory; private AuthFactory authFactory;
@Value("${app.waitingTime:30000}") @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 { public HttpResponse notifySubscriber(String notificationId, String pubsubMessage, Map<String, String> headerAttributes) throws Exception {
Subscription subscription = subscriptionHandler.getSubscriptionFromCache(notificationId); Subscription subscription = subscriptionHandler.getSubscriptionFromCache(notificationId);
...@@ -51,7 +52,7 @@ public class NotificationHandler { ...@@ -51,7 +52,7 @@ public class NotificationHandler {
String endpoint = subscription.getPushEndpoint(); String endpoint = subscription.getPushEndpoint();
String secretType = secret.getSecretType(); String secretType = secret.getSecretType();
String pushUrl = ""; String pushUrl = "";
Map<String, String> requestHeader = new HashMap<String,String>(); Map<String, String> requestHeader = new HashMap<String, String>();
// Authentication Secret // Authentication Secret
SecretAuth secretAuth = authFactory.getSecretAuth(secretType); SecretAuth secretAuth = authFactory.getSecretAuth(secretType);
...@@ -65,7 +66,7 @@ public class NotificationHandler { ...@@ -65,7 +66,7 @@ public class NotificationHandler {
HttpRequest request = HttpRequest.post().url(pushUrl).headers(requestHeader).body(pubsubMessage).connectionTimeout(WAITING_TIME).build(); HttpRequest request = HttpRequest.post().url(pushUrl).headers(requestHeader).body(pubsubMessage).connectionTimeout(WAITING_TIME).build();
HttpResponse response = httpClient.send(request); 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; return response;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment