Package org.osgi.service.cm

Examples of org.osgi.service.cm.ConfigurationAdmin


                if (logFile == null) {
                    throw new ConfigurationException(LogConfigManager.LOG_FILE,
                            "LogFile name has to be specified.");
                }
                // try to get the configadmin
                final ConfigurationAdmin configAdmin = (ConfigurationAdmin) this.bundleContext
                        .getService(sr);
                if (configAdmin != null) {
                    Configuration config;
                    if (pid == null || pid.length() == 0) {
                        config = configAdmin.createFactoryConfiguration(LogConfigManager.FACTORY_PID_CONFIGS);
                    } else {
                        config = configAdmin.getConfiguration(pid);
                    }
                    if (config != null) {
                        Dictionary<String, Object> dict = new Hashtable<String, Object>();
                        dict.put(LogConfigManager.LOG_LEVEL, logLevel.toLowerCase());
                        dict.put(LogConfigManager.LOG_LOGGERS, loggers);
View Full Code Here


                if (pid == null) {
                    throw new ConfigurationException(LogConfigManager.PID,
                            "PID has to be specified.");
                }
                // try to get the configadmin
                final ConfigurationAdmin configAdmin = (ConfigurationAdmin) this.bundleContext
                        .getService(sr);
                if (configAdmin != null) {
                    try {
                        Configuration config = configAdmin.getConfiguration(pid);
                        if (config != null) {
                            config.delete();
                        } else {
                            throw new ConfigurationException(LogConfigManager.PID,
                                    "No configuration for this PID:" + pid);
View Full Code Here

    }

    // ---------- internal -----------------------------------------------------

    private void verifyConfiguration(ServiceReference ref) {
        ConfigurationAdmin ca = (ConfigurationAdmin) bundleContext.getService(ref);
        if (ca == null) {
            log.error("verifyConfiguration: Failed to get Configuration Admin Service from Service Reference");
            return;
        }

        try {
            // find a configuration for theses properties...
            Configuration[] cfgs = ca.listConfigurations("("
                + ConfigurationAdmin.SERVICE_FACTORYPID + "="
                + SERVER_REPOSITORY_FACTORY_PID + ")");
            if (cfgs != null && cfgs.length > 0) {
                log.info(
                    "verifyConfiguration: {} Configurations available for {}, nothing to do",
                    new Object[] { new Integer(cfgs.length),
                        SERVER_REPOSITORY_FACTORY_PID });
                return;
            }

            // No config, create a default one.
            Hashtable<String, String> defaultConfig = new Hashtable<String, String>();
            final String overrideUrl = bundleContext.getProperty(RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY);
            if(overrideUrl != null && overrideUrl.length() > 0) {
                // Ignore other parameters if override URL (SLING-254) is set
                defaultConfig.put(RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY, overrideUrl);
                log.info(RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY + "=" + overrideUrl +
                    ", using it to create the default configuration");

            } else {
               initDefaultConfig(defaultConfig, bundleContext);
            }

            // create the factory and set the properties
            Configuration config = ca.createFactoryConfiguration(SERVER_REPOSITORY_FACTORY_PID);
            config.update(defaultConfig);

            log.info("verifyConfiguration: Created configuration {} for {}",
                config.getPid(), config.getFactoryPid());
View Full Code Here

            return;
        }
       
        out.println("# The CRANKSTART_CONFIG_ID property that we add to configs is meant to detect which factory configs have already been created");
       
        final ConfigurationAdmin ca = (ConfigurationAdmin)bundleContext.getService(ref);
        try {
            final Configuration [] allCfg = ca.listConfigurations(null);
            int count = 0;
            if(allCfg != null) {
                for(Configuration cfg : allCfg) {
                    count++;
                    if(cfg.getFactoryPid() != null && cfg.getFactoryPid().length() > 0) {
View Full Code Here


    @Test
    public void testEnableQueueProcessing() throws Exception {
        JobManager jobManager = mock(JobManager.class);
        ConfigurationAdmin configAdmin = mock(ConfigurationAdmin.class);
        Configuration config = mock(Configuration.class);
        when(configAdmin.createFactoryConfiguration(QueueConfiguration.class.getName(), null)).thenReturn(config);
        BundleContext context = mock(BundleContext.class);
        JobHandlingReplicationQueueProvider jobHandlingReplicationQueueProvider = new JobHandlingReplicationQueueProvider(
                jobManager, context);
        String agentName = "dummy-agent";
        ReplicationQueueProcessor queueProcessor = mock(ReplicationQueueProcessor.class);
View Full Code Here

    }

    @Test
    public void testDisableQueueProcessing() throws Exception {
        JobManager jobManager = mock(JobManager.class);
        ConfigurationAdmin configAdmin = mock(ConfigurationAdmin.class);
        Configuration config = mock(Configuration.class);
        when(configAdmin.createFactoryConfiguration(QueueConfiguration.class.getName(), null)).thenReturn(config);
        BundleContext context = mock(BundleContext.class);
        JobHandlingReplicationQueueProvider jobHandlingReplicationQueueProvider = new JobHandlingReplicationQueueProvider(
                jobManager,  context);
        String agentName = "dummy-agent";
        jobHandlingReplicationQueueProvider.disableQueueProcessing(agentName);
View Full Code Here

    }

    // ---------- internal -----------------------------------------------------

    private void verifyConfiguration(ServiceReference ref) {
        ConfigurationAdmin ca = (ConfigurationAdmin) bundleContext.getService(ref);
        if (ca == null) {
            log.error("verifyConfiguration: Failed to get Configuration Admin Service from Service Reference");
            return;
        }

        try {
            // find a configuration for theses properties...
            Configuration[] cfgs = ca.listConfigurations("("
                + ConfigurationAdmin.SERVICE_FACTORYPID + "="
                + this.getClientRepositoryFactoryPID() + ")");
            if (cfgs != null && cfgs.length > 0) {
                log.info(
                    "verifyConfiguration: {} Configurations available for {}, nothing to do",
                    new Object[] { new Integer(cfgs.length),
                        this.getClientRepositoryFactoryPID() });
                return;
            }

            // we have no configuration, create from default settings
            Hashtable<String, String> defaultConfig = new Hashtable<String, String>();
            final String overrideUrl = bundleContext.getProperty(RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY);
            if(overrideUrl != null && overrideUrl.length() > 0) {
                // Ignore other parameters if override URL (SLING-260) is set
                defaultConfig.put(RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY, overrideUrl);
                log.debug(RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY + "=" + overrideUrl +
                    ", using it to create the default configuration");
               
            } else {
               initDefaultConfig(defaultConfig);
            }

            // create the factory and set the properties
            Configuration config = ca.createFactoryConfiguration(this.getClientRepositoryFactoryPID());
            config.update(defaultConfig);

            log.debug("verifyConfiguration: Created configuration {} for {}",
                config.getPid(), config.getFactoryPid());
View Full Code Here

        JSONObject jb = new JSONObject(MDC.getCopyOfContextMap());
        pw.print(jb.toString());
    }

    private void createTestConfig() throws IOException {
        ConfigurationAdmin ca = (ConfigurationAdmin) configAdminTracker.getService();
        Configuration cfg = ca.getConfiguration("org.apache.sling.extensions.mdc.internal.MDCInsertingFilter",null);

        Dictionary<String,Object> dict = new Hashtable<String, Object>();
        dict.put("headers",new String[]{"mdc-test-header"});
        dict.put("parameters",new String[]{"mdc-test-param"});
        dict.put("cookies",new String[]{"mdc-test-cookie"});
View Full Code Here

    @Rule
    public Service configAdminService = new Service(ConfigurationAdmin.class);
  
    @Test
    public void testConfigAdmin() throws Exception {
        ConfigurationAdmin configAdmin = configAdminService.getService(ConfigurationAdmin.class);
        assertNotNull(
                "Expecting ConfigurationAdmin to be injected by Sling test runner",
                configAdmin);
       
        final String name = "TEST_" + getClass().getName() + System.currentTimeMillis();
        assertNotNull("Expecting config " + name + " to be created",
                configAdmin.getConfiguration(name));
    }
View Full Code Here

     * @throws Exception
     */
    @Override
    protected Dictionary getEditedProps() throws Exception {
        if(pid != null) {
            ConfigurationAdmin configurationAdmin = getConfigurationAdmin();
            if (configurationAdmin != null) {
                Configuration[] configs = configurationAdmin.listConfigurations("(service.pid=" + pid + ")");
                if (configs != null && configs.length > 0) {
                    Configuration configuration = configs[0];
                    if (configuration != null) {
                        return configuration.getProperties();
                    }
View Full Code Here

TOP

Related Classes of org.osgi.service.cm.ConfigurationAdmin

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.