Calling service PollOutagesConfig from custom plugin

I create custom plugin for scheduled outages.
From plugin I want to call existing service PollOutagesConfig from module opennms-config.

A piece of code from my plugin:

public class ScheduledOutagesServiceImpl implements ScheduledOutagesService {


pollOutagesConfigManager = PollOutagesConfigFactory.getInstance();

Outage outage = pollOutagesConfigManager.getOutage(name)


I initiate service in plugin in this way, becouse methods I need are not available due to the limited interface. For example, I want to have access to the method getOutage from class PollOutagesConfigManager which is the implementation of this interface.

While the application is running and the method getOutage is called, I get the following error:

ERROR | qtp694373482-536 | ErrorResponseProvider | 251 - - 24.1.1 | An exception occurred while processing a rest request in an OSGi Rest Service: org.opennms.netmgt.config.poller.outages.Outage cannot be cast to org.opennms.netmgt.config.poller.outages.Outage
java.lang.ClassCastException: org.opennms.netmgt.config.poller.outages.Outage cannot be cast to org.opennms.netmgt.config.poller.outages.Outage
at java.util.ArrayList.forEach( ~[?:?]
at org.opennms.ext.swing.service.ScheduledOutagesServiceImpl.test( ~[?:?]
at org.opennms.ext.swing.web.ScheduledOutagesRestServiceImpl.notify( ~[?:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at sun.reflect.NativeMethodAccessorImpl.invoke( ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke( ~[?:?]
at java.lang.reflect.Method.invoke( ~[?:?]

Problem is related with method argument Outage (org.opennms.netmgt.config.poller.outage). I guess that the reason is that classloader from bundle
opennms-config and from our plugin are various, that`s why returned object is different.

Does anyone have similar problem and knows how to deal with it?

First thing I would try would be to add the org.opennms.netmgt.config.poller.outages package to $OPENNMS_HOME/etc/, erase $OPENNMS_HOME/data and restart.

I suspect that one of the classes is coming from the root class-loader (bundle 0) and the other is being provided by another bundle. These have the same name, but they come from different class-loaders, so we get this exception.

Thank you very much. I did as you wrote and it works.