List of usage examples for java.util Dictionary put
public abstract V put(K key, V value);
From source file:org.apache.felix.webconsole.internal.misc.EventAdminServlet.java
/** * Activate this component./* ww w.j av a2 s . c o m*/ */ public void activateBundle(BundleContext context) { super.activateBundle(context); this.events.clear(); // register as EventHandler service to receive events Dictionary propsBook = new Hashtable(); propsBook.put(Constants.SERVICE_DESCRIPTION, "Felix Web Console EventAdmin plugin"); propsBook.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation"); propsBook.put("event.topics", "*"); eventReceiver = context.registerService(EventHandler.class.getName(), this, propsBook); }
From source file:org.ops4j.pax.web.itest.jetty.WhiteboardR6IntegrationTest.java
@Test public void testResources() throws Exception { Dictionary<String, String> properties = new Hashtable<>(); properties.put("osgi.http.whiteboard.resource.pattern", "/files"); properties.put("osgi.http.whiteboard.resource.prefix", "/images"); ServiceRegistration<Object> registerService = bundleContext.registerService(Object.class, new MyResourceService(), properties); HttpResponse httpResponse = testClient.getHttpResponse("http://127.0.0.1:8181/files/ops4j.png", false, null, false);//from www . j av a2s . c o m Header header = httpResponse.getFirstHeader(HttpHeaders.CONTENT_TYPE); assertEquals("image/png", header.getValue()); registerService.unregister(); }
From source file:org.ops4j.pax.web.itest.jetty.WhiteboardR6IntegrationTest.java
private ServiceRegistration<Servlet> registerServlet(Dictionary<String, String> extendedProps) { Dictionary<String, String> properties = new Hashtable<>(); properties.put("osgi.http.whiteboard.servlet.pattern", "/myservlet"); properties.put("servlet.init.myname", "value"); if (extendedProps != null) { Enumeration<String> keys = extendedProps.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); properties.put(key, extendedProps.get(key)); }// ww w. ja va2 s .c om } ServiceRegistration<Servlet> registerService = bundleContext.registerService(Servlet.class, new MyServlet(), properties); return registerService; }
From source file:org.apache.sling.resourceresolver.impl.legacy.LegacyResourceProviderWhiteboard.java
protected void bindResourceProviderFactory(final ServiceReference ref) { final BundleContext bundleContext = ref.getBundle().getBundleContext(); final ResourceProviderFactory factory = (ResourceProviderFactory) bundleContext.getService(ref); if (factory != null) { final String[] propertyNames = ref.getPropertyKeys(); final boolean ownsRoot = toBoolean(ref.getProperty(OWNS_ROOTS), false); final List<ServiceRegistration> newServices = new ArrayList<ServiceRegistration>(); for (final String path : PropertiesUtil.toStringArray(ref.getProperty(ROOTS), new String[0])) { if (path != null && !path.isEmpty()) { final Dictionary<String, Object> newProps = new Hashtable<String, Object>(); if (PropertiesUtil.toBoolean(ref.getProperty(PROPERTY_REQUIRED), false)) { newProps.put(PROPERTY_AUTHENTICATE, AuthType.required.toString()); } else { newProps.put(PROPERTY_AUTHENTICATE, AuthType.lazy.toString()); }/*from w ww.j a va2s . com*/ newProps.put(PROPERTY_MODIFIABLE, true); newProps.put(PROPERTY_ADAPTABLE, true); newProps.put(PROPERTY_ATTRIBUTABLE, true); newProps.put(PROPERTY_REFRESHABLE, true); newProps.put(PROPERTY_NAME, factory.getClass().getName()); newProps.put(PROPERTY_ROOT, normalizePath(path)); if (ArrayUtils.contains(propertyNames, SERVICE_PID)) { newProps.put(ORIGINAL_SERVICE_PID, ref.getProperty(SERVICE_PID)); } if (ArrayUtils.contains(propertyNames, USE_RESOURCE_ACCESS_SECURITY)) { newProps.put(PROPERTY_USE_RESOURCE_ACCESS_SECURITY, ref.getProperty(USE_RESOURCE_ACCESS_SECURITY)); } if (ArrayUtils.contains(propertyNames, SERVICE_RANKING)) { newProps.put(SERVICE_RANKING, ref.getProperty(SERVICE_RANKING)); } String[] languages = PropertiesUtil.toStringArray(ref.getProperty(LANGUAGES), new String[0]); ServiceRegistration reg = bundleContext.registerService( org.apache.sling.spi.resource.provider.ResourceProvider.class.getName(), new LegacyResourceProviderFactoryAdapter(factory, languages, ownsRoot), newProps); newServices.add(reg); } } registrations.put(factory, newServices); } }
From source file:org.ow2.chameleon.core.activators.ConfigDeployer.java
private void readAndApplyConfiguration(File file, ConfigurationAdmin admin) throws Exception { synchronized (this) { if (admin == null) { LOGGER.warn("Cannot apply configuration " + file.getName() + " - no configuration admin"); configurations.put(file, UnmanagedConfiguration.INSTANCE); } else {/*from w w w. j av a2 s.c o m*/ Properties properties = read(file); String[] pid = parsePid(file.getName()); Dictionary<Object, Object> ht = new Properties(); for (String k : properties.stringPropertyNames()) { ht.put(k, properties.getProperty(k)); } Configuration config = configurations.get(file); if (config == null || config == UnmanagedConfiguration.INSTANCE) { config = getConfiguration(pid[0], pid[1], admin); if (config.getBundleLocation() != null) { config.setBundleLocation(null); } } LOGGER.info("Updating configuration {} in the configuration admin, configuration: {}", config.getPid(), configurations); config.update(ht); configurations.put(file, config); } } }
From source file:org.ops4j.pax.web.itest.jetty.WhiteboardR6IntegrationTest.java
@Test public void testListeners() throws Exception { ServiceRegistration<Servlet> registerService = registerServlet(); MyServletRequestListener listener = new MyServletRequestListener(); Dictionary<String, String> properties = new Hashtable<>(); properties.put("osgi.http.whiteboard.listener", "true"); ServiceRegistration<ServletRequestListener> listenerService = bundleContext .registerService(ServletRequestListener.class, listener, properties); testClient.testWebPath("http://127.0.0.1:8181/myservlet", "Servlet name: value"); assertThat(listener.gotEvent(), is(true)); listenerService.unregister();//from w w w.j a v a 2s. c om registerService.unregister(); }
From source file:org.ops4j.pax.web.itest.jetty.WhiteboardR6IntegrationTest.java
@Test // @Ignore("Registration of ServletContextHelper isn't functional right now") public void testWhiteBoardServletWithContext() throws Exception { Dictionary<String, String> contextProps = new Hashtable<>(); contextProps.put("osgi.http.whiteboard.context.name", "my-context"); contextProps.put("osgi.http.whiteboard.context.path", "/myapp"); CDNServletContextHelper context = new CDNServletContextHelper(); ServiceRegistration<ServletContextHelper> contextHelperService = bundleContext .registerService(ServletContextHelper.class, context, contextProps); Dictionary<String, String> extProps = new Hashtable<>(); extProps.put("osgi.http.whiteboard.context.select", "(osgi.http.whiteboard.context.name=my-context)"); ServiceRegistration<Servlet> registerServlet = registerServlet(extProps); testClient.testWebPath("http://127.0.0.1:8181/myapp/myservlet", "Servlet name: value"); assertEquals(1, context.handleSecurityCalls.get()); registerServlet.unregister();/* ww w . j a va2 s .c o m*/ contextHelperService.unregister(); }
From source file:org.codice.ddf.condpermadmin.PermissionActivator.java
@SuppressWarnings("squid:S1149" /* required by osgi's API */) @Override//from w w w . j av a2 s.co m public void start(BundleContext bundleContext) throws Exception { System.setProperty("/", File.separator); this.conditionalPermissionAdmin = getConditionalPermissionAdmin(bundleContext); String policyDir = SecurityActions.getSystemProperty("ddf.home") + File.separator + "security"; if (policyDir.startsWith("=")) { policyDir = policyDir.substring(1); } File policyDirFile = new File(policyDir); List<ParsedPolicy> parsedPolicies = new ArrayList<>(); for (File file : Objects.requireNonNull(policyDirFile.listFiles())) { ParsedPolicy parse = null; try { parse = new Parser(false).parse(file); } catch (Exception e) { systemExit(file); } parsedPolicies.add(parse); } ConditionalPermissionUpdate conditionalPermissionUpdate = conditionalPermissionAdmin .newConditionalPermissionUpdate(); conditionalPermissionUpdate.getConditionalPermissionInfos().clear(); this.priorityResult = null; List<ConditionalPermissionInfo> allGrantInfos = new ArrayList<>(); List<ConditionalPermissionInfo> allDenyInfos = new ArrayList<>(); for (ParsedPolicy parsedPolicy : parsedPolicies) { List<ParsedPolicyEntry> grantEntries = parsedPolicy.getGrantEntries(); List<ParsedPolicyEntry> denyEntries = parsedPolicy.getDenyEntries(); buildConditionalPermissionInfo(grantEntries, allGrantInfos, ConditionalPermissionInfo.ALLOW); buildConditionalPermissionInfo(denyEntries, allDenyInfos, ConditionalPermissionInfo.DENY); Priority priority = parsedPolicy.getPriority(); if (priorityResult == null) { this.priorityResult = priority; } else if (priority != priorityResult) { // if they don't match, then we can't make a determination on the priority, so we'll // default to deny this.priorityResult = Priority.DENY; } } if (priorityResult == null && !allGrantInfos.isEmpty() && !allDenyInfos.isEmpty()) { this.priorityResult = Priority.GRANT; } if (priorityResult == Priority.GRANT) { conditionalPermissionUpdate.getConditionalPermissionInfos().addAll(allGrantInfos); conditionalPermissionUpdate.getConditionalPermissionInfos().addAll(allDenyInfos); conditionalPermissionUpdate.getConditionalPermissionInfos() .add(getAllPermission(ConditionalPermissionInfo.ALLOW)); } else if (priorityResult == Priority.DENY) { conditionalPermissionUpdate.getConditionalPermissionInfos().addAll(allDenyInfos); conditionalPermissionUpdate.getConditionalPermissionInfos().addAll(allGrantInfos); conditionalPermissionUpdate.getConditionalPermissionInfos() .add(getAllPermission(ConditionalPermissionInfo.DENY)); } conditionalPermissionUpdate.commit(); final Dictionary<String, Object> props = new Hashtable<>(8); props.put(Constants.SERVICE_DESCRIPTION, "DDF :: Platform :: OSGi :: CondPermAdmin"); props.put(Constants.SERVICE_VENDOR, "Codice Foundation"); bundleContext.registerService(PermissionService.class, this, props); }
From source file:org.jboss.tools.project.examples.ProjectExamplesActivator.java
public static Dictionary<Object, Object> getEnvironment() { Dictionary<Object, Object> environment = new Hashtable<Object, Object>(System.getProperties()); Bundle bundle = Platform.getBundle("org.jboss.tools.central"); //$NON-NLS-1$ Version version = bundle.getVersion(); environment.put("org.jboss.tools.central.version", version.toString()); //$NON-NLS-1$ environment.put("org.jboss.tools.central.version.major", version.getMajor()); //$NON-NLS-1$ environment.put("org.jboss.tools.central.version.minor", version.getMinor()); //$NON-NLS-1$ environment.put("org.jboss.tools.central.version.micro", version.getMicro()); //$NON-NLS-1$ return environment; }
From source file:ddf.catalog.validation.impl.ValidationParser.java
private List<Callable<Boolean>> parseMetacardTypes(List<Outer.MetacardType> metacardTypes) { List<Callable<Boolean>> staged = new ArrayList<>(); Bundle bundle = FrameworkUtil.getBundle(this.getClass()); if (bundle == null) { LOGGER.warn(String.format("Unable to get bundle for [%s], Metacard Types will not be registered", this.getClass().getName())); return new ArrayList<>(); }/*from w ww. jav a 2 s. c o m*/ BundleContext context = bundle.getBundleContext(); for (Outer.MetacardType metacardType : metacardTypes) { Set<AttributeDescriptor> attributeDescriptors = new HashSet<>( BasicTypes.BASIC_METACARD.getAttributeDescriptors()); Set<String> requiredAttributes = new HashSet<>(); for (Map.Entry<String, Outer.MetacardAttribute> entry : metacardType.attributes.entrySet()) { String attributeName = entry.getKey(); AttributeDescriptor descriptor = attributeRegistry.getAttributeDescriptor(attributeName) .orElseThrow(() -> new IllegalStateException(String.format( "Metacard type [%s] includes the attribute [%s], but that attribute is not in the attribute registry.", metacardType.type, attributeName))); attributeDescriptors.add(descriptor); if (entry.getValue().required) { requiredAttributes.add(attributeName); } } if (!requiredAttributes.isEmpty()) { final MetacardValidator validator = new RequiredAttributesMetacardValidator(metacardType.type, requiredAttributes); staged.add(() -> context.registerService(MetacardValidator.class, validator, null) != null); } Dictionary<String, Object> properties = new Hashtable<>(); properties.put("name", metacardType.type); MetacardType type = new MetacardTypeImpl(metacardType.type, attributeDescriptors); staged.add(() -> context.registerService(MetacardType.class, type, properties) != null); } return staged; }