EJB and OSGI with JBoss App-Server 7.1.1.Final
jerry_sky Mar 15, 2012 3:07 PMHi,
I have downloaded the actual JBoss Application Server 7 (jboss-as-7.1.1.Final) and I plan a Software-Architecture to use OSGI-Services from EJB-Stateless-Session-Bean. At this reason I implement a small prototype, a simple EJB-Echo-Bean to call a OSGI-Service.
To inject the BundleContext in the Stateless-EJB I use the @Resource-Annotation
- Mr. Diesler describe this solution in https://docs.jboss.org/author/display/JBOSGI/Application+Server+Integration to inject the BundleContext.
Here is the my simple EJB
@Stateless
public class EchoService implements EchoServiceLocal, EchoServiceRemote {
@Resource
BundleContext context;
EchoIF service;
:
@PostConstruct
public void init() {
:
}
@Override
public String echo(String str) {
if(service != null) {
return "OSGI: " + service.echo(str);
} else if(context != null) {
return "context: " + str;
} else {
return str;
}
}
}
But, the App-Container cannot deploy my EAR with the EchoService, because they throws a Exception like this:
:
Caused by: java.lang.IllegalArgumentException: Can not set org.osgi.framework.BundleContext field de.echo.EchoSe
rvice.context to org.jboss.osgi.framework.internal.SystemBundleContext
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146
) [rt.jar:1.6.0_25]
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150
) [rt.jar:1.6.0_25]
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63) [rt.jar:1.6.0_25
]
at java.lang.reflect.Field.set(Field.java:657) [rt.jar:1.6.0_25]
at org.jboss.as.ee.component.ManagedReferenceFieldInjectionInterceptorFactory$ManagedReferenceFieldInjec
I found many other people with the same problem.
I've tested a few solutions that are described here:
https://community.jboss.org/thread/172622?start=15&tstart=0
http://web.archiveorange.com/archive/v/wr91MTZQ817J3WkPms5p
But none of these Solutions works.
Have anybody a idea?
Need the App-Container a special Module or a special configuration to inject the Bundle-Context in EJB´s?
https://docs.jboss.org/author/display/AS7/OSGi+Subsystem+Configuration
thanks,
Jerry