use of org.osgi.framework.BundleException in project sling by apache.
the class Sling method startup.
// ---------- BundleActivator ----------------------------------------------
/**
* Called when the OSGi framework is being started. This implementation
* registers as a service listener for the
* <code>javax.servlet.Servlet</code> class and calls the
* {@link #doStartBundle()} method for implementations to execute more
* startup tasks. Additionally the <code>context</code> URL protocol
* handler is registered.
*
* @param bundleContext The <code>BundleContext</code> of the system
* bundle of the OSGi framework.
* @throws BundleException May be thrown if the {@link #doStartBundle()} throws.
*/
private final void startup(BundleContext bundleContext) {
// register the context URL handler
Hashtable<String, Object> props = new Hashtable<String, Object>();
props.put(URLConstants.URL_HANDLER_PROTOCOL, new String[] { "context" });
ContextProtocolHandler contextHandler = new ContextProtocolHandler(this.resourceProvider);
bundleContext.registerService(URLStreamHandlerService.class.getName(), contextHandler, props);
// register the platform MBeanServer
MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
Hashtable<String, Object> mbeanProps = new Hashtable<String, Object>();
try {
ObjectName beanName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
AttributeList attrs = platformMBeanServer.getAttributes(beanName, new String[] { "MBeanServerId", "SpecificationName", "SpecificationVersion", "SpecificationVendor", "ImplementationName", "ImplementationVersion", "ImplementationVendor" });
for (Object object : attrs) {
Attribute attr = (Attribute) object;
if (attr.getValue() != null) {
mbeanProps.put(attr.getName(), attr.getValue().toString());
}
}
} catch (Exception je) {
logger.log(Logger.LOG_INFO, "start: Cannot set service properties of Platform MBeanServer service, registering without", je);
}
bundleContext.registerService(MBeanServer.class.getName(), platformMBeanServer, mbeanProps);
bundleContext.registerService(LaunchpadContentProvider.class.getName(), resourceProvider, null);
}
use of org.osgi.framework.BundleException in project sling by apache.
the class BundleInstallUpgradeExceptionRetryTest method testUpdateFailsWithMoreThanMaxRetrys.
@Test
public void testUpdateFailsWithMoreThanMaxRetrys() throws Exception {
// install version 1.1 and fail activation with exception all attempts
final Object listener = this.startObservingBundleEvents();
final AtomicReference<ServiceRegistration<AtomicInteger>> ref = new AtomicReference<ServiceRegistration<AtomicInteger>>(null);
final AtomicInteger counter = new AtomicInteger(5);
bundleContext.addBundleListener(new SynchronousBundleListener() {
@Override
public void bundleChanged(org.osgi.framework.BundleEvent event) {
if (event.getType() == org.osgi.framework.BundleEvent.STOPPED && event.getBundle().getSymbolicName().equals(symbolicName) && event.getBundle().getVersion().equals(new Version("1.0.0"))) {
System.out.println(event.getSource() + " " + event.getType());
Thread.dumpStack();
if (ref.get() == null) {
try {
event.getBundle().start();
ref.set(bundleContext.registerService(AtomicInteger.class, counter, null));
} catch (BundleException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
ref.getAndSet(null).unregister();
if (counter.get() == 0) {
bundleContext.removeBundleListener(this);
}
}
}
}
});
installer.updateResources(URL_SCHEME, getInstallableResource(createTestBundle(new Version("2.0.0"))), null);
try {
long time = 0;
while (counter.get() >= 0 && time < 1000) {
sleep(100);
time += 100;
}
assertBundle("After installing", symbolicName, "1.0.0", Bundle.ACTIVE);
} finally {
if (ref.get() != null) {
ref.get().unregister();
}
}
}
use of org.osgi.framework.BundleException in project sling by apache.
the class AbstractLaunchpadStartingMojo method executeWithArtifacts.
/**
* {@inheritDoc}
*/
@Override
protected void executeWithArtifacts() throws MojoExecutionException {
try {
final Map<String, String> props = new HashMap<String, String>();
props.put(SharedConstants.SLING_HOME, slingHome);
// ensure launchpad is set
props.put(SharedConstants.SLING_LAUNCHPAD, slingHome);
if (forceBundleLoad) {
props.put(SharedConstants.FORCE_PACKAGE_BUNDLE_LOADING, "true");
}
// set up and configure Felix Logger
int logLevelNum;
if (logLevel == null) {
logLevelNum = DEFAULT_LOG_LEVEL;
} else {
logLevelNum = toLogLevelInt(logLevel, DEFAULT_LOG_LEVEL);
}
props.put(LOG_LEVEL_PROP, String.valueOf(logLevelNum));
// Display port number on console, in case HttpService doesn't
getLog().info("HTTP server port: " + httpPort);
props.put(PROP_PORT, String.valueOf(httpPort));
// prevent tons of needless WARN from the framework
Logger logger = new Logger();
logger.setLogLevel(Logger.LOG_ERROR);
if (propertiesFile.exists()) {
File tmp = null;
try {
tmp = File.createTempFile("sling", "props");
mavenFileFilter.copyFile(propertiesFile, tmp, true, project, Collections.EMPTY_LIST, true, System.getProperty("file.encoding"), mavenSession);
Properties loadedProps = PropertyUtils.loadPropertyFile(tmp, null);
for (Object key : loadedProps.keySet()) {
props.put((String) key, (String) loadedProps.get(key));
}
} catch (IOException e) {
throw new MojoExecutionException("Unable to create filtered properties file", e);
} catch (MavenFilteringException e) {
throw new MojoExecutionException("Unable to create filtered properties file", e);
} finally {
if (tmp != null) {
tmp.delete();
}
}
}
sling = startSling(resourceProvider, props, logger);
} catch (BundleException be) {
getLog().error("Failed to Start OSGi framework", be);
}
}
use of org.osgi.framework.BundleException in project bnd by bndtools.
the class MiniFramework method installBundle.
@Override
public Bundle installBundle(String location, InputStream in) throws BundleException {
Context c;
try {
in.close();
try {
@SuppressWarnings("unused") URL url = new URL(location);
} catch (MalformedURLException e) {
throw new BundleException("For the mini framework, the location must be a proper URL even though this is not required by the specification " + location, e);
}
c = new Context(this, last, ++ID, location);
bundles.put(Long.valueOf(c.id), c);
last = c;
return c;
} catch (Exception e) {
throw new BundleException("Can't install " + location, e);
}
}
use of org.osgi.framework.BundleException in project bndtools by bndtools.
the class OSGiJUnitLaunchDelegate method getLaunch.
// A couple of hacks to make sure the JUnit plugin is active and notices our
// launch.
@Override
public ILaunch getLaunch(ILaunchConfiguration configuration, String mode) throws CoreException {
// start the JUnit plugin
try {
Bundle jdtJUnitBundle = BundleUtils.findBundle(Plugin.getDefault().getBundleContext(), JDT_JUNIT_BSN, null);
if (jdtJUnitBundle == null)
throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Bundle \"{0}\" was not found. Cannot report JUnit results via the Workbench.", JDT_JUNIT_BSN), null));
jdtJUnitBundle.start();
} catch (BundleException e) {
throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error starting bundle \"{0}\". Cannot report JUnit results via the Workbench.", JDT_JUNIT_BSN), null));
}
// JUnit plugin ignores the launch unless attribute
// "org.eclipse.jdt.launching.PROJECT_ATTR" is set.
ILaunchConfigurationWorkingCopy modifiedConfig = configuration.getWorkingCopy();
IResource launchResource = LaunchUtils.getTargetResource(configuration);
if (launchResource != null) {
String launchProjectName = LaunchUtils.getLaunchProjectName(launchResource);
IProject launchProject = ResourcesPlugin.getWorkspace().getRoot().getProject(launchProjectName);
if (!launchProject.exists()) {
launchProjectName = launchResource.getProject().getName();
}
modifiedConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, launchProjectName);
}
return super.getLaunch(modifiedConfig.doSave(), mode);
}
Aggregations