Example usage for java.util Dictionary put

List of usage examples for java.util Dictionary put

Introduction

In this page you can find the example usage for java.util Dictionary put.

Prototype

public abstract V put(K key, V value);

Source Link

Document

Maps the specified key to the specified value in this dictionary.

Usage

From source file:ddf.registry.client.rest.internal.RestRegistryClient.java

/**
 * Set the external registry that should be queried.
 * @param url URL to the external registry
 *///  ww  w  .j  a v a2 s.co  m
public void setRegistryUrl(String url) {
    if (StringUtils.isNotBlank(url)) {
        if (!configurationList.isEmpty()) {
            LOGGER.debug("Updating registry URL and removing old sources.");
            clearConfigurations();
        }
        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpGet httpGet = new HttpGet(url);
        try {
            CloseableHttpResponse response = httpClient.execute(httpGet);
            String endpoints = IOUtils.toString(response.getEntity().getContent());
            JSONArray endpointArray = new JSONArray(endpoints);
            for (int i = 0; i < endpointArray.length(); i++) {
                JSONObject curEndpoint = endpointArray.getJSONObject(i);

                // get endpoint props
                String type = curEndpoint.getString(ServiceInfo.TYPE_KEY);
                String endpointUrl = curEndpoint.getString(ServiceInfo.URL_KEY);

                // get factory pid using service type
                String pid = serviceResolver.getFactoryPid(type);
                LOGGER.debug("Got factory pid of [{}] for service of type [{}].", pid, type);

                // create new source pointing to this endpoint
                Configuration siteConfig = configAdmin.createFactoryConfiguration(pid, null);
                Dictionary<String, Object> properties = new Hashtable<>();
                properties.put("endpointUrl", endpointUrl);
                properties.put("id", pid);
                LOGGER.debug("Creating new source that points to {}.", endpointUrl);
                siteConfig.update(properties);
                configurationList.add(siteConfig);
            }
        } catch (Exception e) {
            LOGGER.warn("Encountered an error while trying to connect to the remote registry.", e);
        } finally {
            IOUtils.closeQuietly(httpClient);
        }
    } else {
        LOGGER.debug(
                "Registry location reset due to url being empty or null. Deleting any remote sources created from previous registry.");
        clearConfigurations();
    }
}

From source file:org.apache.sling.commons.log.logback.integration.ITConfigPrinter.java

private void createLogConfig(String fileName, String... logConfigs) throws IOException {
    Configuration config = ca.createFactoryConfiguration(FACTORY_PID_CONFIGS, null);
    Dictionary<String, Object> p = new Hashtable<String, Object>();
    p.put(LogConfigManager.LOG_LOGGERS, logConfigs);
    p.put(LogConfigManager.LOG_LEVEL, "DEBUG");
    p.put(LogConfigManager.LOG_FILE, fileName);
    config.update(p);/*from  w ww  .ja  v a  2s  .c  om*/

    delay();
}

From source file:org.opencastproject.kernel.security.SpringSecurityConfigurationArtifactInstaller.java

/**
 * OSGI activation callback//from w  w  w . ja  v  a2 s. co  m
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void activate(ComponentContext cc) {
    this.bundleContext = cc.getBundleContext();
    this.appContexts = new HashMap<String, OsgiBundleXmlApplicationContext>();

    // Register the security filter
    securityFilter = new SecurityFilter(securityService);
    Dictionary props = new Hashtable<String, Boolean>();
    props.put("contextId", RestConstants.HTTP_CONTEXT_ID);
    props.put("pattern", ".*");
    props.put("service.ranking", "2");
    filterRegistration = bundleContext.registerService(Filter.class.getName(), securityFilter, props);
}

From source file:edu.northwestern.bioinformatics.studycalendar.osgi.felixcm.internal.PscFelixPersistenceManagerTest.java

public void testStoreAsUpdate() throws Exception {
    {//from   w w  w.java 2  s .  c  o  m
        Dictionary d = manager.load(GOOD_PID);
        d.put("favorite", "mezzanine");
        d.put("first", 'W');
        d.remove("letters");
        manager.store(GOOD_PID, d);
    }

    Dictionary reloaded = manager.load(GOOD_PID);
    assertEquals("Updated value not updated", "mezzanine", reloaded.get("favorite"));
    assertNull("Removed property still present", reloaded.get("letters"));
    assertEquals("New property not present", 'W', reloaded.get("first"));
}

From source file:org.codice.ddf.endpoints.rest.action.ActionProviderRegistryProxy.java

public void bind(ServiceReference<MetacardTransformer> reference) {

    LOGGER.info("New service registered [{}]", reference);

    String transformerId = null;//  w  ww  .  j a  v a2  s  . c o m

    if (reference.getProperty(Constants.SERVICE_ID) != null) {

        transformerId = reference.getProperty(Constants.SERVICE_ID).toString();

        // backwards compatibility
    }
    if (StringUtils.isBlank(transformerId) && reference.getProperty(Constants.SERVICE_SHORTNAME) != null) {

        transformerId = reference.getProperty(Constants.SERVICE_SHORTNAME).toString();
    }

    if (StringUtils.isBlank(transformerId)) {
        return;
    }

    String actionProviderId = ACTION_ID_PREFIX + transformerId;

    String attributeName = getAttributeName(reference);

    ActionProvider provider = actionFactory.createActionProvider(actionProviderId, transformerId,
            attributeName);

    Dictionary actionProviderProperties = new Hashtable<String, String>();

    actionProviderProperties.put(Constants.SERVICE_ID, actionProviderId);

    ServiceRegistration actionServiceRegistration = getBundleContext().registerService(PROVIDER_INTERFACE_NAME,
            provider, actionProviderProperties);

    LOGGER.info("Registered new {} [{}]", PROVIDER_INTERFACE_NAME, actionServiceRegistration);

    actionProviderRegistry.put(reference, actionServiceRegistration);

}

From source file:org.codice.ddf.rest.impl.action.ActionProviderRegistryProxy.java

public void bind(ServiceReference<MetacardTransformer> reference) {

    LOGGER.info("New service registered [{}]", reference);

    String transformerId = null;//  w ww  . ja v  a2  s  .  co m

    if (reference.getProperty(Constants.SERVICE_ID) != null) {

        transformerId = reference.getProperty(Constants.SERVICE_ID).toString();

        // backwards compatibility
    }
    if (StringUtils.isBlank(transformerId) && reference.getProperty(Constants.SERVICE_SHORTNAME) != null) {

        transformerId = reference.getProperty(Constants.SERVICE_SHORTNAME).toString();
    }

    if (StringUtils.isBlank(transformerId)) {
        return;
    }

    String actionProviderId = ACTION_ID_PREFIX + transformerId;

    String attributeName = getAttributeName(reference);

    ActionProvider provider = actionFactory.createActionProvider(actionProviderId, transformerId,
            attributeName);

    Dictionary<String, String> actionProviderProperties = new DictionaryMap<>();

    actionProviderProperties.put(Constants.SERVICE_ID, actionProviderId);

    ServiceRegistration actionServiceRegistration = getBundleContext().registerService(PROVIDER_INTERFACE_NAME,
            provider, actionProviderProperties);

    LOGGER.info("Registered new {} [{}]", PROVIDER_INTERFACE_NAME, actionServiceRegistration);

    actionProviderRegistry.put(reference, actionServiceRegistration);
}

From source file:org.wisdom.template.thymeleaf.impl.ThymeLeafTemplateImplementation.java

/**
 * Computes the service properties to be exposed with the {@link org.wisdom.api.templates.Template} service.
 *
 * @return the service properties.//from   ww  w .  j a v  a2 s.c  om
 */
