Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: How do I disable a component on a service-builder bundle?
Hi,
I'm trying to override com-liferay-calendar's EmailNotificationSender(https://github.com/liferay/com-liferay-calendar/blob/b08808950ca37bfbe57913db198335afe88ab236/calendar-service/src/main/java/com/liferay/calendar/notification/impl/EmailNotificationSender.java). I used an OSGi Fragment Bundle (https://liferay.dev/blogs/-/blogs/osgi-fragment-bundles) to do this. However, whenever I deploy this fragment, I get the ff. exception:
2019-07-10 17:07:14.706 ERROR [Start Level: Equinox Container: 00748f1f-35a3-0019-1fe6-d9dd9d798b39][com_liferay_calendar_service:103] [com.liferay.calendar.notification.impl.EmailNotificationSender] Cannot register Component
org.osgi.service.component.ComponentException: The component name 'com.liferay.calendar.notification.impl.EmailNotificationSender' has already been registered by Bundle 152 (com.liferay.calendar.service) as Component of Class com.liferay.calendar.notification.impl.EmailNotificationSender
This makes sense, since the linked blog does state that fragments can only append files, not replace them. The next logical step appears to be ensuring that the original NotificationSender is unregistered, before attempting to register EmailNotificationSender. Is this possible? If so, how do I go about doing this? If not, what alternative can I pursue?
I'm trying to override com-liferay-calendar's EmailNotificationSender(https://github.com/liferay/com-liferay-calendar/blob/b08808950ca37bfbe57913db198335afe88ab236/calendar-service/src/main/java/com/liferay/calendar/notification/impl/EmailNotificationSender.java). I used an OSGi Fragment Bundle (https://liferay.dev/blogs/-/blogs/osgi-fragment-bundles) to do this. However, whenever I deploy this fragment, I get the ff. exception:
2019-07-10 17:07:14.706 ERROR [Start Level: Equinox Container: 00748f1f-35a3-0019-1fe6-d9dd9d798b39][com_liferay_calendar_service:103] [com.liferay.calendar.notification.impl.EmailNotificationSender] Cannot register Component
org.osgi.service.component.ComponentException: The component name 'com.liferay.calendar.notification.impl.EmailNotificationSender' has already been registered by Bundle 152 (com.liferay.calendar.service) as Component of Class com.liferay.calendar.notification.impl.EmailNotificationSender
This makes sense, since the linked blog does state that fragments can only append files, not replace them. The next logical step appears to be ensuring that the original NotificationSender is unregistered, before attempting to register EmailNotificationSender. Is this possible? If so, how do I go about doing this? If not, what alternative can I pursue?
I think you can do this another way.
You might need to dig through the source code to see how it's referenced where you want to override it. If it's done with a @Reference, you should be able to get your component in there with a high service.ranking on your osgi component.
If it's retrieved from NotificationSenderFactory, you could override the original one by making sure your component activates after the original so it will get replaced in the hashmap.
You might need to dig through the source code to see how it's referenced where you want to override it. If it's done with a @Reference, you should be able to get your component in there with a high service.ranking on your osgi component.
If it's retrieved from NotificationSenderFactory, you could override the original one by making sure your component activates after the original so it will get replaced in the hashmap.
I thought I was clear in my blog that OSGi fragment bundles could not replace classes from the host bundle, only jsp files or add new files. Existing classes can't be touched because the default order of class loading comes from the host bundle first, the fragment bundle second.
The next logical step appears to be ensuring that the original NotificationSender is unregistered, before attempting to register EmailNotificationSender. Is this possible? If so, how do I go about doing this? If not, what alternative can I pursue?
In an ideal world, you'd be on 7.0.6 GA5 or later, or you're on 7.1 or 7.2, and you'd just blacklist the original NotificationSender component.
If you're on 7.0.5 GA4 or earlier, the process is more complicated, because you'll need to use the ServiceComponentRuntime in order to lookup the ComponentDescriptionDTO to disable the component. This process is described in an earlier forum thread.
In an ideal world, you'd be on 7.0.6 GA5 or later, or you're on 7.1 or 7.2, and you'd just blacklist the original NotificationSender component.
If you're on 7.0.5 GA4 or earlier, the process is more complicated, because you'll need to use the ServiceComponentRuntime in order to lookup the ComponentDescriptionDTO to disable the component. This process is described in an earlier forum thread.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™