Skip to content
Snippets Groups Projects
Commit 19677ab8 authored by Hema Vishnu Pola [Microsoft]'s avatar Hema Vishnu Pola [Microsoft]
Browse files

Merge branch 'creating_spi_for_pubsubhandshake_pubsubrequestextractor' into 'master'

SPI for PubSubRequestExtractor and handshake request handler.

See merge request !10
parents 8424e360 88be5eda
No related branches found
No related tags found
1 merge request!10SPI for PubSubRequestExtractor and handshake request handler.
Pipeline #6511 failed
Showing
with 62 additions and 14 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.provider.interfaces.IPubsubHandshakeHandler;
import org.opengroup.osdu.notification.provider.interfaces.IPubsubRequestBodyExtractor;
import org.opengroup.osdu.notification.utils.Config;
import org.opengroup.osdu.notification.provider.interfaces.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,11 @@ public class PubsubEndpoint {
@PostMapping("/records-changed")
@PreAuthorize("@authorizationFilter.hasAnyPermission('" + Config.OPS + "', '" + Config.PUBSUB + "')")
public ResponseEntity recordChanged() throws Exception {
if(this.pubsubRequestBodyExtractor.isHandshakeRequest()) {
String handshakeResponse = this.pubsubHandshakeHandler.getHandshakeResponse();
return ResponseEntity.ok(handshakeResponse);
}
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.provider.interfaces.IPubsubRequestBodyExtractor;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
......@@ -38,7 +39,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.provider.interfaces.IPubsubRequestBodyExtractor;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
......@@ -27,8 +27,6 @@ import org.springframework.web.context.annotation.RequestScope;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -40,7 +38,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.provider.interfaces;
public interface IPubsubHandshakeHandler {
String getHandshakeResponse();
}
package org.opengroup.osdu.notification.provider.interfaces;
import org.springframework.stereotype.Component;
import org.springframework.http.ResponseEntity;
import java.util.Map;
public interface IPubsubRequestBodyExtractor {
Map<String, String> extractAttributesFromRequestBody() ;
String extractDataFromRequestBody();
String extractNotificationIdFromRequestBody() ;
boolean isHandshakeRequest();
}
......@@ -36,8 +36,8 @@ 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.provider.interfaces.IGoogleServiceAccount;
import org.opengroup.osdu.notification.provider.interfaces.IPubsubRequestBodyExtractor;
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.provider.interfaces.IPubsubRequestBodyExtractor;
import org.opengroup.osdu.notification.utils.Config;
import org.opengroup.osdu.notification.provider.interfaces.IServiceAccountValidator;
import org.powermock.modules.junit4.PowerMockRunner;
......@@ -62,7 +62,7 @@ public class AuthorizationFilterTest {
@Mock
private IServiceAccountValidator 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.provider.interfaces.IPubsubHandshakeHandler;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
@Component
@Lazy
public class PubsubHandshakeHandler implements IPubsubHandshakeHandler {
@Override
public String getHandshakeResponse() {
return null;
}
}
\ No newline at end of file
......@@ -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.provider.interfaces.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