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.ops4j.pax.exam.junit.extender.impl.internal.TestBundleObserver.java

/**
 * {@inheritDoc}/*from  www.j av  a 2 s.  c  o  m*/
 * Registers specified test case as a service.
 */
public void addingEntries(final Bundle bundle, final List<ManifestEntry> manifestEntries) {
    String testClassName = null;
    String testMethodName = null;
    for (ManifestEntry manifestEntry : manifestEntries) {
        if (Constants.PROBE_TEST_CLASS.equals(manifestEntry.getKey())) {
            testClassName = manifestEntry.getValue();
        }
        if (Constants.PROBE_TEST_METHOD.equals(manifestEntry.getKey())) {
            testMethodName = manifestEntry.getValue();
        }
    }
    if (testClassName != null && testMethodName != null) {
        LOG.info("Found test: " + testClassName + "." + testMethodName);
        Dictionary<String, String> props = new Hashtable<String, String>();
        props.put(Constants.TEST_CASE_ATTRIBUTE, testClassName);
        props.put(Constants.TEST_METHOD_ATTRIBUTE, testMethodName);
        final BundleContext bundleContext = BundleUtils.getBundleContext(bundle);
        final ServiceRegistration serviceRegistration = bundleContext.registerService(
                CallableTestMethod.class.getName(),
                new CallableTestMethodImpl(bundleContext, testClassName, testMethodName), props);
        m_registrations.put(bundle, new Registration(testClassName, testMethodName, serviceRegistration));
        LOG.info("Registered testcase [" + testClassName + "." + testMethodName + "]");
    }
}

From source file:org.apache.sling.replication.transport.impl.RepositoryTransportHandler.java

@Override
public void deliverPackageToEndpoint(ReplicationPackage replicationPackage,
        ReplicationEndpoint replicationEndpoint, ReplicationQueueProcessor responseProcessor) throws Exception {

    Session session = null;//  ww w .  j av a2s.  c o  m
    try {
        TransportAuthenticationContext transportAuthenticationContext = new TransportAuthenticationContext();
        String path = replicationEndpoint.getUri().toString().replace("repo:/", "");
        transportAuthenticationContext.addAttribute("path", path);
        session = transportAuthenticationProvider.authenticate(repository, transportAuthenticationContext);
        int lastSlash = replicationPackage.getId().lastIndexOf('/');
        String nodeName = Text.escape(lastSlash < 0 ? replicationPackage.getId()
                : replicationPackage.getId().substring(lastSlash + 1));
        log.info("creating node {} in {}", replicationPackage.getId(), nodeName);

        if (session != null) {
            Node addedNode = session.getNode(path).addNode(nodeName, NodeType.NT_FILE);
            Node contentNode = addedNode.addNode(JcrConstants.JCR_CONTENT, NodeType.NT_RESOURCE);
            if (contentNode != null) {
                InputStream inputStream = null;
                try {
                    inputStream = replicationPackage.createInputStream();
                    contentNode.setProperty(JcrConstants.JCR_DATA,
                            session.getValueFactory().createBinary(inputStream));
                    session.save();
                } finally {
                    IOUtils.closeQuietly(inputStream);
                }
            }
            log.info("package {} delivered to the repository as node {} ", replicationPackage.getId(),
                    addedNode.getPath());

            Dictionary<Object, Object> props = new Properties();
            props.put("path", replicationPackage.getPaths());
            replicationEventFactory.generateEvent(ReplicationEventType.PACKAGE_REPLICATED, props);

        } else {
            throw new Exception("could not get a Session to deliver package to the repository");
        }
    } finally {
        if (session != null) {
            session.logout();
        }
    }
}

From source file:org.apache.sling.tests.sling_2998.SLING_2998_IT.java

@Test
public void testSlingTest() throws Exception {
    final HttpClient httpClient = HttpClients.createDefault();
    final HttpGet httpGet = new HttpGet(baseUri() + "/sling-test/sling/sling-test.html");

    final HttpResponse httpResponse = httpClient.execute(httpGet);
    assertEquals(200, httpResponse.getStatusLine().getStatusCode());

    final Dictionary<String, String> properties = new Hashtable<String, String>();
    properties.put("sling.auth.requirements", "+/sling-test");
    bundleContext.registerService(Object.class.getName(), new Object(), properties);

    final HttpResponse httpResponseUnauthorized = httpClient.execute(httpGet);
    assertEquals(401, httpResponseUnauthorized.getStatusLine().getStatusCode());

    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("admin", "admin"));

    final HttpClient authenticatingHttpClient = HttpClients.custom()
            .setDefaultCredentialsProvider(credentialsProvider).build();
    final HttpResponse httpResponseAuthorized = authenticatingHttpClient.execute(httpGet);
    assertEquals(200, httpResponseAuthorized.getStatusLine().getStatusCode());
}

From source file:org.opengoss.core.internal.registry.ApplicationServiceRegistry.java

public void registerService(ServiceHolder holder) throws Exception {
    //register service in osgi.
    ServiceDescriptor descriptor = holder.getDescriptor();
    UID serviceUid = descriptor.getGlobalUid();
    Dictionary<String, String> props = serviceUid.toDictionary();
    props.put(Constants.SCOPE, descriptor.getScope().toString());
    ServiceRegistration reg = ((PluginServiceRegistry) holder.getRegistry()).getBundleContext()
            .registerService(descriptor.getInterfaces(), holder.getService(), props);
    cache.put(serviceUid, reg);// w w  w.  j  a  v  a 2 s  . c  om
    //register service to network registry.
    if (descriptor.getScope() == (ServiceScope.NETWORK)) {
        ((INetworkServiceRegistry) getParent()).register(application + ":" + serviceUid.getId(),
                (Remote) holder.getService());
    }
}

