List of usage examples for java.util Dictionary put
public abstract V put(K key, V value);
From source file:org.codice.ddf.registry.publication.manager.RegistryPublicationManagerTest.java
@Test public void testHandleEventNoRegistryId() throws Exception { Metacard mcard = getRegistryMetacard(null); Dictionary<String, Object> eventProperties = new Hashtable<>(); eventProperties.put(METACARD_PROPERTY, mcard); Event event = new Event(CREATED_TOPIC, eventProperties); publicationManager.handleEvent(event); assertThat(publicationManager.getPublications().size(), is(0)); }
From source file:org.codice.ddf.registry.publication.manager.RegistryPublicationManagerTest.java
@Test public void testHandleEventBlankRegistryId() throws Exception { Metacard mcard = getRegistryMetacard(""); Dictionary<String, Object> eventProperties = new Hashtable<>(); eventProperties.put(METACARD_PROPERTY, mcard); Event event = new Event(CREATED_TOPIC, eventProperties); publicationManager.handleEvent(event); assertThat(publicationManager.getPublications().size(), is(0)); }
From source file:org.openhab.io.rest.RESTApplication.java
private Dictionary<String, String> getJerseyServletParams() { Dictionary<String, String> jerseyServletParams = new Hashtable<String, String>(); jerseyServletParams.put("javax.ws.rs.Application", RESTApplication.class.getName()); jerseyServletParams.put("org.atmosphere.core.servlet-mapping", RESTApplication.REST_SERVLET_ALIAS + "/*"); jerseyServletParams.put("org.atmosphere.useWebSocket", "true"); jerseyServletParams.put("org.atmosphere.useNative", "true"); jerseyServletParams.put("org.atmosphere.cpr.AtmosphereInterceptor.disableDefaults", "true"); // use the default interceptors without PaddingAtmosphereInterceptor // see: https://groups.google.com/forum/#!topic/openhab/Z-DVBXdNiYE final String[] interceptors = { "org.atmosphere.interceptor.CorsInterceptor", "org.atmosphere.interceptor.CacheHeadersInterceptor", "org.atmosphere.interceptor.AndroidAtmosphereInterceptor", "org.atmosphere.interceptor.SSEAtmosphereInterceptor", "org.atmosphere.interceptor.JSONPAtmosphereInterceptor", "org.atmosphere.interceptor.JavaScriptProtocol", "org.atmosphere.interceptor.OnDisconnectInterceptor" }; jerseyServletParams.put("org.atmosphere.cpr.AtmosphereInterceptor", StringUtils.join(interceptors, ",")); // The BroadcasterCache is set in ResourceStateChangeListener.registerItems(), because otherwise // it gets somehow overridden by other registered servlets (e.g. the CV-bundle) //jerseyServletParams.put("org.atmosphere.cpr.broadcasterCacheClass", "org.atmosphere.cache.UUIDBroadcasterCache"); jerseyServletParams.put("org.atmosphere.cpr.broadcasterLifeCyclePolicy", "IDLE_DESTROY"); jerseyServletParams.put("org.atmosphere.cpr.CometSupport.maxInactiveActivity", "3000000"); jerseyServletParams.put("org.atmosphere.cpr.broadcaster.maxProcessingThreads", "10"); // Default: unlimited! jerseyServletParams.put("org.atmosphere.cpr.broadcaster.maxAsyncWriteThreads", "10"); // Default: 200 on atmos 2.2 jerseyServletParams.put("com.sun.jersey.spi.container.ResourceFilter", "org.atmosphere.core.AtmosphereFilter"); // required because of bug http://java.net/jira/browse/JERSEY-361 jerseyServletParams.put(FeaturesAndProperties.FEATURE_XMLROOTELEMENT_PROCESSING, "true"); return jerseyServletParams; }
From source file:org.eclipse.gyrex.model.common.provider.BaseModelManager.java
/** * Registers the metrics on behalf of the bundle which loaded this class. * /* ww w . j ava 2s . co m*/ * @throws IllegalArgumentException * if the class was not loaded by a bundle class loader * @throws IllegalStateException * if the bundle which loaded the class has no valid bundle * context */ private void registerMetrics() throws IllegalArgumentException, IllegalStateException { // get bundle context // TODO: we might need to wrap this into a privileged call final Bundle bundle = FrameworkUtil.getBundle(getClass()); final BundleContext bundleContext = null != bundle ? bundle.getBundleContext() : null; if (null == bundleContext) { throw new IllegalStateException("Unable to determin bundle context for class '" + getClass().getName() + "'. Please ensure that this class was loaded by a bundle which is either STARTING, ACTIVE or STOPPING."); } // create properties final Dictionary<String, Object> properties = new Hashtable<String, Object>(2); properties.put(Constants.SERVICE_VENDOR, this.getClass().getName()); properties.put(Constants.SERVICE_DESCRIPTION, "Metrics for model manager implementation '" + this.getClass().getName() + "'."); properties.put(IRepositoryContstants.SERVICE_PROPERTY_REPOSITORY_ID, getRepository().getRepositoryId()); if (StringUtils.isNotBlank(getRepository().getDescription())) { properties.put(IRepositoryContstants.SERVICE_PROPERTY_REPOSITORY_DESCRIPTION, getRepository().getDescription()); } properties.put(IRuntimeContextConstants.SERVICE_PROPERTY_CONTEXT_PATH, getContext().getContextPath().toString()); // register service metricsRegistration = bundleContext.registerService(MetricSet.class.getName(), metrics, properties); }
From source file:org.ops4j.pax.web.service.internal.Activator.java
/** * Registers a managed service to listen on configuration updates. * * @param bundleContext bundle context to use for registration */// www.j a v a 2s.c o m private void createManagedService(final BundleContext bundleContext) { final ManagedService managedService = new ManagedService() { /** * Sets the resolver on sever controller. * * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary) */ public void updated(final Dictionary config) throws ConfigurationException { try { m_lock.lock(); final PropertyResolver resolver; if (config == null) { resolver = new BundleContextPropertyResolver(bundleContext, new DefaultPropertyResolver()); } else { resolver = new DictionaryPropertyResolver(config, new BundleContextPropertyResolver(bundleContext, new DefaultPropertyResolver())); } final ConfigurationImpl configuration = new ConfigurationImpl(resolver); m_serverController.configure(configuration); determineServiceProperties(config, configuration, m_serverController.getHttpPort(), m_serverController.getHttpSecurePort()); if (m_httpServiceFactoryReg != null) { m_httpServiceFactoryReg.setProperties(m_httpServiceFactoryProps); } } finally { m_lock.unlock(); } } }; final Dictionary<String, String> props = new Hashtable<String, String>(); props.put(Constants.SERVICE_PID, PID); bundleContext.registerService(ManagedService.class.getName(), managedService, props); try { m_lock.lock(); if (!m_serverController.isConfigured()) { try { managedService.updated(null); } catch (ConfigurationException ignore) { // this should never happen LOG.error("Internal error. Cannot set initial configuration resolver.", ignore); } } } finally { m_lock.unlock(); } }
From source file:org.ops4j.pax.runner.platform.internal.Activator.java
/** * Registers a managed service to listen on configuration updates. *///w w w .j av a 2s .c om private void registerManagedService() { final Dictionary<String, String> props = new Hashtable<String, String>(); props.put(Constants.SERVICE_PID, ServiceConstants.PID); m_managedServiceReg = m_bundleContext.registerService(ManagedService.class.getName(), new ManagedService() { /** * Sets the resolver for each registred platform. * * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary) */ public void updated(final Dictionary config) throws ConfigurationException { m_lock.lock(); try { m_config = config; for (PlatformImpl platform : m_platforms.values()) { if (m_config == null) { platform.setResolver(new BundleContextPropertyResolver(m_bundleContext)); } else { platform.setResolver(new DictionaryPropertyResolver(config, new BundleContextPropertyResolver(m_bundleContext))); } } } finally { m_lock.unlock(); } } }, props); }
From source file:org.ops4j.pax.jdbc.pool.dbcp2.impl.ds.PooledDataSourceFactory.java
public Dictionary<String, Object> createPropsForPoolingDataSourceFactory( ServiceReference<DataSourceFactory> reference) { Dictionary<String, Object> props = new Hashtable<String, Object>(); for (String key : reference.getPropertyKeys()) { if (!"service.id".equals(key)) { props.put(key, reference.getProperty(key)); }/*from w w w. ja v a 2 s .c o m*/ } props.put("pooled", "true"); props.put(DataSourceFactory.OSGI_JDBC_DRIVER_NAME, getPoolDriverName(reference)); return props; }
From source file:org.wso2.carbon.appfactory.application.mgt.internal.ApplicationManagementServiceComponent.java
protected void activate(ComponentContext context) { BundleContext bundleContext = context.getBundleContext(); bundleContext.registerService(ApplicationUserManagementService.class.getName(), new ApplicationUserManagementService(), null); AppFactoryConfiguration appFactoryConfiguration = Util.getConfiguration(); int priority = -1; if (Boolean.parseBoolean(appFactoryConfiguration.getFirstProperty("BAM.EnableStatPublishing"))) { try {//ww w.jav a 2s . c om priority = Integer .parseInt(appFactoryConfiguration.getFirstProperty("BAM.Property.ListenerPriority")); bundleContext.registerService(ApplicationEventsHandler.class.getName(), new StatPublishEventsListener("StatPublishEventsListener", priority), null); } catch (NumberFormatException nfe) { log.error("Invalid priority provided for StatPublishEventsListener", nfe); } } try { priority = Integer.parseInt(appFactoryConfiguration .getFirstProperty("EventHandlers.EnvironmentAuthorizationHandler.priority")); bundleContext.registerService(ApplicationEventsHandler.class.getName(), new EnvironmentAuthorizationListener("EnvironmentAuthorizationListener", priority), null); } catch (NumberFormatException nfe) { log.error("Invalid priority provided for EnvironmentAuthorizationListener", nfe); } Dictionary<String, Object> propsNonBuild = new Hashtable<String, Object>(); propsNonBuild.put(AppFactoryConstants.STORAGE_TYPE, AppFactoryConstants.BUILDABLE_STORAGE_TYPE); bundleContext.registerService(ApplicationInfoService.class.getName(), new ApplicationInfoService(), null); try { priority = Integer.parseInt(appFactoryConfiguration .getFirstProperty("EventHandlers.NonBuildableApplicationEventListner.priority")); bundleContext.registerService(ApplicationEventsHandler.class.getName(), new NonBuildableApplicationEventListner("NonBuildableApplicationEventListner", priority), propsNonBuild); } catch (NumberFormatException nfe) { log.error("Invalid priority provided for NonBuildableApplicationEventListner", nfe); } try { priority = Integer.parseInt(appFactoryConfiguration .getFirstProperty("EventHandlers.ApplicationInfomationChangeListner.priority")); bundleContext.registerService(ApplicationEventsHandler.class.getName(), new ApplicationInfomationChangeListner("ApplicationInfomationChangeListner", priority), null); } catch (NumberFormatException nfe) { log.error("Invalid priority provided for ApplicationInfomationChangeListner", nfe); } try { priority = Integer.parseInt(appFactoryConfiguration .getFirstProperty("EventHandlers.InitialArtifactDeployerHandler.priority")); bundleContext.registerService(ApplicationEventsHandler.class.getName(), new InitialArtifactDeployerHandler("InitialArtifactDeployerHandler", 45), null); } catch (NumberFormatException nfe) { log.error("Invalid priority provided for InitialArtifactDeployerHandler", nfe); } if (log.isDebugEnabled()) { log.debug("Application Management Service bundle is activated "); } }
From source file:com.ibm.jaggr.service.impl.config.BundleVersionsHashTest.java
@Test public void testBundleVersionsHash() throws Exception { URI tmpDir = new File(System.getProperty("user.dir")).toURI(); IAggregator mockAggregator = TestUtils.createMockAggregator(); InitParams initParams = new InitParams(Arrays .asList(new InitParam[] { new InitParam("propName", "getBundleVersionsHash", mockAggregator) })); BundleVersionsHash bvh = new BundleVersionsHash(); IServiceReference mockServiceReference = EasyMock.createNiceMock(IServiceReference.class); IServiceReference[] serviceReferences = new IServiceReference[] { mockServiceReference }; IPlatformServices mockPlatformServices = EasyMock.createNiceMock(IPlatformServices.class); IAggregatorExtension mockExtension = EasyMock.createMock(IAggregatorExtension.class); EasyMock.expect(mockAggregator.getPlatformServices()).andReturn(mockPlatformServices).anyTimes(); EasyMock.replay(mockAggregator);//from ww w. j a v a2 s.co m Dictionary<String, String> dict = new Hashtable<String, String>(); dict.put("name", mockAggregator.getName()); EasyMock.expect(mockPlatformServices.getService(mockServiceReference)).andReturn(bvh).anyTimes(); EasyMock.expect(mockExtension.getInitParams()).andReturn(initParams).anyTimes(); EasyMock.expect(mockPlatformServices.getServiceReferences(IConfigScopeModifier.class.getName(), "(name=" + mockAggregator.getName() + ")")).andReturn(serviceReferences).anyTimes(); EasyMock.replay(mockServiceReference, mockPlatformServices, mockExtension); bvh.initialize(mockAggregator, mockExtension, null); EasyMock.verify(mockPlatformServices); Bundle mockBundle1 = EasyMock.createMock(Bundle.class); Bundle mockBundle2 = EasyMock.createMock(Bundle.class); PowerMock.mockStatic(Platform.class); EasyMock.expect(Platform.getBundle("com.test.bundle1")).andReturn(mockBundle1).anyTimes(); EasyMock.expect(Platform.getBundle("com.test.bundle2")).andReturn(mockBundle2).anyTimes(); EasyMock.expect(Platform.getBundle("com.test.bundle3")).andReturn(null).anyTimes(); final Dictionary<String, String> bundle1Headers = new Hashtable<String, String>(); final Dictionary<String, String> bundle2Headers = new Hashtable<String, String>(); EasyMock.expect(mockBundle1.getHeaders()).andAnswer(new IAnswer<Dictionary<String, String>>() { @Override public Dictionary<String, String> answer() throws Throwable { return bundle1Headers; } }).anyTimes(); EasyMock.expect(mockBundle2.getHeaders()).andAnswer(new IAnswer<Dictionary<String, String>>() { @Override public Dictionary<String, String> answer() throws Throwable { return bundle2Headers; } }).anyTimes(); PowerMock.replay(Platform.class, mockBundle1, mockBundle2); bundle1Headers.put("Bnd-LastModified", "123456789"); bundle2Headers.put("Bnd-LastModified", "234567890"); bundle1Headers.put("Bundle-Version", "1.2.3.20140414"); bundle2Headers.put("Bundle-Version", "1.2.3.20140412"); String config = "{cacheBust:getBundleVersionsHash(['Bundle-Version', 'Bnd-LastModified'], 'com.test.bundle1', 'com.test.bundle2')}"; ConfigImpl cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); String cacheBust = cfg.getCacheBust(); bundle1Headers.put("Bnd-LastModified", "123456780"); cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.assertFalse(cacheBust.equals(cfg.getCacheBust())); bundle1Headers.put("Bnd-LastModified", "123456789"); cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.assertEquals(cacheBust, cfg.getCacheBust()); bundle2Headers.put("Bundle-Version", "1.2.4"); cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.assertFalse(cacheBust.equals(cfg.getCacheBust())); bundle2Headers.put("Bundle-Version", "1.2.3.20140412"); cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.assertEquals(cacheBust, cfg.getCacheBust()); // Test that when header names are not specified, it defaults to 'Bundle-Version'. config = "{cacheBust:getBundleVersionsHash('com.test.bundle1', 'com.test.bundle2')}"; cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); cacheBust = cfg.getCacheBust(); bundle1Headers.put("Bnd-LastModified", "123456780"); cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.assertEquals(cacheBust, cfg.getCacheBust()); bundle2Headers.put("Bundle-Version", "1.2.4"); cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.assertFalse(cacheBust.equals(cfg.getCacheBust())); bundle2Headers.put("Bundle-Version", "1.2.3.20140412"); cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.assertEquals(cacheBust, cfg.getCacheBust()); // Ensure exception thrown if a specified bundle is not found config = "{cacheBust:getBundleVersionsHash('com.test.bundle1', 'com.test.bundle2', 'com.test.bundle3')}"; try { cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.fail("Expected exception"); } catch (WrappedException ex) { Assert.assertTrue(NotFoundException.class.isInstance(ex.getCause())); } // ensure exception thrown if argument is wrong type config = "{cacheBust:getBundleVersionsHash({})}"; try { cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.fail("Expected exception"); } catch (WrappedException ex) { Assert.assertTrue(IllegalArgumentException.class.isInstance(ex.getCause())); } // ensure value is null if no bundle names specified config = "{cacheBust:getBundleVersionsHash()}"; cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.assertNull(cfg.getCacheBust()); config = "{cacheBust:getBundleVersionsHash(['Bundle-Version'])}"; cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.assertNull(cfg.getCacheBust()); config = "{}"; cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.assertNull(cfg.getCacheBust()); // Ensure that cacheBust is a base64 encoded array of 16 bytes. byte[] bytes = Base64.decodeBase64(cacheBust); Assert.assertEquals(16, bytes.length); }
From source file:com.adobe.acs.commons.http.headers.impl.AbstractDispatcherCacheHeaderFilter.java
@Activate @SuppressWarnings("squid:S1149") protected final void activate(ComponentContext context) throws Exception { Dictionary<?, ?> properties = context.getProperties(); doActivate(context);//from w w w . ja v a2 s . c om String[] filters = PropertiesUtil.toStringArray(properties.get(PROP_FILTER_PATTERN)); if (filters == null || filters.length == 0) { throw new ConfigurationException(PROP_FILTER_PATTERN, "At least one filter pattern must be specified."); } for (String pattern : filters) { Dictionary<String, String> filterProps = new Hashtable<String, String>(); log.debug("Adding filter ({}) to pattern: {}", this.toString(), pattern); filterProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_REGEX, pattern); filterProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT, "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=*)"); ServiceRegistration filterReg = context.getBundleContext().registerService(Filter.class.getName(), this, filterProps); filterRegistrations.add(filterReg); } }