Hi all, I've been looking for info on this topic with no avail. I'm currently using PAX-Web (Pax Web - WAR Extender) to run a number of servlets in a WAB. I'm working on Equinox. Legacy code used programmatic service lookup to access other OSGi services (Service Tracker) but I've refactored most of the code base to use Declarative Services instead. (that solved several start-up order issues in the process)
My issue is that Declarative Services dependency injection is not working with PAX-Web loaded servlets. If I include a OSGI-INF/service.xml file declaring the servlet dependencies, the class is loaded twice: Once by DS and once by PAX-WEB. Logically, only the class loaded by DS is injected with any dependencies declared. DS: at org.eclipse.equinox.internal.ds.model.ServiceComponent.*createInstance* (ServiceComponent.java:480) at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.createInstance(ServiceComponentProp.java:271) at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:332) at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:588) at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:196) at org.eclipse.equinox.internal.ds.Resolver.getEligible(Resolver.java:328) at org.eclipse.equinox.internal.ds.SCRManager.serviceChanged(SCRManager.java:221 PAX-WEB: at org.ops4j.pax.web.extender.war.internal.RegisterWebAppVisitorHS.* newInstance*(RegisterWebAppVisitorHS.java:225) at org.ops4j.pax.web.extender.war.internal.RegisterWebAppVisitorWC.visit(RegisterWebAppVisitorWC.java:202) at org.ops4j.pax.web.extender.war.internal.model.WebApp.accept(WebApp.java:583) at org.ops4j.pax.web.extender.war.internal.WebAppPublisher$HttpServiceListener.register(WebAppPublisher.java:170) at org.ops4j.pax.web.extender.war.internal.WebAppPublisher$HttpServiceListener.serviceChanged(WebAppPublisher.java:155) at org.ops4j.pax.web.extender.war.internal.WebAppPublisher$HttpServiceListener.serviceChanged(WebAppPublisher.java:119) at org.ops4j.pax.swissbox.tracker.ReplaceableService.setService(ReplaceableService.java:114) at org.ops4j.pax.swissbox.tracker.ReplaceableService.access$100(ReplaceableService.java:28) at org.ops4j.pax.swissbox.tracker.ReplaceableService$CollectionListener.serviceAdded(ReplaceableService.java:183) at org.ops4j.pax.swissbox.tracker.ServiceCollection$Tracker.addingService(ServiceCollection.java:181) I worked around this situation by declaring the references to the services static and synchronizing the access (not very nice. Might impact performance), eg. public synchronized void onServiceUp(FooService svc) { ClassImpl.fooService = svc; } but I've a situation now where I do need an instance of a service injected for each servlet instance created, so the synchronized hack approach won't work. I also tried to declare the servlet and its dependecies using the OSGi way, by declaring this servlet to offer a javax.servlet.Servlet service: [ <property name="alias" type="String" value="/main/fooservice"/> <property name="servlet-name" type="String" value="FooServlet"/ --> <service> <provide interface="javax.servlet.Servlet"/> </service>] But given that the servlet is also in the WAR, PAX-Web finds it and tries to register it, resulting in a 'WAR: Http context already used' like described here: http://www.mail-archive.com/general@lists.ops4j.org/msg11221.html So, to summarize my question: Is there a correct/recommended way to use Declarative Services (DS) with Pax Web- War extender and if so, what are the best practices? Many thanks, Gerard.
_______________________________________________ general mailing list general@lists.ops4j.org http://lists.ops4j.org/mailman/listinfo/general