From source file:org.eclipse.e4.opensocial.container.internal.browserHandlers.pubsub.SubscribeHandler.java

@Override
public Object handle(final Browser browser, final Object[] arguments) {
    final String channel = (String) arguments[1];
    final String callbackName = (String) arguments[2];

    // publish an EventHandler
    EventHandler eventHandler = new EventHandler() {
        @Override//from  w ww. jav a  2  s  . co m
        public void handleEvent(Event event) {
            final Integer source = (Integer) event.getProperty(MODULEID_EVENT_PROPERTY);
            // 'message' field is the JSON representation of the event
            // properties map
            final JSONObject message = new JSONObject();
            try {
                for (String key : event.getPropertyNames()) {
                    Object value = event.getProperty(key);
                    if (value instanceof String)
                        message.put(key, (String) value);
                    else if (value instanceof Integer)
                        message.put(key, (Integer) value);
                    else if (value instanceof Long)
                        message.put(key, (Long) value);
                    else if (value instanceof Double)
                        message.put(key, (Double) value);
                    else
                        message.put(key, value.toString() + "                                    ");
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            browser.getDisplay().syncExec(new Runnable() {
                public void run() {
                    if (!browser.isDisposed())
                        browser.evaluate("var f = " + callbackName + "; f('" + source + "', '"
                                + message.toString() + "');");
                }
            });
        }
    };

    Dictionary<Object, Object> properties = new Hashtable<Object, Object>();
    properties.put(EventConstants.EVENT_TOPIC, channel);
    // TODO put moduleId
    ServiceRegistration sr = getBundleContext().registerService(EventHandler.class.getName(), eventHandler,
            properties);
    registeredHandlers.add(sr);
    return null;
}

From source file:org.opencastproject.engage.theodul.manager.impl.Activator.java

private void registerStaticResources(File overrideDir, BundleContext bc) {
    // build properties
    Dictionary<String, String> props = new Hashtable<String, String>();
    props.put("contextId", RestConstants.HTTP_CONTEXT_ID);
    props.put("alias", URL_ALIAS);

    // instantiate Servelet that delivers the resources
    StaticResource staticResource = new StaticResource(
            new StaticResourceClassloader(bc.getBundle(), overrideDir, UI_CLASSPATH), UI_CLASSPATH, URL_ALIAS,
            UI_WELCOME_FILE);/*w  ww  . j ava2 s.c  om*/

    // register Servelet as a Service
    registrationStaticResources = bc.registerService(Servlet.class.getName(), staticResource, props);
}

From source file:org.opencastproject.engage.theodul.manager.impl.Activator.java

private void registerServices(BundleContext bc) {
    // register plugin manager
    Dictionary<String, String> props = new Hashtable<String, String>();
    props.put("service.description", "Service that manages plugins for the Theodul player");
    EngagePluginManagerImpl manager = new EngagePluginManagerImpl();
    manager.activate(bc);//from w  ww  .  ja v  a2  s. co  m
    registrationPluginManager = bc.registerService(EngagePluginManager.class.getName(), manager, props);

    // register plugin manager endpoint
    props = new Hashtable<String, String>();
    props.put("service.description", "Theodul Plugin Manager REST Endpoint");
    props.put("opencast.service.type", "org.opencastproject.engage.plugin.manager");
    props.put("opencast.service.path", "/engage/theodul/manager");
    EngagePluginManagerRestService endpoint = new EngagePluginManagerRestService();
    endpoint.setPluginManager(manager);
    registrationRestEndpoint = bc.registerService(EngagePluginManagerRestService.class.getName(), endpoint,
            props);
    endpoint.activate(); // was DS before, keeping it for the activation message
}

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

public void testModifyingALoadedDictionaryDoesNotAffectThePersistedData() throws Exception {
    Dictionary first = manager.load(GOOD_PID);
    first.put("favorite", "apocrypha");

    Dictionary second = manager.load(GOOD_PID);
    assertEquals("godspeed", second.get("favorite"));
}

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

public void testStoreFiltersOutBundleLocation() throws Exception {
    String newPid = "edu.nwu.psc.breakfast";
    {//from ww w  .ja  va  2 s .c o m
        Dictionary d = new Hashtable();
        d.put("hash", "browns");
        d.put("waffle", "belgian");
        d.put(BUNDLE_LOCATION_PROPERTY, "file:/path/to/breakfast-2.0.jar");

        manager.store(newPid, d);
    }

    List actual = getJdbcTemplate().queryForList(
            "SELECT id FROM osgi_cm_properties WHERE name=? AND service_pid=?",
            new Object[] { BUNDLE_LOCATION_PROPERTY, newPid });
    assertEquals("Should be no results: " + actual, 0, actual.size());
}

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

@Test
public void testExternalConfig() throws Exception {
    Configuration config = ca.getConfiguration(PID, null);
    Dictionary<String, Object> p = new Hashtable<String, Object>();
    p.put(LOG_LEVEL, "DEBUG");
    p.put(LOGBACK_FILE, FilenameUtils.concat(new File(".").getAbsolutePath(),
            "src/test/resources/test1-external-config.xml"));
    config.update(p);//  w w  w .j  av a2s. c  o  m

    delay();

    ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory
            .getLogger(Logger.ROOT_LOGGER_NAME);
    assertNotNull(rootLogger.getAppender("FILE"));
}