Search in sources :

Example 1 with CswSubscription

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;
}
Also used : Configuration(org.osgi.service.cm.Configuration) LogSanitizer(org.codice.ddf.log.sanitizer.LogSanitizer) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) IOException(java.io.IOException) CswSubscription(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) JAXBException(javax.xml.bind.JAXBException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) IOException(java.io.IOException) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 2 with CswSubscription

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);
}
Also used : Dictionary(java.util.Dictionary) Configuration(org.osgi.service.cm.Configuration) SecurityManager(ddf.security.service.SecurityManager) SecureCxfClientFactory(org.codice.ddf.cxf.client.SecureCxfClientFactory) ClientBuilderFactory(org.codice.ddf.cxf.client.ClientBuilderFactory) Subscription(ddf.catalog.event.Subscription) CswSubscription(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription) ServiceRegistration(org.osgi.framework.ServiceRegistration) ClientBuilderImpl(org.codice.ddf.cxf.client.impl.ClientBuilderImpl) TransformerManager(org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager) QueryRequest(ddf.catalog.operation.QueryRequest) InputStream(java.io.InputStream) Bundle(org.osgi.framework.Bundle) OAuthSecurity(org.codice.ddf.cxf.oauth.OAuthSecurity) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) WebClient(org.apache.cxf.jaxrs.client.WebClient) ServiceReference(org.osgi.framework.ServiceReference) Filter(org.osgi.framework.Filter) FileOutputStream(java.io.FileOutputStream) EventProcessor(ddf.catalog.event.EventProcessor) SamlSecurity(org.codice.ddf.security.jaxrs.SamlSecurity) CswSubscription(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) BundleContext(org.osgi.framework.BundleContext) SecurityLogger(ddf.security.audit.SecurityLogger) Before(org.junit.Before)

Example 3 with CswSubscription

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;
}
Also used : CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) CswSubscription(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription) Subscription(ddf.catalog.event.Subscription) CswSubscription(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription) DictionaryMap(org.codice.ddf.configuration.DictionaryMap) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Aggregations

CswSubscription (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription)3 ServiceRegistration (org.osgi.framework.ServiceRegistration)3 Subscription (ddf.catalog.event.Subscription)2 CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)2 Configuration (org.osgi.service.cm.Configuration)2 EventProcessor (ddf.catalog.event.EventProcessor)1 QueryRequest (ddf.catalog.operation.QueryRequest)1 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)1 SecurityLogger (ddf.security.audit.SecurityLogger)1 SecurityManager (ddf.security.service.SecurityManager)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Dictionary (java.util.Dictionary)1 JAXBException (javax.xml.bind.JAXBException)1 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)1 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)1 WebClient (org.apache.cxf.jaxrs.client.WebClient)1 DictionaryMap (org.codice.ddf.configuration.DictionaryMap)1 ClientBuilderFactory (org.codice.ddf.cxf.client.ClientBuilderFactory)1