Re: Can a DS component expose multiple services?
> Jean-Baptiste Onofré : > Yes, it' possible to have several services by component (imho, it > should be avoided when possible to avoid unexpected cascading > refresh). > A component can implement multiple interfaces, and the @Component > annotation accepts the list of exposed interfaces. Yep, I found out. :-) Working example code further down the thread.
Re: Can a DS component expose multiple services?
Hi, Yes, it' possible to have several services by component (imho, it should be avoided when possible to avoid unexpected cascading refresh). A component can implement multiple interfaces, and the @Component annotation accepts the list of exposed interfaces. Regards JB On Sat, Mar 16, 2024 at 7:44 AM Steinar Bang wrote: > > Can a Java class implementing a DS component expose more than one > OSGi service? > > My usecase is that I have a DS component implementing a servlet Filter, > plugging into the web whiteboard. > > https://github.com/steinarb/oldalbum/blob/master/oldalbum.web.security/src/main/java/no/priv/bang/oldalbum/web/security/OldAlbumShiroFilter.java#L35 > > And then I would like a way to retrigger configuration of the filter and > the simplest way would be if the filter could expose a service with a > method that could be used to trigger reconfiguration. > > What if I subtype the Filter interface with a new interface and expose > that interface from the component, would still be able to "find" the web > whiteboard? (I think not, because if I remember correctly if a class > does not directly implement an interface, the interface for the service > must be specified in @Component annotation...?) > > Hm... looks like the service parameter of @Component can be an array...? > > https://docs.osgi.org/specification/osgi.cmpn/8.0.0/service.component.html#org.osgi.service.component.annotations.Component.service-- > > I'll try. > > Hm... looks like the Filter interface has an init() method...? > > https://docs.oracle.com/cd/E17802_01/products/products/servlet/2.5/docs/servlet-2_5-mr2/javax/servlet/Filter.html#init(javax.servlet.FilterConfig) > > Could that be used, I wonder? > > No, implemented by shiro AbstractFilter, probably best not to mess with > that...? > > So: I will try a new interface with a single callback method and inject > that service into a REST endpoint and see if I can make the filter > reconfigure itself. >
Re: Can a DS component expose multiple services?
So, update: Yes a DS component can expose multiple services This worked: https://gist.github.com/steinarb/39e9b4de1ee2ab6da57eea4c7df9e5b5#file-oldalbumshirofilter-java-L39 Filter is picked up fine by the OSGi web whiteboard (verified that I get a login prompt when I expect to get it). And ReloadableShiroFilter is picked up by the Web API and can be used to trigger a shiro filter config reload.
Can a DS component expose multiple services?
Can a Java class implementing a DS component expose more than one OSGi service? My usecase is that I have a DS component implementing a servlet Filter, plugging into the web whiteboard. https://github.com/steinarb/oldalbum/blob/master/oldalbum.web.security/src/main/java/no/priv/bang/oldalbum/web/security/OldAlbumShiroFilter.java#L35 And then I would like a way to retrigger configuration of the filter and the simplest way would be if the filter could expose a service with a method that could be used to trigger reconfiguration. What if I subtype the Filter interface with a new interface and expose that interface from the component, would still be able to "find" the web whiteboard? (I think not, because if I remember correctly if a class does not directly implement an interface, the interface for the service must be specified in @Component annotation...?) Hm... looks like the service parameter of @Component can be an array...? https://docs.osgi.org/specification/osgi.cmpn/8.0.0/service.component.html#org.osgi.service.component.annotations.Component.service-- I'll try. Hm... looks like the Filter interface has an init() method...? https://docs.oracle.com/cd/E17802_01/products/products/servlet/2.5/docs/servlet-2_5-mr2/javax/servlet/Filter.html#init(javax.servlet.FilterConfig) Could that be used, I wonder? No, implemented by shiro AbstractFilter, probably best not to mess with that...? So: I will try a new interface with a single callback method and inject that service into a REST endpoint and see if I can make the filter reconfigure itself.