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.openhab.binding.withings.internal.api.WithingsAccount.java

public void registerAccount(BundleContext bundleContext) {

    Dictionary<String, Object> serviceProperties = new Hashtable<String, Object>();
    serviceProperties.put("withings.accountid", accountId);
    serviceProperties.put("withings.userid", userId);

    if (this.clientServiceRegistration != null) {
        this.clientServiceRegistration.unregister();
    }/*from  w  ww.  ja v  a  2s . co m*/

    this.clientServiceRegistration = bundleContext.registerService(WithingsApiClient.class.getName(),
            new WithingsApiClient(consumer, userId), serviceProperties);
}

From source file:ch.entwine.weblounge.kernel.publisher.ResourcePublishingService.java

/**
 * Registers any static resources that are declared in the bundle's manifest
 * as a servlet./*  w w w.  j a v  a  2 s .  c o m*/
 * 
 * @param bundle
 *          the active bundle
 */
public void registerResources(Bundle bundle) {

    String resourcePath = (String) bundle.getHeaders().get(HTTP_RESOURCE);
    String contextPath = (String) bundle.getHeaders().get(HTTP_CONTEXT);
    String welcomeFile = (String) bundle.getHeaders().get(HTTP_WELCOME);

    // Are there any relevant manifest headers?
    if (StringUtils.isBlank(resourcePath) || StringUtils.isBlank(contextPath)) {
        logger.debug("No resource manifest headers found in bundle {}", bundle.getSymbolicName());
        return;
    }

    BundleContext bundleCtx = bundle.getBundleContext();

    logger.info("Publishing resources from bundle://{} at {}", bundle.getSymbolicName(), contextPath);

    // Create and register the resource servlet
    try {
        Servlet servlet = new ResourcesServlet(bundle, resourcePath, welcomeFile);
        Dictionary<String, String> servletRegistrationProperties = new Hashtable<String, String>();
        servletRegistrationProperties.put(ALIAS, contextPath);
        servletRegistrationProperties.put(SharedHttpContext.SERVLET_NAME, bundle.getSymbolicName() + "-static");
        ServiceRegistration servletRegistration = bundleCtx.registerService(Servlet.class.getName(), servlet,
                servletRegistrationProperties);
        resourceRegistrations.put(bundle.getSymbolicName(), servletRegistration);
    } catch (Throwable t) {
        logger.error("Error publishing resources service at " + contextPath, t);
    }

}

From source file:org.apache.axis2.osgi.deployment.OSGiConfigurationContextFactory.java

public synchronized void start(BundleContext context) {
    this.context = context;
    bundleTracker = new BundleTracker(context);
    Dictionary props = new Properties();
    props.put(Constants.SERVICE_PID, "org.apache.axis2.osgi");
    mngServiceRegistration = context.registerService(ManagedService.class.getName(), this, props);
}

From source file:ch.entwine.weblounge.dispatcher.impl.DispatcherServiceImpl.java

/**
 * Callback for OSGi's declarative services component activation.
 * /*from w w w  . j  av  a2s .  c  o m*/
 * @param context
 *          the component context
 * @throws Exception
 *           if component activation fails
 */
void activate(ComponentContext context) throws Exception {
    BundleContext bundleContext = context.getBundleContext();
    logger.info("Activating weblounge dispatcher");

    Dictionary<String, String> initParams = new Hashtable<String, String>();
    initParams.put(SharedHttpContext.ALIAS, "/");
    initParams.put(SharedHttpContext.SERVLET_NAME, "default");
    initParams.put(SharedHttpContext.CONTEXT_ID, SharedHttpContext.WEBLOUNGE_CONTEXT_ID);
    initParams.put(SharedHttpContext.PATTERN, ".*");
    dispatcherServiceRegistration = bundleContext.registerService(Servlet.class.getName(), dispatcher,
            initParams);

    instanceName = StringUtils.trimToNull(context.getBundleContext().getProperty(OPT_INSTANCE_NAME));
    if (instanceName != null)
        logger.info("Instance name is '{}'", instanceName);
    else
        logger.debug("No explicit instance name has been set");
    dispatcher.setName(instanceName);

    logger.debug("Weblounge dispatcher activated");
}

From source file:org.apache.ace.authentication.processor.basicauth.BasicHttpAuthenticationProcessorTest.java

