Skip to content
Snippets Groups Projects
Commit df2a30b0 authored by Komal Makkar's avatar Komal Makkar
Browse files

SPI for PubSubRequestExtractor and handshake request handler. Added interfaces

1. IPubsubRequestBodyExtractor
2. IPubsubHandshakehandler
parent e87d941d
No related branches found
No related tags found
2 merge requests!12Pubsub Azure Implementation.,!10SPI for PubSubRequestExtractor and handshake request handler.
Pipeline #5513 failed
Showing
with 63 additions and 12 deletions
......@@ -34,7 +34,8 @@ import org.opengroup.osdu.core.common.notification.ISubscriptionFactory;
import org.opengroup.osdu.core.common.notification.ISubscriptionService;
import org.opengroup.osdu.core.common.notification.SubscriptionException;
import org.opengroup.osdu.notification.di.SubscriptionCacheFactory;
import org.opengroup.osdu.notification.pubsub.PubsubRequestBodyExtractor;
import org.opengroup.osdu.notification.pubsub.IPubsubHandshakeHandler;
import org.opengroup.osdu.notification.pubsub.IPubsubRequestBodyExtractor;
import org.opengroup.osdu.notification.utils.Config;
import org.opengroup.osdu.notification.utils.IGoogleServiceAccount;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -56,7 +57,9 @@ import java.util.Map;
@RequestMapping("/push-handlers")
public class PubsubEndpoint {
@Autowired
private PubsubRequestBodyExtractor pubsubRequestBodyExtractor;
private IPubsubRequestBodyExtractor pubsubRequestBodyExtractor;
@Autowired
private IPubsubHandshakeHandler pubsubHandshakeHandler;
@Autowired
private ISignatureService signatureService;
@Autowired
......@@ -83,6 +86,10 @@ public class PubsubEndpoint {
@PostMapping("/records-changed")
@PreAuthorize("@authorizationFilter.hasAnyPermission('" + Config.OPS + "', '" + Config.PUBSUB + "')")
public ResponseEntity recordChanged() throws Exception {
if(this.pubsubRequestBodyExtractor.isHandshakeRequest()) {
this.pubsubHandshakeHandler.getHandshakeResponse();
}
String notificationId = this.pubsubRequestBodyExtractor.extractNotificationIdFromRequestBody();
String pubsubMessage = this.pubsubRequestBodyExtractor.extractDataFromRequestBody();
Map<String, String> headerAttributes = this.pubsubRequestBodyExtractor.extractAttributesFromRequestBody();
......
......@@ -15,9 +15,10 @@
*/
package org.opengroup.osdu.notification.di;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient;
import org.opengroup.osdu.notification.pubsub.PubsubRequestBodyExtractor;
import org.opengroup.osdu.notification.pubsub.IPubsubRequestBodyExtractor;
import org.opengroup.osdu.notification.utils.IAppProperties;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -39,7 +40,7 @@ public class CredentialHeadersProvider implements FactoryBean<DpsHeaders> {
private HttpServletRequest httpRequest;
@Autowired
private PubsubRequestBodyExtractor pubsubRequestBodyExtractor;
private IPubsubRequestBodyExtractor pubsubRequestBodyExtractor;
@Autowired
private IServiceAccountJwtClient serviceAccountJwtClient;
......
......@@ -19,7 +19,7 @@ package org.opengroup.osdu.notification.di;
import com.google.api.client.util.Strings;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.http.RequestInfo;
import org.opengroup.osdu.notification.pubsub.PubsubRequestBodyExtractor;
import org.opengroup.osdu.notification.pubsub.IPubsubRequestBodyExtractor;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
......@@ -40,7 +40,7 @@ public class RequestInfoExt extends RequestInfo {
private HttpServletRequest httpRequest;
@Inject
private PubsubRequestBodyExtractor requestBodyExtractor;
private IPubsubRequestBodyExtractor requestBodyExtractor;
@Inject
public RequestInfoExt(HttpServletRequest request) {
......
package org.opengroup.osdu.notification.pubsub;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
@Component
public interface IPubsubHandshakeHandler {
ResponseEntity getHandshakeResponse();
}
package org.opengroup.osdu.notification.pubsub;
import org.springframework.stereotype.Component;
import org.springframework.http.ResponseEntity;
import java.util.Map;
@Component
public interface IPubsubRequestBodyExtractor {
Map<String, String> extractAttributesFromRequestBody() ;
String extractDataFromRequestBody();
String extractNotificationIdFromRequestBody() ;
boolean isHandshakeRequest();
}
......@@ -36,7 +36,7 @@ import org.opengroup.osdu.core.common.notification.SubscriptionFactory;
import org.opengroup.osdu.core.common.notification.SubscriptionService;
import org.opengroup.osdu.notification.di.CredentialHeadersProvider;
import org.opengroup.osdu.notification.di.SubscriptionCacheFactory;
import org.opengroup.osdu.notification.pubsub.PubsubRequestBodyExtractor;
import org.opengroup.osdu.notification.pubsub.IPubsubRequestBodyExtractor;
import org.opengroup.osdu.notification.utils.IGoogleServiceAccount;
import org.powermock.modules.junit4.PowerMockRunner;
import org.springframework.http.ResponseEntity;
......@@ -54,7 +54,7 @@ import static org.mockito.Mockito.when;
@RunWith(PowerMockRunner.class)
public class PubsubEndpointTests {
@Mock
private PubsubRequestBodyExtractor pubsubRequestBodyExtractor;
private IPubsubRequestBodyExtractor pubsubRequestBodyExtractor;
@Mock
private ISignatureService signatureService;
@Mock
......
......@@ -26,7 +26,7 @@ import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.provider.interfaces.IAuthorizationService;
import org.opengroup.osdu.notification.di.RequestInfoExt;
import org.opengroup.osdu.notification.pubsub.PubsubRequestBodyExtractor;
import org.opengroup.osdu.notification.pubsub.IPubsubRequestBodyExtractor;
import org.opengroup.osdu.notification.utils.Config;
import org.opengroup.osdu.notification.utils.ServiceAccountValidator;
import org.powermock.modules.junit4.PowerMockRunner;
......@@ -59,7 +59,7 @@ public class AuthorizationFilterTest {
@Mock
private ServiceAccountValidator validator;
@Mock
private PubsubRequestBodyExtractor extractor;
private IPubsubRequestBodyExtractor extractor;
@InjectMocks
private AuthorizationFilter sut;
......
package org.opengroup.osdu.notification.provider.gcp.pubsub;
import org.opengroup.osdu.notification.pubsub.IPubsubHandshakeHandler;
import org.springframework.http.ResponseEntity;
public class PubsubHandshakeHandler implements IPubsubHandshakeHandler {
@Override
public ResponseEntity getHandshakeResponse() {
return null;
}
}
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.opengroup.osdu.notification.pubsub;
package org.opengroup.osdu.notification.provider.gcp.pubsub;
import com.google.common.base.Strings;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
......@@ -25,6 +25,7 @@ import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.opengroup.osdu.notification.pubsub.IPubsubRequestBodyExtractor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
......@@ -41,7 +42,7 @@ import java.util.stream.Stream;
@Component
@RequestScope
public class PubsubRequestBodyExtractor {
public class PubsubRequestBodyExtractor implements IPubsubRequestBodyExtractor {
private static final String INVALID_PUBSUB_MESSAGE = "Invalid pubsub message";
private static final Gson GSON = new Gson();
private MessageContent messageContent;
......@@ -80,6 +81,10 @@ public class PubsubRequestBodyExtractor {
return fullNotificationId[fullNotificationId.length - 1];
}
public boolean isHandshakeRequest() {
return false;
}
private MessageContent extractPubsubMessageFromRequestBody() {
if (this.root == null) {
this.root = this.extractRootJsonElementFromRequestBody();
......
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