use of org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription in project ddf by codice.
the class CswSubscriptionEndpoint method deleteCswSubscription.
private synchronized CswSubscription deleteCswSubscription(String subscriptionId) throws CswException {
String methodName = "deleteCswSubscription";
LogSanitizer logSanitizedId = LogSanitizer.sanitize(subscriptionId);
LOGGER.trace(ENTERING_STR, methodName);
LOGGER.trace("subscriptionId = {}", logSanitizedId);
if (StringUtils.isEmpty(subscriptionId)) {
throw new CswException("Unable to delete subscription because subscription ID is null or empty");
}
CswSubscription subscription = getSubscription(subscriptionId);
try {
LOGGER.debug("Removing (unregistering) subscription: {}", logSanitizedId);
ServiceRegistration sr = registeredSubscriptions.remove(subscriptionId);
if (sr != null) {
sr.unregister();
} else {
LOGGER.debug("No ServiceRegistration found for subscription: {}", logSanitizedId);
}
Configuration subscriptionConfig = getSubscriptionConfiguration(subscriptionId);
try {
if (subscriptionConfig != null) {
LOGGER.debug("Deleting subscription for subscriptionId = {}", logSanitizedId);
subscriptionConfig.delete();
} else {
LOGGER.debug("subscriptionConfig is NULL for ID = {}", logSanitizedId);
}
} catch (IOException e) {
LOGGER.debug("IOException trying to delete subscription's configuration for subscription ID {}", subscriptionId, e);
}
LOGGER.debug("Subscription removal complete");
} catch (Exception e) {
LOGGER.debug("Could not delete subscription for {}", logSanitizedId, e);
}
LOGGER.trace("EXITING: {} (status = {})", methodName, false);
return subscription;
}
use of org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription in project ddf by codice.
the class CswSubscriptionEndpointTest method setUp.
@Before
public void setUp() throws Exception {
systemKeystoreFile = temporaryFolder.newFile("serverKeystore.jks");
FileOutputStream systemKeyOutStream = new FileOutputStream(systemKeystoreFile);
InputStream systemKeyStream = CswSubscriptionEndpointTest.class.getResourceAsStream("/serverKeystore.jks");
IOUtils.copy(systemKeyStream, systemKeyOutStream);
systemTruststoreFile = temporaryFolder.newFile("serverTruststore.jks");
FileOutputStream systemTrustOutStream = new FileOutputStream(systemTruststoreFile);
InputStream systemTrustStream = CswSubscriptionEndpointTest.class.getResourceAsStream("/serverTruststore.jks");
IOUtils.copy(systemTrustStream, systemTrustOutStream);
System.setProperty(SecurityConstants.KEYSTORE_TYPE, "jks");
System.setProperty(SecurityConstants.TRUSTSTORE_TYPE, "jks");
System.setProperty("ddf.home", "");
System.setProperty(SecurityConstants.KEYSTORE_PATH, systemKeystoreFile.getAbsolutePath());
System.setProperty(SecurityConstants.TRUSTSTORE_PATH, systemTruststoreFile.getAbsolutePath());
System.setProperty(SecurityConstants.KEYSTORE_PASSWORD, password);
System.setProperty(SecurityConstants.TRUSTSTORE_PASSWORD, password);
eventProcessor = mock(EventProcessor.class);
mockInputManager = mock(TransformerManager.class);
mockContext = mock(BundleContext.class);
mockMimeTypeManager = mock(TransformerManager.class);
mockSchemaManager = mock(TransformerManager.class);
validator = mock(Validator.class);
queryFactory = mock(CswQueryFactory.class);
query = mock(QueryRequest.class);
when(queryFactory.getQuery(any(GetRecordsType.class))).thenReturn(query);
serviceRegistration = mock(ServiceRegistration.class);
subscriptionReference = mock(ServiceReference.class);
bundle = mock(Bundle.class);
osgiFilter = mock(Filter.class);
configAdminRef = mock(ServiceReference.class);
configAdmin = mock(ConfigurationAdmin.class);
config = mock(Configuration.class);
SecureCxfClientFactory mockFactory = mock(SecureCxfClientFactory.class);
clientBuilderFactory = mock(ClientBuilderFactory.class);
ClientBuilder<WebClient> clientBuilder = new ClientBuilderImpl<WebClient>(mock(OAuthSecurity.class), mock(SamlSecurity.class), mock(SecurityLogger.class), mock(SecurityManager.class)) {
@Override
public SecureCxfClientFactory<WebClient> build() {
return mockFactory;
}
};
when(clientBuilderFactory.<WebClient>getClientBuilder()).thenReturn(clientBuilder);
Configuration[] configArry = { config };
defaultRequest = createDefaultGetRecordsRequest();
subscription = new CswSubscription(mockMimeTypeManager, defaultRequest.get202RecordsType(), query, clientBuilderFactory, security);
when(osgiFilter.toString()).thenReturn(FILTER_STR);
doReturn(serviceRegistration).when(mockContext).registerService(eq(Subscription.class.getName()), any(Subscription.class), any(Dictionary.class));
doReturn(configAdminRef).when(mockContext).getServiceReference(eq(ConfigurationAdmin.class.getName()));
when(serviceRegistration.getReference()).thenReturn(subscriptionReference);
doReturn(bundle).when(subscriptionReference).getBundle();
when(subscriptionReference.getBundle()).thenReturn(bundle);
when(bundle.getBundleId()).thenReturn(bundleId);
when(mockContext.createFilter(anyString())).thenReturn(osgiFilter);
when(mockContext.getService(eq(configAdminRef))).thenReturn(configAdmin);
when(mockContext.getService(eq(subscriptionReference))).thenReturn(subscription);
when(configAdmin.listConfigurations(eq(FILTER_STR))).thenReturn(configArry);
when(configAdmin.createFactoryConfiguration(anyString(), isNull())).thenReturn(config);
cswSubscriptionEndpoint = new CswSubscriptionEndpointStub(eventProcessor, mockMimeTypeManager, mockSchemaManager, mockInputManager, validator, queryFactory, mockContext, clientBuilderFactory, security);
}
use of org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription in project ddf by codice.
the class CswSubscriptionEndpoint method addOrUpdateSubscription.
public synchronized String addOrUpdateSubscription(GetRecordsType request, boolean persistSubscription) throws CswException {
String methodName = "createSubscription";
LOGGER.trace("ENTERING: {} (persistSubscription = {})", methodName, persistSubscription);
if (request.getResponseHandler() == null || request.getResponseHandler().isEmpty() || StringUtils.isEmpty(request.getResponseHandler().get(0))) {
throw new CswException("Unable to create subscription because deliveryMethodUrl is null or empty");
}
String deliveryMethodUrl = request.getResponseHandler().get(0);
String subscriptionUuid = getSubscriptionUuid(request.getRequestId());
LOGGER.debug("subscriptionUuid = {}", subscriptionUuid);
request.setRequestId(subscriptionUuid);
// to registry
if (registeredSubscriptions.containsKey(subscriptionUuid)) {
LOGGER.debug("Delete existing subscription {} for re-creation", subscriptionUuid);
deleteCswSubscription(subscriptionUuid);
}
CswSubscription sub = createSubscription(request);
Dictionary<String, String> props = new DictionaryMap<>();
props.put("subscription-id", subscriptionUuid);
props.put("event-endpoint", request.getResponseHandler().get(0));
LOGGER.debug("Registering Subscription");
ServiceRegistration serviceRegistration = getBundleContext().registerService(Subscription.class.getName(), sub, props);
if (serviceRegistration != null) {
LOGGER.debug("Subscription registered with bundle ID = {} ", serviceRegistration.getReference().getBundle().getBundleId());
registeredSubscriptions.put(subscriptionUuid, serviceRegistration);
// client originally provided.
if (persistSubscription) {
persistSubscription(sub, deliveryMethodUrl, subscriptionUuid);
}
} else {
LOGGER.debug("Subscription registration failed");
}
LOGGER.trace(EXITING_STR, methodName);
return subscriptionUuid;
}
Aggregations