Community
Participate
Working Groups
Build Identifier: 1.0.0.M1 2010-11-12 16:46:33,268 INFO o.e.g.b.c.s.OsgiBundleXmlApplicationContext[]: Publishing application context as OSGi service with properties {org.springframework.context.service.name=com.bosch.msp.security, Bundle-SymbolicName=com.bosch.msp.security, Bundle-Version=0.0.1.SNAPSHOT} 2010-11-12 16:46:33,268 DEBUG o.e.g.b.c.s.OsgiBundleXmlApplicationContext[]: Publishing service under classes {org.eclipse.gemini.blueprint.context.DelegatedExecutionOsgiBundleApplicationContext, org.eclipse.gemini.blueprint.context.ConfigurableOsgiBundleApplicationContext, org.springframework.context.ConfigurableApplicationContext, org.springframework.context.ApplicationContext, org.springframework.context.Lifecycle, org.springframework.beans.factory.ListableBeanFactory, org.springframework.beans.factory.HierarchicalBeanFactory, org.springframework.context.MessageSource, org.springframework.context.ApplicationEventPublisher, org.springframework.core.io.support.ResourcePatternResolver, org.springframework.beans.factory.BeanFactory, org.springframework.core.io.ResourceLoader, org.springframework.beans.factory.DisposableBean} 2010-11-12 16:46:33,268 DEBUG o.e.g.b.c.s.OsgiBundleXmlApplicationContext[]: Post refresh error java.lang.IllegalArgumentException: Service object is not an instance of "org.eclipse.gemini.blueprint.context.DelegatedExecutionOsgiBundleApplicationContext". at org.apache.felix.framework.Felix.registerService(Felix.java:2835) ~[felix.jar:na] at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:251) ~[felix.jar:na] at org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext$3.run(AbstractOsgiBundleApplicationContext.java:353) ~[na:na] at org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext$3.run(AbstractOsgiBundleApplicationContext.java:351) ~[na:na] at java.security.AccessController.doPrivileged(Native Method) ~[na:1.6.0_22] at org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext.publishContextAsOsgiServiceIfNecessary(AbstractOsgiBundleApplicationContext.java:351) ~[na:na] at org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext.finishRefresh(AbstractOsgiBundleApplicationContext.java:223) ~[na:na] at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:328) ~[na:na] at org.eclipse.gemini.blueprint.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85) ~[na:na] at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:290) ~[na:na] at org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:137) ~[na:na] at java.lang.Thread.run(Thread.java:662) ~[na:1.6.0_22] Reproducible: Always Steps to Reproduce: 1. Class public class Spike { private BundleContext bundleContext; public void setBundleContext(final BundleContext bundleContext) { this.bundleContext = bundleContext; System.out.println("setBundleContext called with BundleContext=" + bundleContext); } public void init() { System.out.println("initialized. BundleContext=" + bundleContext); } } 2. Blueprint XML <?xml version="1.0" encoding="UTF-8" standalone="no"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <bean id="spike" class="foo.bar.Spike" init-method="init"> <property name="bundleContext" ref="blueprintBundleContext"/> </bean> </blueprint> 3. Deploy bundle in Apache Felix 3.0.6 with Gemini Bluprint 1.0.0.M1 and Spring dependencies 3.0.5.RELEASE.
Interesting - I recall seeing this problem in the past but don't recall what the issue was. Can you try testing under equinox since the class is an instance of the aforementioned interface and moreover various checks are made when exporting the class.
Created attachment 188580 [details] Supertype hierarchy of AbstractOsgiBundleApplicationContext
Comment on attachment 188580 [details] Supertype hierarchy of AbstractOsgiBundleApplicationContext Hi Costin, with equinox it is working. But I investigated the problem a little bit further and extended Felix implementation at the code lines, the execption is thrown. I Just added to display the service object's classe name and got the following stack trace: java.lang.IllegalArgumentException: Service object is not an instance of "org.eclipse.gemini.blueprint.context.DelegatedExecutionOsgiBundleApplicationContext". Service object class=class org.eclipse.gemini.blueprint.context.support.AbstractOsgiBundleApplicationContext$3 at org.apache.felix.framework.Felix.registerService(Felix.java:2847) ~[felix.jar:na] ... It seems that Gemini tries to register an anonymous instance of AbstractOsgiBundleApplicationContext with objectClass=DelegatedExecutionOsgiBundleApplicationContext I also digged into Gemini and found that AbstractOsgiBundleApplicationContext indeed does not implement the interface DelegatedExecutionOsgiBundleApplicationContext (see attached supertypes hierachy of AbstractOsgiBundleApplicationContext) /Bjoern
We've experienced the same problem when using Spring DM 2.0.0.M1 and found the problem to be the fact that the security manager were active. The real problem in our case is the following code in AbstractOsgiBundleApplicationContext.publishContextAsOsgiServiceIfNecessary: // Publish under all the significant interfaces we see boolean hasSecurity = (System.getSecurityManager() != null); if (hasSecurity) { try { serviceRegistration = AccessController.doPrivileged(new PrivilegedAction<ServiceRegistration>() { public ServiceRegistration run() { return getBundleContext().registerService(serviceNames, AbstractOsgiBundleApplicationContext.this, serviceProperties); } }, acc); } catch (AccessControlException ex) { logger.error("Application context service publication aborted due to security issues " + "- does the bundle has the rights to publish the service ? ", ex); } } else { serviceRegistration = getBundleContext().registerService(serviceNames, this, serviceProperties); } By changing the "this" reference in PrivilegedAction.run to "AbstractOsgiBundleApplicationContext.this" the problem is fixed. /Tomas
Created attachment 190978 [details] Patch against Spring DM subversion revision 2435
fixed in rev #14 Thanks for the detailed report Tomas and Bjoern
marked as closed