OSGI dude, overriding JournalArticleSitemapURLProvider

Javier Lamadrid, modified 6 Years ago. New Member Posts: 15 Join Date: 4/8/19 Recent Posts
Hi!,

What is the correct way to override the JournalArticleSitemapURLProvider service to create a custom sitemap in direct web content?.

If I simply create a SitemapURLProvider service for the JournalArticle classname(*) it works when deployed the first time, but when the server is restarted, the service is registered first and the one that is treated is Liferay (JournalArticleSitemapUrlProvider). Even if a "service.ranking: Integer = 100" is added.
Curiously, if I do the same with a negative ranking, it seems to work correctly, but so a priori it seems to me that I am not doing the right thing emoticon

(*)

@Component (immediate = true, service = SitemapURLProvider.class)
public class CustomJournalArticleSitemapUrlProvider implements SitemapURLProvider {
@Override
public String getClassName () {
return JournalArticle.class.getName ();
}


Regards,
thumbnail
David H Nebinger, modified 6 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts
Keep your component as is. Just add the Liferay component to the blacklist to prevent it from starting and taking your component's place.
Javier Lamadrid, modified 6 Years ago. New Member Posts: 15 Join Date: 4/8/19 Recent Posts
It works correctly, thank you very much David!

I would like to ask you another question: What about "com.liferay.portal.util.LayoutSitemapURLProvider"? In this case there is no @Component annotation, instead there is an @OSGiBeanProperties and it cannot be added to the blacklist (or I don't know how to). On the other hand, the unorthodox solution of the negative ranking seems to continue working, is there a more correct solution?. Thank you very much in advance.
Regards.
thumbnail
Minhchau Dang, modified 6 Years ago. Liferay Master Posts: 598 Join Date: 10/22/07 Recent Posts
Javier Lamadrid:
What about "com.liferay.portal.util.LayoutSitemapURLProvider"?

It's injected via layout-spring.xml, so it ends up being part of the system bundle 0, which is probably not compatible with the way Liferay implemented component blacklists (from reading the code, it seems like it watches for non-system bundle start events, though I could be wrong).

As a workaround, you could add a custom layout-spring.xml to Liferay's WEB-INF/classes/META-INF that comments out the reference to the class so that no Spring bean gets created (and thus no OSGi component gets injected once the portal is initialized). In the future (7.3 and beyond), it should be possible to blacklist it because it's moved outside of system bundle 0 with LPS-97978.
Javier Lamadrid, modified 6 Years ago. New Member Posts: 15 Join Date: 4/8/19 Recent Posts
I check it, thank you very much Minhchau!

Regards