Search in sources :

Example 1 with PojoServiceRegistry

use of org.apache.felix.connect.launch.PojoServiceRegistry in project jackrabbit-oak by apache.

the class OakOSGiRepositoryFactory method initializeServiceRegistry.

@SuppressWarnings("unchecked")
PojoServiceRegistry initializeServiceRegistry(Map config) {
    processConfig(config);
    PojoServiceRegistry registry = createServiceRegistry(config);
    registerMBeanServer(registry);
    startConfigTracker(registry, config);
    preProcessRegistry(registry);
    startBundles(registry, (String) config.get(REPOSITORY_BUNDLE_FILTER), config);
    postProcessRegistry(registry);
    return registry;
}
Also used : PojoServiceRegistry(org.apache.felix.connect.launch.PojoServiceRegistry)

Example 2 with PojoServiceRegistry

use of org.apache.felix.connect.launch.PojoServiceRegistry in project jackrabbit-oak by apache.

the class RepositoryStartupServlet method configWebConsoleSecurityProvider.

private void configWebConsoleSecurityProvider(Repository repository) {
    if (repository instanceof ServiceRegistryProvider) {
        PojoServiceRegistry registry = ((ServiceRegistryProvider) repository).getServiceRegistry();
        registry.registerService(WebConsoleSecurityProvider.class.getName(), new RepositorySecurityProvider(repository), null);
    }
}
Also used : PojoServiceRegistry(org.apache.felix.connect.launch.PojoServiceRegistry) WebConsoleSecurityProvider(org.apache.felix.webconsole.WebConsoleSecurityProvider) ServiceRegistryProvider(org.apache.jackrabbit.oak.run.osgi.ServiceRegistryProvider)

Example 3 with PojoServiceRegistry

use of org.apache.felix.connect.launch.PojoServiceRegistry in project karaf by apache.

the class EncryptableConfigAdminPropertyPlaceholderTest method setUp.

