Commit bcb6bc0d authored by Nikhil Singh[MicroSoft]'s avatar Nikhil Singh[MicroSoft]
Browse files

Commit 9 Contents:

1-Review Comments addressed
parent e5546143
Pipeline #53052 failed with stages
in 40 seconds
......@@ -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);
......
......@@ -30,7 +30,6 @@ import java.util.HashMap;
import java.util.Map;
@Component
@RequestScope
public class GsaAuth implements SecretAuth {
@Autowired
private IGoogleServiceAccount gsaTokenProvider;
......
......@@ -27,7 +27,6 @@ import java.util.HashMap;
import java.util.Map;
@Component
@RequestScope
public class HmacAuth implements SecretAuth {
@Autowired
private ISignatureService signatureService;
......
......@@ -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;
}
}
......@@ -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;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment