Message Boards
OSGi component override for Servlet Filter needs to be manually redeployed
Krzysztof Gołębiowski, modified 3 Years ago.
OSGi component override for Servlet Filter needs to be manually redeployed
Liferay Master Posts: 549 Join Date: 6/25/11 Recent Posts
Hello Everyone,
Some time ago I created an OSGi service override for CASFilter to support multiple domains for different sites. I've described everything in this blog post, so you can see the entire solution straight away (the actual implementation is in MultidomainCASFilter).
My module works very well until the server is restarted when it gets disabled and in order to reenable, I have to deploy the plugin again. I think the reason behind this might be the default static reference policy, which says the container to use the old component until it is explicitly reactivated or becomes unavailable.
First, I was thinking about reconfiguring the service reference with OSGi .config file as it is written here. The problem though is that filters are not explicitly referenced as they are part of Filter Chain, so I assume they are dynamically resolved somewhere deep in the Liferay code.
Any ideas about how to fix it?
KG
Some time ago I created an OSGi service override for CASFilter to support multiple domains for different sites. I've described everything in this blog post, so you can see the entire solution straight away (the actual implementation is in MultidomainCASFilter).
My module works very well until the server is restarted when it gets disabled and in order to reenable, I have to deploy the plugin again. I think the reason behind this might be the default static reference policy, which says the container to use the old component until it is explicitly reactivated or becomes unavailable.
First, I was thinking about reconfiguring the service reference with OSGi .config file as it is written here. The problem though is that filters are not explicitly referenced as they are part of Filter Chain, so I assume they are dynamically resolved somewhere deep in the Liferay code.
Any ideas about how to fix it?
KG
Christoph Rabel, modified 3 Years ago.
RE: OSGi component override for Servlet Filter needs to be manually redeplo
Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent Posts
Maybe it helps if your module is activated later?
https://help.liferay.com/hc/en-us/articles/360018168631-Waiting-on-Lifecycle-Events-
https://help.liferay.com/hc/en-us/articles/360018168631-Waiting-on-Lifecycle-Events-
[code] @Reference(target = ModuleServiceLifecycle.PORTAL_INITIALIZED)
private ModuleServiceLifecycle _portalInitialized;
That way, your module is only activated when the portal is initialized. No idea if it makes a difference but since it is easy to test ...
Krzysztof Gołębiowski, modified 3 Years ago.
RE: OSGi component override for Servlet Filter needs to be manually redeplo
Liferay Master Posts: 549 Join Date: 6/25/11 Recent Posts
Thanks for the suggestion, it worked! Actually that makes sense, now the Filter is started after all the others are initialized so it overrides the default CASFilter. I'll update my blog so the knowledge is saved
I feel though that this is still kind of a workaround and there should be some way to override servlet Filters declaratively but I also think this is how it was implemented in Liferay for now so... we cannot do anything more.
I feel though that this is still kind of a workaround and there should be some way to override servlet Filters declaratively but I also think this is how it was implemented in Liferay for now so... we cannot do anything more.
Christoph Rabel, modified 3 Years ago.
RE: OSGi component override for Servlet Filter needs to be manually redeplo
Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent Posts
I agree, it should be controlled by service ranking.
I could be totally off, but I believe these classes are relevant:
https://github.com/liferay/liferay-portal/blob/7.3.x/portal-kernel/src/com/liferay/portal/kernel/servlet/filters/invoker/InvokerFilterHelper.java
Looks like a map <filtername, filter> and if a new filter with the same name appears, it replaces the previous filter. It probably should check the service ranking of the filter or something like that and only then replace it in the map.
I could be totally off, but I believe these classes are relevant:
https://github.com/liferay/liferay-portal/blob/7.3.x/portal-kernel/src/com/liferay/portal/kernel/servlet/filters/invoker/InvokerFilterHelper.java
Looks like a map <filtername, filter> and if a new filter with the same name appears, it replaces the previous filter. It probably should check the service ranking of the filter or something like that and only then replace it in the map.
Olaf Kock, modified 3 Years ago.