@Before
public void setUp() throws Exception {
    // Configure Jasypt
    enc = new StandardPBEStringEncryptor();
    env = new EnvironmentStringPBEConfig();
    env.setAlgorithm("PBEWithMD5AndDES");
    env.setPassword("password");
    enc.setConfig(env);
    System.setProperty("org.osgi.framework.storage", "target/osgi/" + System.currentTimeMillis());
    System.setProperty("karaf.name", "root");
    List<BundleDescriptor> bundles = new ClasspathScanner().scanForBundles("(Bundle-SymbolicName=*)");
    bundles.add(getBundleDescriptor("target/jasypt2.jar", bundle().add("OSGI-INF/blueprint/karaf-jaas-jasypt.xml", getClass().getResource("/OSGI-INF/blueprint/karaf-jaas-jasypt.xml")).set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", "jasypt").set("Bundle-Version", "0.0.0")));
    bundles.add(getBundleDescriptor("target/test2.jar", bundle().add("OSGI-INF/blueprint/configadmin-test.xml", getClass().getResource("configadmin-test.xml")).set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", "configtest").set("Bundle-Version", "0.0.0")));
    Map config = new HashMap();
    config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, bundles);
    PojoServiceRegistry reg = new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(config);
    bundleContext = reg.getBundleContext();
}
Also used : PojoServiceRegistry(org.apache.felix.connect.launch.PojoServiceRegistry) StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor) BundleDescriptor(org.apache.felix.connect.launch.BundleDescriptor) PojoServiceRegistryFactoryImpl(org.apache.felix.connect.PojoServiceRegistryFactoryImpl) EnvironmentStringPBEConfig(org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig) ClasspathScanner(org.apache.felix.connect.launch.ClasspathScanner) Before(org.junit.Before)

Example 4 with PojoServiceRegistry

use of org.apache.felix.connect.launch.PojoServiceRegistry in project camel by apache.

the class CamelBlueprintHelper method createBundleContext.

public static BundleContext createBundleContext(String name, String bundleFilter, TinyBundle bundle, TinyBundle configAdminInitBundle, ClassLoader loader) throws Exception {
    // ensure felix-connect stores bundles in an unique target directory
    String uid = "" + System.currentTimeMillis();
    String tempDir = "target/bundles/" + uid;
    System.setProperty("org.osgi.framework.storage", tempDir);
    createDirectory(tempDir);
    // use another directory for the jar of the bundle as it cannot be in the same directory
    // as it has a file lock during running the tests which will cause the temp dir to not be
    // fully deleted between tests
    createDirectory("target/test-bundles");
    List<BundleDescriptor> bundles = new LinkedList<>();
    if (configAdminInitBundle != null) {
        String jarName = "configAdminInitBundle-" + uid + ".jar";
        bundles.add(getBundleDescriptor("target/test-bundles/" + jarName, configAdminInitBundle));
    }
    if (bundle != null) {
        String jarName = name.toLowerCase(Locale.ENGLISH) + "-" + uid + ".jar";
        bundles.add(getBundleDescriptor("target/test-bundles/" + jarName, bundle));
    }
    List<BundleDescriptor> bundleDescriptors = getBundleDescriptors(bundleFilter, loader);
    // let's put configadmin before blueprint.core
    int idx1 = -1;
    int idx2 = -1;
    for (int i = 0; i < bundleDescriptors.size(); i++) {
        BundleDescriptor bd = bundleDescriptors.get(i);
        if ("org.apache.felix.configadmin".equals(bd.getHeaders().get("Bundle-SymbolicName"))) {
            idx1 = i;
        }
        if ("org.apache.aries.blueprint.core".equals(bd.getHeaders().get("Bundle-SymbolicName"))) {
            idx2 = i;
        }
    }
    if (idx1 >= 0 && idx2 >= 0 && idx1 > idx2) {
        bundleDescriptors.add(idx2, bundleDescriptors.remove(idx1));
    }
    // get the bundles
    bundles.addAll(bundleDescriptors);
    if (LOG.isDebugEnabled()) {
        for (int i = 0; i < bundles.size(); i++) {
            BundleDescriptor desc = bundles.get(i);
            LOG.debug("Bundle #{} -> {}", i, desc);
        }
    }
    // setup felix-connect to use our bundles
    Map<String, Object> config = new HashMap<String, Object>();
    config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, bundles);
    // create pojorsr osgi service registry
    PojoServiceRegistry reg = new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(config);
    return reg.getBundleContext();
}
Also used : PojoServiceRegistry(org.apache.felix.connect.launch.PojoServiceRegistry) BundleDescriptor(org.apache.felix.connect.launch.BundleDescriptor) HashMap(java.util.HashMap) PojoServiceRegistryFactoryImpl(org.apache.felix.connect.PojoServiceRegistryFactoryImpl) LinkedList(java.util.LinkedList)

Example 5 with PojoServiceRegistry

use of org.apache.felix.connect.launch.PojoServiceRegistry in project jackrabbit-oak by apache.

the class OakOSGiRepositoryFactory method getRepository.

@SuppressWarnings("unchecked")
public Repository getRepository(Map parameters) throws RepositoryException {
    if (parameters == null || !parameters.containsKey(REPOSITORY_HOME)) {
        // Required param missing so repository cannot be created
        return null;
    }
    Map config = new HashMap();
    config.putAll(parameters);
    PojoServiceRegistry registry = initializeServiceRegistry(config);
    BundleActivator activator = getApplicationActivator(config);
    try {
        activator.start(registry.getBundleContext());
    } catch (Exception e) {
        log.warn("Error occurred while starting activator {}", activator.getClass(), e);
    }
    // Future which would be used to notify when repository is ready
    // to be used
    SettableFuture<Repository> repoFuture = SettableFuture.create();
    new RunnableJobTracker(registry.getBundleContext());
    int timeoutInSecs = PropertiesUtil.toInteger(config.get(REPOSITORY_TIMEOUT_IN_SECS), DEFAULT_TIMEOUT);
    // Start the tracker for repository creation
    new RepositoryTracker(registry, activator, repoFuture, timeoutInSecs);
    // where OSGi runtime fails to start due to bugs (like cycles)
    try {
        return repoFuture.get(timeoutInSecs, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new RepositoryException("Repository initialization was interrupted");
    } catch (ExecutionException e) {
        throw new RepositoryException(e);
    } catch (TimeoutException e) {
        try {
            if (PropertiesUtil.toBoolean(config.get(REPOSITORY_SHUTDOWN_ON_TIMEOUT), true)) {
                shutdown(registry, timeoutInSecs);
                log.info("OSGi container shutdown after waiting for repository initialization for {} sec", timeoutInSecs);
            } else {
                log.warn("[{}] found to be false. Container is not stopped", REPOSITORY_SHUTDOWN_ON_TIMEOUT);
            }
        } catch (BundleException be) {
            log.warn("Error occurred while shutting down the service registry (due to " + "startup timeout) backing the Repository ", be);
        }
        throw new RepositoryException("Repository could not be started in " + timeoutInSecs + " seconds", e);
    }
}
Also used : HashMap(java.util.HashMap) BundleActivator(org.osgi.framework.BundleActivator) RepositoryException(javax.jcr.RepositoryException) TimeoutException(java.util.concurrent.TimeoutException) RepositoryException(javax.jcr.RepositoryException) BundleException(org.osgi.framework.BundleException) ExecutionException(java.util.concurrent.ExecutionException) PojoServiceRegistry(org.apache.felix.connect.launch.PojoServiceRegistry) Repository(javax.jcr.Repository) JackrabbitRepository(org.apache.jackrabbit.api.JackrabbitRepository) BundleException(org.osgi.framework.BundleException) ExecutionException(java.util.concurrent.ExecutionException) HashMap(java.util.HashMap) Map(java.util.Map) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

PojoServiceRegistry (org.apache.felix.connect.launch.PojoServiceRegistry)7 HashMap (java.util.HashMap)3 PojoServiceRegistryFactoryImpl (org.apache.felix.connect.PojoServiceRegistryFactoryImpl)3 BundleDescriptor (org.apache.felix.connect.launch.BundleDescriptor)3 Map (java.util.Map)2 ClasspathScanner (org.apache.felix.connect.launch.ClasspathScanner)2 WebConsoleSecurityProvider (org.apache.felix.webconsole.WebConsoleSecurityProvider)2 ServiceRegistryProvider (org.apache.jackrabbit.oak.run.osgi.ServiceRegistryProvider)2 StandardPBEStringEncryptor (org.jasypt.encryption.pbe.StandardPBEStringEncryptor)2 EnvironmentStringPBEConfig (org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig)2 Before (org.junit.Before)2 LinkedList (java.util.LinkedList)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 PostConstruct (javax.annotation.PostConstruct)1 Repository (javax.jcr.Repository)1 RepositoryException (javax.jcr.RepositoryException)1 JackrabbitRepository (org.apache.jackrabbit.api.JackrabbitRepository)1 BundleActivator (org.osgi.framework.BundleActivator)1 BundleException (org.osgi.framework.BundleException)1