use of ddf.catalog.event.Subscription 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 ddf.catalog.event.Subscription in project ddf by codice.
the class ListCommand method printSubscription.
private void printSubscription(Map.Entry<String, ServiceReference<Subscription>> entry) {
PrintStream console = System.out;
Subscription subscription = bundleContext.getService(entry.getValue());
String rowColor = "";
if (subscription != null && subscription.getDeliveryMethod() instanceof Pingable && !((Pingable) subscription.getDeliveryMethod()).ping()) {
rowColor = RED_CONSOLE_COLOR;
}
console.println(String.format("%s%s\t %s%s", rowColor, entry.getKey(), entry.getValue().getProperty("event-endpoint"), DEFAULT_CONSOLE_COLOR));
}
use of ddf.catalog.event.Subscription in project ddf by codice.
the class DummyPreSubscriptionPlugin method process.
public Subscription process(Subscription input) throws PluginExecutionException {
String methodName = "process";
LOGGER.trace(ENTERING, methodName);
Subscription newSubscription = input;
if (input != null) {
FilterDelegate<Filter> delegate = new CopyFilterDelegate(filterBuilder);
try {
// Make a defensive copy of the original filter (just in case anyone else expects
// it to remain unmodified)
Filter copiedFilter = filterAdapter.adapt(input, delegate);
// Define the extra query clause(s) to add to the copied filter
Filter extraFilter = filterBuilder.attribute(Metacard.ANY_TEXT).like().text("CAN");
// AND the extra query clause(s) to the copied filter
Filter modifiedFilter = filterBuilder.allOf(copiedFilter, extraFilter);
// Create a new subscription with the modified filter
newSubscription = new SubscriptionImpl(modifiedFilter, input.getDeliveryMethod(), input.getSourceIds(), input.isEnterprise());
} catch (UnsupportedQueryException e) {
throw new PluginExecutionException(e);
}
}
LOGGER.trace(EXITING, methodName);
return newSubscription;
}
use of ddf.catalog.event.Subscription in project ddf by codice.
the class ListCommandTest method testListNoArgsSourceAndEnterpriseSubscriptionFound.
/**
* Test subscriptions:list command with source and enterprise subscriptions. Make sure enterprise
* and source id info is printed.
*
* @throws Exception
*/
@Test
public void testListNoArgsSourceAndEnterpriseSubscriptionFound() throws Exception {
ListCommand listCommand = new ListCommand();
BundleContext bundleContext = mock(BundleContext.class);
listCommand.setBundleContext(bundleContext);
Subscription sourceSubscription = mock(Subscription.class);
when(sourceSubscription.getSourceIds()).thenReturn(Collections.singleton("source.id"));
when(sourceSubscription.isEnterprise()).thenReturn(false);
ServiceReference<Subscription> sourceSubscriptionReference = mock(ServiceReference.class);
when(sourceSubscriptionReference.getPropertyKeys()).thenReturn(new String[] { SUBSCRIPTION_ID_PROPERTY_KEY });
when(sourceSubscriptionReference.getProperty("subscription-id")).thenReturn(MY_SUBSCRIPTION_ID);
when(bundleContext.getService(sourceSubscriptionReference)).thenReturn(sourceSubscription);
Subscription enterpriseSubscription = mock(Subscription.class);
when(enterpriseSubscription.getSourceIds()).thenReturn(null);
when(enterpriseSubscription.isEnterprise()).thenReturn(true);
ServiceReference enterpriseSubscriptionReference = mock(ServiceReference.class);
when(enterpriseSubscriptionReference.getPropertyKeys()).thenReturn(new String[] { SUBSCRIPTION_ID_PROPERTY_KEY });
when(enterpriseSubscriptionReference.getProperty(SUBSCRIPTION_ID_PROPERTY_KEY)).thenReturn(YOUR_SUBSCRIPTION_ID);
when(bundleContext.getService(enterpriseSubscriptionReference)).thenReturn(enterpriseSubscription);
ServiceReference[] refs = new ServiceReference[] { sourceSubscriptionReference, enterpriseSubscriptionReference };
when(bundleContext.getServiceReferences(eq(SubscriptionsCommand.SERVICE_PID), isNull())).thenReturn(refs);
PrintStream realSystemOut = System.out;
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
System.setOut(new PrintStream(buffer));
// when
listCommand.execute();
/* cleanup */
System.setOut(realSystemOut);
// then
List<String> linesWithText = getConsoleOutputText(buffer);
assertThat(linesWithText.size(), is(4));
assertThat(linesWithText, hasItems(containsString("Total subscriptions found: 2"), allOf(containsString(MY_SUBSCRIPTION_ID), containsString("false"), containsString("source.id")), allOf(containsString(YOUR_SUBSCRIPTION_ID), containsString("true"))));
buffer.close();
}
use of ddf.catalog.event.Subscription 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