/**
 * Tests that updated throws an exception for missing "key.username" property. 
 *//*w w w .  jav  a  2  s .  c  om*/
@Test(groups = { UNIT }, expectedExceptions = ConfigurationException.class)
public void testUpdatedDoesNotAcceptMissingKeyUsername() throws ConfigurationException {
    Dictionary<String, Object> props = new Hashtable<>();
    props.put(PROPERTY_KEY_PASSWORD, "foo");

    new BasicHttpAuthenticationProcessor().updated(props);
}

From source file:org.apache.ace.authentication.processor.basicauth.BasicHttpAuthenticationProcessorTest.java

/**
 * Tests that updated throws an exception for missing "key.password" property. 
 *///from  w  w w  . j a v  a  2s.  c o m
@Test(groups = { UNIT }, expectedExceptions = ConfigurationException.class)
public void testUpdatedDoesNotAcceptMissingKeyPassword() throws ConfigurationException {
    Dictionary<String, Object> props = new Hashtable<>();
    props.put(PROPERTY_KEY_USERNAME, "foo");

    new BasicHttpAuthenticationProcessor().updated(props);
}

From source file:org.apache.ace.authentication.processor.basicauth.BasicHttpAuthenticationProcessorTest.java

/**
 * Tests that updated throws an exception for missing "key.username" property. 
 *//*from   w w  w. ja v a  2s .  com*/
@Test(groups = { UNIT }, expectedExceptions = ConfigurationException.class)
public void testUpdatedDoesNotAcceptEmptyKeyUsername() throws ConfigurationException {
    Dictionary<String, Object> props = new Hashtable<>();
    props.put(PROPERTY_KEY_USERNAME, "");
    props.put(PROPERTY_KEY_PASSWORD, "foo");

    new BasicHttpAuthenticationProcessor().updated(props);
}

From source file:org.apache.ace.authentication.processor.basicauth.BasicHttpAuthenticationProcessorTest.java

/**
 * Tests that updated throws an exception for missing "key.password" property. 
 */// w w w  .jav  a2 s . c o m
@Test(groups = { UNIT }, expectedExceptions = ConfigurationException.class)
public void testUpdatedDoesNotAcceptEmptyKeyPassword() throws ConfigurationException {
    Dictionary<String, Object> props = new Hashtable<>();
    props.put(PROPERTY_KEY_USERNAME, "foo");
    props.put(PROPERTY_KEY_PASSWORD, "");

    new BasicHttpAuthenticationProcessor().updated(props);
}

From source file:org.openengsb.itests.exam.EventForwardIT.java

@Test
public void testSendEvent_shouldCallService() throws Exception {
    authenticateAsAdmin();//from ww w  .  j  a  v a  2  s  .  c  om
    addHelloWorldRule();
    ContextCurrentService contextService = getOsgiService(ContextCurrentService.class);
    contextService.createContext("42");
    ContextHolder.get().setCurrentContextId("42");

    Dictionary<String, Object> properties = new Hashtable<String, Object>();
    String[] clazzes = new String[] { Domain.class.getName(), ExampleDomain.class.getName() };
    properties.put("id", "dummyLog");
    properties.put("location.42", new String[] { "example" });

    DummyLogDomain logService = new DummyLogDomain();
    getBundleContext().registerService(clazzes, logService, properties);

    LogEvent e = new LogEvent();
    e.setName("42");

    ExampleDomainEvents exampleEvents = getOsgiService(ExampleDomainEvents.class);
    // this should be routed through the domain, which forwards it to the workflow service
    exampleEvents.raiseEvent(e);

    assertThat(logService.isWasCalled(), is(true));
}

From source file:org.opennaas.extensions.roadm.wonesys.transports.rawsocket.RawSocketTransport.java

protected Event createEvent(String eventTopic, String message) {
    Dictionary<String, Object> properties = new Hashtable<String, Object>();
    properties.put(RawSocketTransport.TRANSPORT_ID_PROPERTY_NAME, getTransportID());
    properties.put(RawSocketTransport.ARRIVAL_TIME_PROPERTY_NAME, new Date().getTime());
    if (message != null)
        properties.put(MESSAGE_PROPERTY_NAME, message);

    return new Event(eventTopic, properties);
}