public Dictionary<String, ?> getServiceProperties() {
    Dictionary<String, String> props = new Hashtable<>();
    props.put("name", name());
    props.put("fullName", fullName());
    props.put("mimetype", mimetype());
    props.put("engine", engine());
    return props;
}

From source file:org.apache.sling.models.it.ServiceInjectionWithDifferentRankingTest.java

@SuppressWarnings("unchecked")
private void registerSimpleService(int ranking) {
    @SuppressWarnings("rawtypes")
    Dictionary serviceProps = new Hashtable();
    serviceProps.put(Constants.SERVICE_RANKING, new Integer(ranking));
    ServiceRegistration serviceRegistration = bundleContext.registerService(SimpleService.class.getName(),
            new SimpleServiceWithCustomRanking(ranking), serviceProps);
    serviceRegistrations.add(serviceRegistration);
}

From source file:org.apache.sling.extensions.logback.integration.ITConfigAdminSupport.java

@Test
public void testChangeLogLevelWithConfig() throws Exception {
    //Set log level to debug for foo1.bar
    Configuration config = ca.createFactoryConfiguration(FACTORY_PID_CONFIGS, null);
    Dictionary<String, Object> p = new Hashtable<String, Object>();
    p.put(LOG_LOGGERS, new String[] { "foo1.bar" });
    p.put(LOG_LEVEL, "DEBUG");
    config.update(p);/*from   www  .jav  a  2s .com*/

    delay();

    Logger slf4jLogger = LoggerFactory.getLogger("foo1.bar");
    assertTrue(slf4jLogger.isDebugEnabled());
    assertTrue(LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME).isInfoEnabled());
    assertFalse(LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME).isDebugEnabled());

    //foo1.bar should not have explicit appender attached with it
    Iterator<Appender<ILoggingEvent>> itr = ((ch.qos.logback.classic.Logger) slf4jLogger)
            .iteratorForAppenders();
    assertFalse(itr.hasNext());
}

From source file:edu.northwestern.bioinformatics.studycalendar.osgi.felixcm.internal.PscFelixPersistenceManagerTest.java

public void testStoreAsNew() throws Exception {
    String newPid = "edu.nwu.psc.numbers";
    {//from   w  w w  .  java  2 s  . co  m
        Dictionary d = new Hashtable();
        d.put("aleph", (byte) 0);
        d.put("nature", new int[] { 2, 72 });
        d.put("pie", new Vector(Arrays.asList("chess", "key lime")));

        manager.store(newPid, d);
    }

    Dictionary loaded = manager.load(newPid);
    assertEquals("Wrong reloaded contents: " + loaded, 3, loaded.size());
    assertEquals("Missing aleph", (byte) 0, loaded.get("aleph"));

    assertTrue("Missing nature", loaded.get("nature") instanceof int[]);
    int[] actualNature = (int[]) loaded.get("nature");
    assertEquals("Wrong value 0 in nature", 2, actualNature[0]);
    assertEquals("Wrong value 1 in nature", 72, actualNature[1]);

    assertTrue("Missing pie", loaded.get("pie") instanceof Vector);
    List actualPie = (List) loaded.get("pie");
    assertEquals("Wrong value 0 in pie", "chess", actualPie.get(0));
    assertEquals("Wrong value 1 in pie", "key lime", actualPie.get(1));
}