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:org.eclipse.data.sampledb.SampledbActivator.java

/**
 * @see org.eclipse.core.runtime.Plugin#start(org.osgi.framework.BundleContext)
 */// w  w  w .  j  a va  2s.  com
public void start(BundleContext context) throws Exception {
    LOGGER.info("Sampledb plugin starts up. Current startCount=" + startCount);
    synchronized (SampledbActivator.class) {
        if (++startCount == 1) {
            // First time to start for this instance of JVM
            // initialze database directory now
            init();
        }
    }
    String dbUrl = getDBUrl();

    // Copy connection properties and replace user and password with fixed
    // value
    Properties props = new Properties();
    props.put(USER, SAMPLE_DB_SCHEMA);
    props.put(PASSWORD, EMPTY_VALUE);

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Getting Sample DB JDBC connection. DriverClass=" + DERBY_DRIVER_CLASS + ", Url=" + dbUrl);
    }

    // initClassLoaders();
    try {
        getDerbyDriver().connect(dbUrl, props);
    } catch (Exception e) {
        System.out.println();
    }
    DataSource ds = getDataSource();
    Dictionary<String, String> sprops = new Hashtable<String, String>();
    sprops.put(DATASOURCE_NAME, SAMPLE_DB_SCHEMA);
    sprops.put(OSGI_JNDI_SERVICE_NAME, DATASOURCE + FILE_DELIM + SAMPLE_DB_SCHEMA);
    // Register a new TimeServiceImpl with the above props
    context.registerService(DataSource.class, ds, sprops);
    this.context = context;
}

From source file:org.apache.aries.jpa.itest.AbstractJPAItest.java

public void createConfigForLogging() throws IOException {
    Configuration logConfig = configAdmin.getConfiguration("org.ops4j.pax.logging", null);
    Dictionary<String, String> props = new Hashtable<String, String>();
    props.put("log4j.rootLogger", "INFO, stdout");
    props.put("log4j.logger.org.apache.aries.transaction", "DEBUG");
    props.put("log4j.logger.org.apache.aries.transaction.parsing", "DEBUG");
    props.put("log4j.logger.org.apache.aries.jpa.blueprint.impl", "DEBUG");
    props.put("log4j.appender.stdout", "org.apache.log4j.ConsoleAppender");
    props.put("log4j.appender.stdout.layout", "org.apache.log4j.PatternLayout");
    props.put("log4j.appender.stdout.layout.ConversionPattern", "%d{ISO8601} | %-5.5p | %-16.16t | %c | %m%n");
    logConfig.update(props);/*from  ww  w  .ja  v a  2  s  .  c o  m*/
}

From source file:org.ops4j.pax.web.extender.samples.whiteboard.internal.Activator.java

