use of org.osgi.service.cm.Configuration in project ddf by codice.
the class ManagedServiceFactoryConfigurationFile method createConfig.
@Override
public void createConfig() throws ConfigurationFileException {
String factoryPid = getFactoryPid();
try {
Configuration configuration = configAdmin.createFactoryConfiguration(factoryPid, null);
configuration.update(properties);
} catch (IOException e) {
String message = String.format("Unable to get or update Configuration for factory pid [%s].", factoryPid);
LOGGER.info(message, e);
throw new ConfigurationFileException(message, e);
}
}
use of org.osgi.service.cm.Configuration in project ddf by codice.
the class CswSubscriptionEndpoint method getSubscriptionConfiguration.
private Configuration getSubscriptionConfiguration(String subscriptionUuid) {
String methodName = "getSubscriptionConfiguration";
LOGGER.trace("ENTERING: {}", methodName);
String filterStr = getSubscriptionUuidFilter(subscriptionUuid);
LOGGER.debug("filterStr = {}", filterStr);
Configuration config = null;
try {
org.osgi.framework.Filter filter = getBundleContext().createFilter(filterStr);
LOGGER.debug("filter.toString() = {}", filter.toString());
ConfigurationAdmin configAdmin = getConfigAdmin();
if (configAdmin != null) {
Configuration[] configs = configAdmin.listConfigurations(filter.toString());
if (configs == null) {
LOGGER.debug("Did NOT find a configuration for filter {}", filterStr);
} else if (configs.length != 1) {
LOGGER.debug("Found multiple configurations for filter {}", filterStr);
} else {
LOGGER.debug("Found exactly one configuration for filter {}", filterStr);
config = configs[0];
}
}
} catch (InvalidSyntaxException e) {
LOGGER.debug("Invalid syntax for filter used for searching configuration instances", e);
} catch (IOException e) {
LOGGER.debug("IOException trying to list configurations for filter {}", filterStr, e);
}
LOGGER.trace("EXITING: {}", methodName);
return config;
}
use of org.osgi.service.cm.Configuration in project ddf by codice.
the class CswSubscriptionEndpoint method deleteCswSubscription.
private synchronized CswSubscription deleteCswSubscription(String subscriptionId) throws CswException {
String methodName = "deleteCswSubscription";
LOGGER.trace("ENTERING: {}", methodName);
LOGGER.trace("subscriptionId = {}", subscriptionId);
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: {}", subscriptionId);
ServiceRegistration sr = (ServiceRegistration) registeredSubscriptions.remove(subscriptionId);
if (sr != null) {
sr.unregister();
} else {
LOGGER.debug("No ServiceRegistration found for subscription: {}", subscriptionId);
}
Configuration subscriptionConfig = getSubscriptionConfiguration(subscriptionId);
try {
if (subscriptionConfig != null) {
LOGGER.debug("Deleting subscription for subscriptionId = {}", subscriptionId);
subscriptionConfig.delete();
} else {
LOGGER.debug("subscriptionConfig is NULL for ID = {}", subscriptionId);
}
} 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 {}", subscriptionId, e);
}
LOGGER.trace("EXITING: {} (status = {})", methodName, false);
return subscription;
}
use of org.osgi.service.cm.Configuration in project ddf by codice.
the class CswSubscriptionEndpoint method persistSubscription.
/**
* Persist the subscription to the OSGi ConfigAdmin service. Persisted registeredSubscriptions can then be restored if DDF
* is restarted after a DDF outage or DDF is shutdown.
* Pass in client-provided subscriptionId and subscription UUID because the filter XML to be persisted for this subscription will be used to
* restore this subscription and should consist of the exact values the
* client originally provided.
*/
private void persistSubscription(CswSubscription subscription, String deliveryMethodUrl, String subscriptionUuid) {
String methodName = "persistSubscription";
LOGGER.trace("ENTERING: {}", methodName);
try {
StringWriter sw = new StringWriter();
CswQueryFactory.getJaxBContext().createMarshaller().marshal(objectFactory.createGetRecords(subscription.getOriginalRequest()), sw);
String filterXml = sw.toString();
// Store filter XML, deliveryMethod URL, this endpoint's factory PID, and subscription ID into OSGi CongiAdmin
if (filterXml != null) {
Configuration config = getConfigAdmin().createFactoryConfiguration(CswSubscriptionConfigFactory.FACTORY_PID, null);
Dictionary<String, String> props = new Hashtable<>();
props.put(CswSubscriptionConfigFactory.SUBSCRIPTION_ID, subscriptionUuid);
props.put(CswSubscriptionConfigFactory.FILTER_XML, filterXml);
props.put(CswSubscriptionConfigFactory.DELIVERY_METHOD_URL, deliveryMethodUrl);
props.put(CswSubscriptionConfigFactory.SUBSCRIPTION_UUID, subscriptionUuid);
LOGGER.debug("Done adding persisting subscription to ConfigAdmin");
config.update(props);
}
} catch (JAXBException | IOException e) {
LOGGER.debug("Unable to persist subscription {}", subscriptionUuid, e);
}
LOGGER.trace("EXITING: {}", methodName);
}
use of org.osgi.service.cm.Configuration in project ddf by codice.
the class TestCatalog method testIngestPlugin.
@Test
public void testIngestPlugin() throws Exception {
//ingest a data set to make sure we don't have any issues initially
String id1 = ingestGeoJson(getFileContent(JSON_RECORD_RESOURCE_PATH + "/SimpleGeoJsonRecord"));
String xPath1 = format(METACARD_X_PATH, id1);
//verify ingest by querying
ValidatableResponse response = executeOpenSearch("xml", "q=*");
response.body(hasXPath(xPath1));
//change ingest plugin role to ingest
CatalogPolicyProperties catalogPolicyProperties = new CatalogPolicyProperties();
catalogPolicyProperties.put("createPermissions", new String[] { "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role=ingest" });
Configuration config = configAdmin.getConfiguration("org.codice.ddf.catalog.security.CatalogPolicy", null);
Dictionary<String, Object> configProps = new Hashtable<>(catalogPolicyProperties);
config.update(configProps);
getServiceManager().waitForAllBundles();
//try ingesting again - it should fail this time
given().body(getFileContent(JSON_RECORD_RESOURCE_PATH + "/SimpleGeoJsonRecord")).header(HttpHeaders.CONTENT_TYPE, "application/json").expect().log().all().statusCode(400).when().post(REST_PATH.getUrl());
//verify query for first id works
response = executeOpenSearch("xml", "q=*");
response.body(hasXPath(xPath1));
//revert to original configuration
configProps.put("createPermissions", new String[] { "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role=guest" });
config.update(configProps);
getServiceManager().waitForAllBundles();
deleteMetacard(id1);
}
Aggregations