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;
}
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);
}
}
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();
}
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();
}
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);
}
}
Aggregations