0

I'm observing strange behavior in my OSGi application. I basically have several bundles providing the implementation for one service interface. The consuming bundles are supposed to use the implementation of one of these bundles that matches a specific version.

I've been trying to achieve this by first retrieving all services using a filter on the service tracker like this:

serviceTaskTracker = new ServiceTracker(bundleContext, 
bundleContext.createFilter("(objectClass=*ServiceTasks)"), null);
ServiceReference[] serviceReferences = serviceTaskTracker.getServiceReferences();

Subsequently, I'm iterating over the result set

for (ServiceReference serviceReference : serviceReferences) {
        Bundle currentBundle = serviceReference.getBundle();

        try {
            Version currentVersion = currentBundle.getVersion();
        } catch (Throwable e) {
            System.out.println(e);
            e.printStackTrace();
        }

        if (currentVersion.equals(specifiedVersion)) {
            service = (ServiceTasks) bundleContext.getService(serviceReference);
        }
}

Now it crashes when calling currentBundle.getVersion() reporting a "No such method error". This is especially weird to me, as I can step up to that line in Eclipse' debug mode, highlight "currentBundle.getVersion()", press CTRL + Shift + D to execute it and get the expected version of the providing bundle. Pressing F6 to step once more, it crashes.

currentBundle.getClass() returns "(org.eclipse.osgi.framework.internal.core.BundleHost)" before I call getVersion() on it.

The stacktrace looks like this:

java.lang.NoSuchMethodError: org.osgi.framework.Bundle.getVersion()Lorg/osgi/framework/Version; java.lang.NoSuchMethodError: org.osgi.framework.Bundle.getVersion()Lorg/osgi/framework/Version; at de.paas.engine.adapter.activiti.PaasServiceTask.getServiceTaskService(PaasServiceTask.java:69) at de.paas.servicetasks.exampleprocess.SendMailTask.paasExecute(SendMailTask.java:58) at de.paas.engine.adapter.activiti.PaasServiceTask.execute(PaasServiceTask.java:119) at org.activiti.engine.impl.bpmn.helper.ClassDelegate.execute(ClassDelegate.java:115) at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:44) at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525) at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerStart.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerStart.java:52) at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56) at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525) at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:49) at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525) at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionCreateScope.execute(AtomicOperationTransitionCreateScope.java:49) at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525) at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerTake.execute(AtomicOperationTransitionNotifyListenerTake.java:65) at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525) at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionDestroyScope.execute(AtomicOperationTransitionDestroyScope.java:115) at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525) at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerEnd.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerEnd.java:36) at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56) at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525) at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:49) at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.take(ExecutionEntity.java:365) at org.activiti.engine.impl.bpmn.behavior.ExclusiveGatewayActivityBehavior.leave(ExclusiveGatewayActivityBehavior.java:74) at org.activiti.engine.impl.bpmn.behavior.FlowNodeActivityBehavior.execute(FlowNodeActivityBehavior.java:36) at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:44) at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525) at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerStart.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerStart.java:52) at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56) at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525) at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:49) at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525) at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionCreateScope.execute(AtomicOperationTransitionCreateScope.java:49) at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525) at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerTake.execute(AtomicOperationTransitionNotifyListenerTake.java:65) at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525) at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionDestroyScope.execute(AtomicOperationTransitionDestroyScope.java:115) at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525) at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerEnd.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerEnd.java:36) at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56) at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525) at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:49) at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:77) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:530) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:525) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.take(ExecutionEntity.java:365) at org.activiti.engine.impl.bpmn.behavior.BpmnActivityBehavior.performOutgoingBehavior(BpmnActivityBehavior.java:102) at org.activiti.engine.impl.bpmn.behavior.BpmnActivityBehavior.performDefaultOutgoingBehavior(BpmnActivityBehavior.java:51) at org.activiti.engine.impl.bpmn.behavior.FlowNodeActivityBehavior.leave(FlowNodeActivityBehavior.java:44) at org.activiti.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior.leave(AbstractBpmnActivityBehavior.java:47) at org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior.signal(UserTaskActivityBehavior.java:92) at org.activiti.engine.impl.persistence.entity.ExecutionEntity.signal(ExecutionEntity.java:348) at org.activiti.engine.impl.persistence.entity.TaskEntity.complete(TaskEntity.java:149) at org.activiti.engine.impl.cmd.SubmitTaskFormCmd.execute(SubmitTaskFormCmd.java:74) at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24) at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:42) at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33) at org.activiti.engine.impl.FormServiceImpl.submitTaskFormData(FormServiceImpl.java:68) at de.paas.engine.adapter.activiti.ActivitiEngine.submit(ActivitiEngine.java:116) at de.paas.engine.core.ProcessEngineModule.submit(ProcessEngineModule.java:119) at de.paas.handler.ProcessHandler.post(ProcessHandler.java:223) at de.paas.dispatcher.PortalDispatcher.dispatch(PortalDispatcher.java:77) at de.paas.dispatcher.PortalDispatcher.doPost(PortalDispatcher.java:106) at de.paas.controller.FrontController.startService(FrontController.java:87) at de.paas.controller.FrontController.doFilter(FrontController.java:160) at de.paas.filter.core.PaasChain.doFilter(PaasChain.java:28) at de.paas.filter.PaasMessageFilter.doFilter(PaasMessageFilter.java:53) at de.paas.filter.core.PaasChain.doFilter(PaasChain.java:28) at de.paas.filter.PaasAuthorisationFilter.doFilter(PaasAuthorisationFilter.java:31) at de.paas.filter.core.PaasChain.doFilter(PaasChain.java:28) at de.paas.filter.PaasSessionFilter.doFilter(PaasSessionFilter.java:39) at de.paas.filter.core.PaasChain.doFilter(PaasChain.java:28) at de.paas.filter.PaasCallExceptionFilter.doFilter(PaasCallExceptionFilter.java:44) at de.paas.filter.core.PaasChain.doFilter(PaasChain.java:28) at de.paas.dispatcher.PortalDispatcher.service(PortalDispatcher.java:51) at org.eclipse.equinox.http.servlet.internal.ServletRegistration.handleRequest(ServletRegistration.java:91) at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:110) at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:60) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.eclipse.equinox.servletbridge.BridgeServlet.service(BridgeServlet.java:115) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722)

