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.apache.ace.authentication.processor.basicauth.BasicHttpAuthenticationProcessorTest.java

/**
 * Tests that updated does not throw an exception for a correct configuration.
 *///  ww w. j a  va2  s  .c  o m
@Test(groups = { UNIT })
public void testUpdatedDoesAcceptCorrectProperties() throws ConfigurationException {
    final String keyUsername = "foo";
    final String keyPassword = "bar";

    Dictionary<String, Object> props = new Hashtable<>();
    props.put(PROPERTY_KEY_USERNAME, keyUsername);
    props.put(PROPERTY_KEY_PASSWORD, keyPassword);

    BasicHttpAuthenticationProcessor processor = new BasicHttpAuthenticationProcessor();

    processor.updated(props);

    // Test whether we can use the new properties...
    when(m_servletRequest.getHeader(AUTHORIZATION_HEADER)).thenReturn(createAuthHeaderValue("bob:secret"));

    User user = mock(User.class);
    when(user.getName()).thenReturn("bob");
    when(user.hasCredential(eq(keyPassword), eq("secret"))).thenReturn(Boolean.TRUE);

    when(m_userAdmin.getUser(eq(keyUsername), eq("bob"))).thenReturn(user);

    User result = processor.authenticate(m_userAdmin, m_servletRequest);
    assert result != null : "Expected a valid user to be returned!";

    assert "bob".equals(user.getName()) : "Expected user bob to be returned!";
}

From source file:org.opencastproject.workflow.impl.WorkflowDefinitionScanner.java

/**
 * {@inheritDoc}//from  ww  w . j  av a2 s .  c  om
 * 
 * @see org.apache.felix.fileinstall.ArtifactInstaller#install(java.io.File)
 */
public void install(File artifact) throws Exception {
    WorkflowDefinition def = currentWFD;

    // If the current workflow definition is null, it means this is a first install and not an update...
    if (def == null) {
        // ... so we have to load the definition first
        def = parseWorkflowDefinitionFile(artifact);

        if (def == null) {
            logger.warn("Unable to install workflow from {}", artifact.getAbsolutePath());
            artifactsWithError.add(artifact);
            return;
        }
    }

    logger.info("Installing workflow from file {}", artifact.getAbsolutePath());
    artifactsWithError.remove(artifact);
    artifactIds.put(artifact, def.getId());
    putWokflowDefinition(def.getId(), def);

    // Determine the number of available profiles
    String[] filesInDirectory = artifact.getParentFile().list(new FilenameFilter() {
        public boolean accept(File arg0, String name) {
            return name.endsWith(".xml");
        }
    });

    logger.info("Worfkflow definition '{}' from file {} installed", def.getId(), artifact.getAbsolutePath());

    // Once all profiles have been loaded, announce readiness
    if ((filesInDirectory.length - artifactsWithError.size()) == artifactIds.size() && !isWFSinitiliazed) {
        logger.info("{} Workflow definitions loaded, activating Workflow service",
                filesInDirectory.length - artifactsWithError.size());
        Dictionary<String, String> properties = new Hashtable<String, String>();
        properties.put(ARTIFACT, "workflowdefinition");
        logger.debug("Indicating readiness of workflow definitions");
        bundleCtx.registerService(ReadinessIndicator.class.getName(), new ReadinessIndicator(), properties);
        isWFSinitiliazed = true;
    }
}

From source file:org.eclipse.gemini.blueprint.extender.internal.blueprint.event.OsgiEventDispatcher.java

private void initDependencies(Dictionary<String, Object> props, BlueprintEvent event) {
    String[] deps = event.getDependencies();
    if (!ObjectUtils.isEmpty(deps)) {
        props.put(DEPENDENCIES, deps);
        // props.put(SERVICE_FILTER, deps[0]);
        // props.put(SERVICE_FILTER_2, deps[0]);
        // props.put(SERVICE_OBJECTCLASS, extractObjectClassFromFilter(deps[0]));
        props.put(ALL_DEPENDENCIES, deps);
    }//from   ww w  . j  a v a2  s . c om
}

