System.setProperty("jboss.protocol.handler.modules", "org.jboss.osgi.framework");
// Setup the OSGi {@link Framework} properties
Configuration config = injectedConfig.getValue();
Map<String, Object> props = new HashMap<String, Object>(config.getProperties());
ServiceContainer container = context.getController().getServiceContainer();
ModuleLoader moduleLoader = injectedModuleLoader.getValue().getModuleLoader();
Module frameworkModule = new FrameworkModuleLoader(moduleLoader, props).getFrameworkModule();
props.put(IntegrationMode.class.getName(), IntegrationMode.CONTAINER);
props.put(ModuleLoader.class.getName(), moduleLoader);
props.put(ServiceContainer.class.getName(), container);
props.put(Module.class.getName(), frameworkModule);
// [TODO] This is a temporary workaround to configure the HTTP subsystem in OSGi
// this will go away once the HTTP subsystem from AS implements the OSGi HTTP Service.
props.put("org.osgi.service.http.port", "" + osgiHttpServerPortBinding.getValue().getSocketAddress().getPort());
// Always clean the framework storage
// [TODO] Differentiate beetween user data and persisted bundles
props.put(Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
// Get {@link ModuleLoader} for the OSGi layer
bundleManager = new BundleManager(props);
ModuleManagerPlugin plugin = bundleManager.getPlugin(ModuleManagerPlugin.class);
ModuleLoader osgiModuleLoader = plugin.getModuleLoader();
// Register the {@link ModuleLoader} with the {@link ClassifyingModuleLoaderService}
ServiceController<?> controller = container.getRequiredService(ClassifyingModuleLoaderService.SERVICE_NAME);
ClassifyingModuleLoaderService moduleLoaderService = (ClassifyingModuleLoaderService) controller.getValue();
Value<ModuleLoader> value = new ImmediateValue<ModuleLoader>(osgiModuleLoader);
osgiModuleLoaderInjector = new ClassifyingModuleLoaderInjector(Constants.JBOSGI_PREFIX, value);
osgiModuleLoaderInjector.inject(moduleLoaderService);
} catch (Throwable t) {