public void start(final BundleContext bundleContext) throws Exception {
    Dictionary props;

    // register a custom http context that forbids access
    props = new Hashtable();
    props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, "forbidden");
    m_httpContextReg = bundleContext.registerService(HttpContext.class.getName(), new WhiteboardContext(),
            props);/*from   ww w  .  j a v a2s .  com*/
    // and an servlet that cannot be accessed due to the above context
    props = new Hashtable();
    props.put(ExtenderConstants.PROPERTY_ALIAS, "/forbidden");
    props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, "forbidden");
    m_forbiddenServletReg = bundleContext.registerService(Servlet.class.getName(),
            new WhiteboardServlet("/forbidden"), props);

    props = new Hashtable();
    props.put("alias", "/whiteboard");
    m_servletReg = bundleContext.registerService(Servlet.class.getName(), new WhiteboardServlet("/whiteboard"),
            props);

    props = new Hashtable();
    props.put("alias", "/root");
    m_rootServletReg = bundleContext.registerService(HttpServlet.class.getName(),
            new WhiteboardServlet("/root"), props);

    DefaultResourceMapping resourceMapping = new DefaultResourceMapping();
    resourceMapping.setAlias("/whiteboardresources");
    resourceMapping.setPath("/images");
    m_resourcesReg = bundleContext.registerService(ResourceMapping.class.getName(), resourceMapping, null);

    try {
        // register a filter
        props = new Hashtable();
        props.put(ExtenderConstants.PROPERTY_URL_PATTERNS, "/whiteboard/filtered/*");
        m_filterReg = bundleContext.registerService(Filter.class.getName(), new WhiteboardFilter(), props);
    } catch (NoClassDefFoundError ignore) {
        // in this case most probably that we do not have a servlet version >= 2.3
        // required by our filter
        LOG.warn("Cannot start filter example (javax.servlet version?): " + ignore.getMessage());
    }

    try {
        // register a servlet request listener
        m_listenerReg = bundleContext.registerService(EventListener.class.getName(), new WhiteboardListener(),
                null);
    } catch (NoClassDefFoundError ignore) {
        // in this case most probably that we do not have a servlet version >= 2.4
        // required by our request listener
        LOG.warn("Cannot start filter example (javax.servlet version?): " + ignore.getMessage());
    }

    // servlet to test exceptions and error pages
    props = new Hashtable();
    props.put("alias", "/exception");
    m_exceptionServletRegistration = bundleContext.registerService(HttpServlet.class.getName(),
            new ExceptionServlet(), props);

    // register resource at root of bundle
    DefaultResourceMapping rootResourceMapping = new DefaultResourceMapping();
    rootResourceMapping.setAlias("/");
    rootResourceMapping.setPath("");
    m_rootResourceMappingRegistration = bundleContext.registerService(ResourceMapping.class.getName(),
            rootResourceMapping, null);

    // register welcome page - interesting how it will work with the root servlet, i.e. will it showdow it
    DefaultWelcomeFileMapping welcomeFileMapping = new DefaultWelcomeFileMapping();
    welcomeFileMapping.setRedirect(true);
    welcomeFileMapping.setWelcomeFiles(new String[] { "index.html", "welcome.html" });
    m_welcomeFileRegistration = bundleContext.registerService(WelcomeFileMapping.class.getName(),
            welcomeFileMapping, null);

    // register error pages for 404 and java.lang.Exception
    DefaultErrorPageMapping errorpageMapping = new DefaultErrorPageMapping();
    errorpageMapping.setError("404");
    errorpageMapping.setLocation("/404.html");

    m_404errorpageRegistration = bundleContext.registerService(ErrorPageMapping.class.getName(),
            errorpageMapping, null);

    // java.lang.Exception
    DefaultErrorPageMapping exceptionErrorMapping = new DefaultErrorPageMapping();
    exceptionErrorMapping.setError(java.lang.Exception.class.getName());
    exceptionErrorMapping.setLocation("/uncaughtException.html");
    m_uncaughtExceptionRegistration = bundleContext.registerService(ErrorPageMapping.class.getName(),
            exceptionErrorMapping, null);
}

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

@SuppressWarnings({ "unchecked" })
public Dictionary load(String pid) throws IOException {
    log.debug("Loading configuration dictionary for {}", pid);

    List<OsgiConfigurationProperty> list = getProperties(pid);
    if (list.isEmpty()) {
        throw new IOException("No configuration for PID=\"" + pid + "\"");
    }//from  w w w.  j a v  a  2 s.  c o m
    Dictionary out = new Hashtable();
    for (OsgiConfigurationProperty property : list) {
        if (!EXCLUDED_PROPERTIES.contains(property.getName())) {
            out.put(property.getName(), property.getValue());
        }
    }
    return out;
}

From source file:org.apache.aries.jpa.itest.AbstractJPAItest.java

@Before
public void createConfigForDataSource() throws Exception {
    if (config == null) {
        createConfigForLogging();//  www.ja va 2  s . c o m
        config = configAdmin.createFactoryConfiguration("org.ops4j.datasource", null);
        Dictionary<String, String> props = new Hashtable<String, String>();
        props.put(DataSourceFactory.OSGI_JDBC_DRIVER_CLASS, "org.apache.derby.jdbc.EmbeddedDriver-pool-xa");
        props.put(DataSourceFactory.JDBC_URL, "jdbc:derby:memory:TEST1;create=true");
        props.put("dataSourceName", "testds");
        config.update(props);
        LOG.info("Created DataSource config testds");
    }
}

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

/**
 * Checks the default settings. It runs the bundle with minimum dependencies
 *//* www. j av a2 s .  c o  m*/
@Test
public void testJULLogging() throws Exception {
    java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger("foo.jul.1");
    org.slf4j.Logger slf4jLogger = LoggerFactory.getLogger("foo.jul.1");

    assertEquals(java.util.logging.Level.FINEST, julLogger.getLevel());
    assertTrue(slf4jLogger.isTraceEnabled());

    // Now add an appender and see if JUL logs are handled
    TestAppender ta = new TestAppender();
    Dictionary<String, Object> props = new Hashtable<String, Object>();

    String[] loggers = { "foo.jul.1", };
    ch.qos.logback.classic.Logger bar = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(loggers[0]);
    bar.setLevel(Level.INFO);

    props.put("loggers", loggers);
    ServiceRegistration sr = bundleContext.registerService(Appender.class.getName(), ta, props);

    delay();

    // Level should be INFO now
    assertEquals(java.util.logging.Level.INFO, julLogger.getLevel());

    julLogger.info("Info message");
    julLogger.fine("Fine message");

    assertEquals(1, ta.events.size());

}