I can only guess this is caused by OSGi magic in the background?! Any help is highly appreciated. Thank you!! Johannes

Johannes
  • 494
  • 4
  • 13
  • Can you provide the stack trace, and also print the class of the bundle before the getVersion() call? There should not be any OSGi magic that can cause this. OSGi only messes with the class loaders. – Francis Upton IV May 24 '12 at 08:12
  • I edited my post and it now shows the return value of currentBundle.getClass() (I hope that's what you meant, is it?) as well as that way too long stack trace. – Johannes May 24 '12 at 08:29
  • Hmmmm, it looks like there is some mismatch in your OSGi implementation between what was compiled and what is executing. However, the class you print out seems correct? How are you executing this? – Francis Upton IV May 24 '12 at 08:34
  • I'm using the Equinox servlet bridge ( http://www.eclipse.org/equinox/server/http_in_container.php ) for an Equinox 3.7.2 OSGi platform within a servlet running on a Tomcat 7 server. – Johannes May 24 '12 at 08:41
  • I can't think of anything at the moment, hopefully someone smarter will come along and help you. Sorry. – Francis Upton IV May 24 '12 at 08:43

2 Answers2

10

The getVersion() method was added to Bundle in version 1.5 of the package org.osgi.framework, i.e. OSGi Release 4.2. It looks like you have compiled against OSGi R4.2 but are actually running on something lower.

This kind of problem can be easily avoided by using version ranges on your Import-Package statement. In this example you should import the org.osgi.framework package as version range [1.5,2.0)... this would then prevent your bundle from resolving on an earlier version of the OSGi framework.

Neil Bartlett
  • 23,743
  • 4
  • 44
  • 77
  • Thanks so much! I never realized I was deploying my bundles to a platform running an old version of OSGi and wouldn't have ever found out about it. Now updating all the bundles... – Johannes May 24 '12 at 14:24
1

Working on a hunch here: I think your code, and the platform code, have a different idea of where the org.osgi.framework package comes from. This can happen when the OSGi API is loaded from different bundles, resulting in classes that have the same name, but are not compatible.

You can try using the console to see how your bundles is wired to the org.osgi.framework package, and see in what way the bundle that produces the Bundle you inspect is wired up. My best guess is that you're embedding too much into your application, which may work correctly while debugging in Eclipse, but gets wired incorrectly while running in Tomcat (depending on the exact way in which you deploy your project).

Angelo van der Sijpt
  • 3,611
  • 18
  • 24