From source file:org.apache.felix.http.itest.SessionHandlingTest.java

private void setupServlet(final String name, String[] path, int rank, final String context) throws Exception {
    Dictionary<String, Object> servletProps = new Hashtable<String, Object>();
    servletProps.put(HTTP_WHITEBOARD_SERVLET_NAME, name);
    servletProps.put(HTTP_WHITEBOARD_SERVLET_PATTERN, path);
    servletProps.put(SERVICE_RANKING, rank);
    if (context != null) {
        servletProps.put(HTTP_WHITEBOARD_CONTEXT_SELECT,
                "(" + HTTP_WHITEBOARD_CONTEXT_NAME + "=" + context + ")");
    }/*www  .j  a v a  2s  .  co m*/

    Servlet sessionServlet = new TestServlet(initLatch, destroyLatch) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
            final boolean create = req.getParameter("create") != null;
            if (create) {
                req.getSession();
            }
            final boolean destroy = req.getParameter("destroy") != null;
            if (destroy) {
                req.getSession().invalidate();
            }
            final HttpSession s = req.getSession(false);
            if (s != null) {
                s.setAttribute("value", context);
            }

            final PrintWriter pw = resp.getWriter();
            pw.println("{");
            if (s == null) {
                pw.println(" \"session\" : false");
            } else {
                pw.println(" \"session\" : true,");
                pw.println(" \"sessionId\" : \"" + s.getId() + "\",");
                pw.println(" \"value\" : \"" + s.getAttribute("value") + "\"");
            }
            pw.println("}");
        }
    };

    registrations.add(m_context.registerService(Servlet.class.getName(), sessionServlet, servletProps));
}

From source file:org.wso2.carbon.identity.mgt.internal.IdentityMgtServiceComponent.java

protected void activate(ComponentContext context) {

    Dictionary<String, String> props = new Hashtable<String, String>();
    props.put(CarbonConstants.AXIS2_CONFIG_SERVICE, AxisObserver.class.getName());
    context.getBundleContext().registerService(AxisObserver.class.getName(),
            new IdentityMgtDeploymentInterceptor(), props);
    init();//from  w  w w . j  av a 2s  .  co m

    if (log.isDebugEnabled()) {
        log.debug("Identity Management Listener is enabled");
    }

    ServiceRegistration serviceRegistration = context.getBundleContext()
            .registerService(UserOperationEventListener.class.getName(), new IdentityMgtEventListener(), null);
    if (serviceRegistration != null) {
        if (log.isDebugEnabled()) {
            log.debug("Identity Management - UserOperationEventListener registered.");
        }
    } else {
        log.error("Identity Management - UserOperationEventListener could not be registered.");
    }

    UserOperationsNotificationListener notificationListener = new UserOperationsNotificationListener();
    ServiceRegistration userOperationNotificationSR = context.getBundleContext()
            .registerService(UserOperationEventListener.class.getName(), notificationListener, null);

    if (userOperationNotificationSR != null) {
        if (log.isDebugEnabled()) {
            log.debug("Identity Management - UserOperationNotificationListener registered.");
        }
    } else {
        log.error("Identity Management - UserOperationNotificationListener could not be registered.");
    }

    if (log.isDebugEnabled()) {
        log.debug("Identity Management bundle is activated");
    }

    RegistryCleanUpService registryCleanUpService = new RegistryCleanUpService(
            IdentityMgtConfig.getInstance().getRegistryCleanUpPeriod(),
            IdentityMgtConfig.getInstance().getRegistryCleanUpPeriod());
    registryCleanUpService.activateCleanUp();
}

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

