use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe in project ddf by codice.
the class AbstractCswSource method configureEventService.
private void configureEventService() {
if (!cswSourceConfiguration.isRegisterForEvents()) {
LOGGER.debug("registerForEvents = false - do not configure site {} for events", this.getId());
removeEventServiceSubscription();
return;
}
if (StringUtils.isEmpty(cswSourceConfiguration.getEventServiceAddress())) {
LOGGER.debug("eventServiceAddress is NULL or empty - do not configure site {} for events", this.getId());
return;
}
// a single event should be sent)
if (filterlessSubscriptionId != null) {
LOGGER.debug("filterless subscription already configured for site " + filterlessSubscriptionId);
return;
}
initSubscribeClientFactory();
CswSubscribe cswSubscribe = subscribeClientFactory.getClientForSubject(getSystemSubject());
GetRecordsType request = createSubscriptionGetRecordsRequest();
try {
Response response = cswSubscribe.createRecordsSubscription(request);
if (Response.Status.OK.getStatusCode() == response.getStatus()) {
AcknowledgementType acknowledgementType = response.readEntity(AcknowledgementType.class);
filterlessSubscriptionId = acknowledgementType.getRequestId();
}
} catch (CswException e) {
LOGGER.info("Failed to register a subscription for events from csw source with id of " + this.getId());
}
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe in project ddf by codice.
the class AbstractCswSource method removeEventServiceSubscription.
private void removeEventServiceSubscription() {
if (filterlessSubscriptionId != null && subscribeClientFactory != null) {
CswSubscribe cswSubscribe = subscribeClientFactory.getClientForSubject(getSystemSubject());
try {
cswSubscribe.deleteRecordsSubscription(filterlessSubscriptionId);
} catch (CswException e) {
LOGGER.info("Failed to remove filterless subscription registered for id {} for csw source with id of {}", filterlessSubscriptionId, this.getId());
}
filterlessSubscriptionId = null;
}
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe in project ddf by codice.
the class TestCswSource method testRefreshWithRegisterForEvents.
@Test
public void testRefreshWithRegisterForEvents() throws Exception {
String subscriptionId = "subscriptionid";
String eventEndpoint = "https://ddf/services/csw/subscriptions";
CswSourceStub cswSource = (CswSourceStub) getCswSource(mockCsw, mockContext, "contentType");
CswSubscribe client = mock(CswSubscribe.class);
Response response = mock(Response.class);
AcknowledgementType ack = mock(AcknowledgementType.class);
when(client.createRecordsSubscription(any(GetRecordsType.class))).thenReturn(response);
when(response.getStatus()).thenReturn(200);
when(response.readEntity(any(Class.class))).thenReturn(ack);
when(ack.getRequestId()).thenReturn(subscriptionId);
when(cswSource.getSubscriberClientFactory().getClientForSubject(cswSource.getSubject())).thenReturn(client);
// Set Configuration Map
Map<String, Object> configuration = getConfigurationMap(cswSource);
configuration.put(cswSource.REGISTER_FOR_EVENTS, true);
configuration.put(cswSource.EVENT_SERVICE_ADDRESS, eventEndpoint);
// Call Refresh
cswSource.refresh(configuration);
// Get Configuration
CswSourceConfiguration cswSourceConfiguration = cswSource.cswSourceConfiguration;
// Assert Refresh Changes
Assert.assertTrue(cswSourceConfiguration.isRegisterForEvents());
Assert.assertEquals(cswSourceConfiguration.getEventServiceAddress(), eventEndpoint);
verify(ack).getRequestId();
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe in project ddf by codice.
the class TestCswSource method testRefreshWithUpdateRegisterForEvents.
@Test
public void testRefreshWithUpdateRegisterForEvents() throws Exception {
String subscriptionId = "subscriptionid";
String eventEndpoint = "https://ddf/services/csw/subscriptions";
CswSourceStub cswSource = (CswSourceStub) getCswSource(mockCsw, mockContext, "contentType");
cswSource.filterlessSubscriptionId = subscriptionId;
CswSubscribe client = mock(CswSubscribe.class);
Response response = mock(Response.class);
AcknowledgementType ack = mock(AcknowledgementType.class);
when(client.createRecordsSubscription(any(GetRecordsType.class))).thenReturn(response);
when(response.getStatus()).thenReturn(200);
when(response.readEntity(any(Class.class))).thenReturn(ack);
when(ack.getRequestId()).thenReturn(subscriptionId);
when(cswSource.getSubscriberClientFactory().getClientForSubject(cswSource.getSubject())).thenReturn(client);
cswSource.cswSourceConfiguration.setRegisterForEvents(true);
cswSource.cswSourceConfiguration.setEventServiceAddress(eventEndpoint + "/original");
// Set Configuration Map
Map<String, Object> configuration = getConfigurationMap(cswSource);
configuration.put(cswSource.REGISTER_FOR_EVENTS, true);
configuration.put(cswSource.EVENT_SERVICE_ADDRESS, eventEndpoint);
// Call Refresh
cswSource.refresh(configuration);
// Get Configuration
CswSourceConfiguration cswSourceConfiguration = cswSource.cswSourceConfiguration;
// Assert Refresh Changes
Assert.assertTrue(cswSourceConfiguration.isRegisterForEvents());
Assert.assertEquals(cswSourceConfiguration.getEventServiceAddress(), eventEndpoint);
verify(client).deleteRecordsSubscription(subscriptionId);
verify(ack).getRequestId();
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe in project ddf by codice.
the class TestCswSource method testRefreshWithUnregisterForEvents.
@Test
public void testRefreshWithUnregisterForEvents() throws Exception {
String subscriptionId = "subscriptionid";
String eventEndpoint = "https://ddf/services/csw/subscriptions";
CswSourceStub cswSource = (CswSourceStub) getCswSource(mockCsw, mockContext, "contentType");
cswSource.filterlessSubscriptionId = subscriptionId;
CswSubscribe client = mock(CswSubscribe.class);
Response response = mock(Response.class);
AcknowledgementType ack = mock(AcknowledgementType.class);
when(client.createRecordsSubscription(any(GetRecordsType.class))).thenReturn(response);
when(response.getStatus()).thenReturn(200);
when(response.readEntity(any(Class.class))).thenReturn(ack);
when(ack.getRequestId()).thenReturn(subscriptionId);
when(cswSource.getSubscriberClientFactory().getClientForSubject(cswSource.getSubject())).thenReturn(client);
cswSource.cswSourceConfiguration.setRegisterForEvents(true);
cswSource.cswSourceConfiguration.setEventServiceAddress(eventEndpoint);
// Set Configuration Map
Map<String, Object> configuration = getConfigurationMap(cswSource);
configuration.put(cswSource.REGISTER_FOR_EVENTS, false);
configuration.put(cswSource.EVENT_SERVICE_ADDRESS, eventEndpoint);
// Call Refresh
cswSource.refresh(configuration);
// Get Configuration
CswSourceConfiguration cswSourceConfiguration = cswSource.cswSourceConfiguration;
// Assert Refresh Changes
Assert.assertFalse(cswSourceConfiguration.isRegisterForEvents());
Assert.assertEquals(cswSourceConfiguration.getEventServiceAddress(), eventEndpoint);
verify(client).deleteRecordsSubscription(subscriptionId);
}
Aggregations