From source file:ch.entwine.weblounge.contentrepository.fs.DocumentVersionTest.java

/**
 * @throws java.lang.Exception/*from   ww  w . ja v a2s  . c om*/
 */
@Before
public void setUp() throws Exception {
    String rootPath = PathUtils.concat(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    repositoryRoot = new File(rootPath);
    FileUtils.deleteQuietly(repositoryRoot);

    // Create the index configuration
    System.setProperty("weblounge.home", rootPath);
    TestUtils.startTesting();
    ElasticSearchUtils.createIndexConfigurationAt(repositoryRoot);

    // Template
    template = EasyMock.createNiceMock(PageTemplate.class);
    EasyMock.expect(template.getIdentifier()).andReturn("templateid").anyTimes();
    EasyMock.expect(template.getStage()).andReturn("non-existing").anyTimes();
    EasyMock.replay(template);

    Set<Language> languages = new HashSet<Language>();
    languages.add(LanguageUtils.getLanguage("en"));
    languages.add(LanguageUtils.getLanguage("de"));

    // Site
    site = EasyMock.createNiceMock(Site.class);
    EasyMock.expect(site.getIdentifier()).andReturn("test").anyTimes();
    EasyMock.expect(site.getTemplate((String) EasyMock.anyObject())).andReturn(template).anyTimes();
    EasyMock.expect(site.getDefaultTemplate()).andReturn(template).anyTimes();
    EasyMock.expect(site.getLanguages()).andReturn(languages.toArray(new Language[languages.size()]))
            .anyTimes();
    EasyMock.expect(site.getModules()).andReturn(new Module[] {}).anyTimes();
    EasyMock.expect(site.getDefaultLanguage()).andReturn(LanguageUtils.getLanguage("de")).anyTimes();
    EasyMock.expect(site.getAdministrator()).andReturn(new SiteAdminImpl("admin")).anyTimes();
    EasyMock.replay(site);

    // Connect to the repository
    repository = new FileSystemContentRepository();
    repository.setSerializer(serializer);
    repository.setEnvironment(Environment.Production);
    Dictionary<String, Object> repositoryProperties = new Hashtable<String, Object>();
    repositoryProperties.put(FileSystemContentRepository.OPT_ROOT_DIR, repositoryRoot.getAbsolutePath());
    repository.updated(repositoryProperties);
    repository.connect(site);

    // Remove the default home page
    repository.delete(new PageURIImpl(site, "/"), true);
}

From source file:org.ops4j.pax.web.itest.jetty.WhiteboardR6IntegrationTest.java

@Test
public void testErrorServlet() throws Exception {
    Dictionary<String, String> properties = new Hashtable<>();
    properties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ERROR_PAGE, "java.io.IOException");
    properties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ERROR_PAGE, "404");

    ServiceRegistration<Servlet> registerService = bundleContext.registerService(Servlet.class,
            new MyErrorServlet(), properties);

    testClient.testWebPath("http://127.0.0.1:8181/error", "Error Servlet, we do have a 404", 404, false);

    registerService.unregister();/*from  w w  w . ja  va 2s.  c  o m*/
}

From source file:org.ops4j.pax.web.itest.jetty.WhiteboardR6IntegrationTest.java

@Test
public void testAsyncServlet() throws Exception {
    Dictionary<String, String> properties = new Hashtable<>();
    properties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/as");
    properties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED, "true");

    ServiceRegistration<Servlet> registerService = bundleContext.registerService(Servlet.class,
            new AsyncServlet(), properties);

    testClient.testAsyncWebPath("http://127.0.0.1:8181/as", "Servlet executed async in:", 200, false, null);

    registerService.unregister();//  ww  w.  ja  v  a  2  s .  c  om
}

From source file:org.ops4j.pax.web.itest.jetty.WhiteboardR6IntegrationTest.java

@Test
public void testFilterServlet() throws Exception {
    ServiceRegistration<Servlet> registerService = registerServlet();

    Dictionary<String, String> properties = new Hashtable<>();
    properties.put("osgi.http.whiteboard.filter.pattern", "/*");
    ServiceRegistration<javax.servlet.Filter> registerFilter = bundleContext
            .registerService(javax.servlet.Filter.class, new MyFilter(), properties);

    testClient.testWebPath("http://127.0.0.1:8181/myservlet", "before");

    registerFilter.unregister();/*ww  w  .  j  a  v  a  2  s . c  o m*/
    registerService.unregister();
}