public void updated(Dictionary dictionary) throws ConfigurationException {
    try {//from w  ww .j  ava2 s  .  c om
        startConfigurationContext(dictionary);
        if (configCtxServiceRegistration != null) {
            configCtxServiceRegistration.unregister();
        }
        //register ConfigurationContext as a OSGi serivce
        configCtxServiceRegistration = context.registerService(ConfigurationContext.class.getName(), configCtx,
                null);

        Registry servicesRegistry = new ServiceRegistry(context, configCtx);
        Registry moduleRegistry = new ModuleRegistry(context, configCtx, servicesRegistry);
        bundleTracker.addRegistry(servicesRegistry);
        bundleTracker.addRegistry(moduleRegistry);
        bundleTracker.open();

        new WSTracker(configCtx, context).open();

        context.addServiceListener(new AxisConfigServiceListener(configCtx, context));

        Dictionary prop = new Properties();
        prop.put(PROTOCOL, "http");
        //adding the default listener
        context.registerService(TransportListener.class.getName(), new HttpListener(context), prop);
        log.info("Axis2 environment has started.");
    } catch (AxisFault e) {
        String msg = "Error while creating ConfigurationContext";
        log.error(msg, e);
        throw new ConfigurationException(msg, msg, e);
    }

}

From source file:org.openengsb.connector.virtual.filewatcher.internal.FileWatcherConnectorTest.java

@Before
public void setUp() throws Exception {
    setupConnectorManager();/*www. ja v a  2 s. co m*/

    Activator activator = new Activator();
    activator.start(bundleContext);
    createDomainProviderMock(NullDomain.class, "example");

    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put("connector", "filewatcher");
    doAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            ServiceList<EventSupport> eventSupports = makeServiceList(EventSupport.class);
            for (EventSupport e : eventSupports) {
                try {
                    e.onEvent(new Event());
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
            EKBCommit commit = (EKBCommit) invocation.getArguments()[0];
            for (Object o : commit.getInserts()) {
                if (!activeModels.containsKey(o.getClass())) {
                    activeModels.put(o.getClass(), new ArrayList<Object>());
                }
                activeModels.get(o.getClass()).add(o);
            }
            return null;
        }
    }).when(persistenceService).commit(any(EKBCommit.class));
    when(queryService.queryForActiveModels(any(Class.class))).thenAnswer(new Answer<List<Object>>() {
        @Override
        public List<Object> answer(InvocationOnMock invocation) throws Throwable {
            Class<?> type = (Class<?>) invocation.getArguments()[0];
            return activeModels.get(type);
        }
    });
    FileWatcherConnectorProvider provider = new FileWatcherConnectorProvider("foo", persistenceService,
            queryService, bundleContext, mock(AuthenticationContext.class));
    provider.setId("filewatcher");
    registerService(provider, props, VirtualConnectorProvider.class);
}

From source file:org.eclipse.virgo.snaps.core.internal.SnapFactoryMonitorTests.java

private ServiceRegistration<SnapFactory> publishFactory(SnapFactory factory, String hostName,
        String hostVersionRange) {
    Dictionary<String, String> p = new Hashtable<String, String>();
    p.put(SnapFactory.FACTORY_NAME_PROPERTY, hostName);
    p.put(SnapFactory.FACTORY_RANGE_PROPERTY, hostVersionRange);

    return getBundleContext().registerService(SnapFactory.class, factory, p);
}

From source file:org.eclipse.virgo.snaps.core.internal.SnapFactoryMonitorTests.java

private void publishContextForBundle(Bundle bundle) {
    ServletContext context = new MockServletContext();

    Dictionary<String, String> p = new Hashtable<String, String>();
    p.put("osgi.web.symbolicname", bundle.getSymbolicName());
    p.put("osgi.web.version", bundle.getVersion().toString());

    bundle.getBundleContext().registerService(ServletContext.class, context, p);
}

From source file:org.codice.ddf.registry.publication.manager.RegistryPublicationManagerTest.java

@Test
public void testHandleEventNonRegistryMcard() throws Exception {
    Metacard mcard = new MetacardImpl();
    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));
}