Send notifications via jython script

Using openhab 3.1 with jython helper libraries.
Normal actions like Voice.say work fine but WebPushNotificationAction.sendHABotNotification produces the following runtime exception:


java.lang.RuntimeException

obj.localizedMessage = u'java.lang.ClassNotFoundException'

obj.stackTrace = array(java.lang.StackTraceElement, [javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:50), javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:55), org.openhab.ui.habot.notification.internal.webpush.PushService.send(PushService.java:156), org.openhab.ui.habot.notification.internal.NotificationService.sendNotification(NotificationService.java:128), org.openhab.ui.habot.notification.internal.NotificationService.broadcastNotification(NotificationService.java:110), org.openhab.ui.habot.notification.WebPushNotificationAction.sendHABotNotificationExt(WebPushNotificationAction.java:101), org.openhab.ui.habot.notification.WebPushNotificationAction.sendHABotNotification(WebPushNotificationAction.java:46), java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method), java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62), java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43), java.base/java.lang.reflect.Method.invoke(Method.java:566), org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190), org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:208), org.python.core.PyObject.__call__(PyObject.java:461), org.python.core.PyObject.__call__(PyObject.java:465), org.python.pycode._pyx1035.pushReport$11(/etc/openhab/automation/jsr223/python/personal/00_routines_statuschecks.py:117), org.python.pycode._pyx1035.call_function(/etc/openhab/automation/jsr223/python/personal/00_routines_statuschecks.py), org.python.core.PyTableCode.call(PyTableCode.java:173), org.python.core.PyBaseCode.call(PyBaseCode.java:150), org.python.core.PyFunction.__call__(PyFunction.java:426), org.python.core.PyMethod.__call__(PyMethod.java:141), org.python.pycode._pyx1035.handleInvokeLeave$13(/etc/openhab/automation/jsr223/python/personal/00_routines_statuschecks.py:142), org.python.pycode._pyx1035.call_function(/etc/openhab/automation/jsr223/python/personal/00_routines_statuschecks.py), org.python.core.PyTableCode.call(PyTableCode.java:173), org.python.core.PyBaseCode.call(PyBaseCode.java:150), org.python.core.PyFunction.__call__(PyFunction.java:426), personal.composer$py._wrapper$10(/etc/openhab/automation/lib/python/personal/composer.py:77), personal.composer$py.call_function(/etc/openhab/automation/lib/python/personal/composer.py), org.python.core.PyTableCode.call(PyTableCode.java:173), org.python.core.PyBaseCode.call(PyBaseCode.java:150), org.python.core.PyFunction.__call__(PyFunction.java:426), org.python.core.PyMethod.__call__(PyMethod.java:141), personal.composer$py.execute$3(/etc/openhab/automation/lib/python/personal/composer.py:28), personal.composer$py.call_function(/etc/openhab/automation/lib/python/personal/composer.py), org.python.core.PyTableCode.call(PyTableCode.java:173), org.python.core.PyBaseCode.call(PyBaseCode.java:306), org.python.core.PyBaseCode.call(PyBaseCode.java:197), org.python.core.PyFunction.__call__(PyFunction.java:485), org.python.core.PyMethod.instancemethod___call__(PyMethod.java:237), org.python.core.PyMethod.__call__(PyMethod.java:228), org.python.core.PyMethod.__call__(PyMethod.java:218), org.python.core.PyMethod.__call__(PyMethod.java:213), org.python.core.PyObject._jcallexc(PyObject.java:3565), org.python.core.PyObject._jcall(PyObject.java:3598), org.python.proxies.personal.composer$__RelayRule$2015.execute(Unknown Source), org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleRuleActionHandlerDelegate.execute(SimpleRuleActionHandlerDelegate.java:34), org.openhab.core.automation.module.script.rulesupport.internal.delegates.SimpleActionHandlerDelegate.execute(SimpleActionHandlerDelegate.java:59), org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1183), org.openhab.core.automation.internal.RuleEngineImpl.runRule(RuleEngineImpl.java:991), org.openhab.core.automation.internal.TriggerHandlerCallbackImpl$TriggerData.run(TriggerHandlerCallbackImpl.java:90), java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515), java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264), java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304), java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128), java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628), java.base/java.lang.Thread.run(Thread.java:829)])

A rule with the classic rule engine that just states:


rule "habot.notify"

when 

    Item TestSwitch1 changed to ON

then

    sendHABotNotification("foo")

end

produces something quite similar:

2021-07-28 09:06:04.327 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘test-1’ failed: java.lang.ClassNotFoundException in test

On the other hand, a rule clicked together in UI works just fine
code of the rule:

triggers: []
conditions: []
actions:
  - inputs: {}
    id: "1"
    configuration:
      body: Ring Ring Ring
    type: habot.WebPushNotificationAction

Please help

Now I made another rule via UI and gave it some trigger item. This rule now works fine just as the one before if I click “Run” in UI.
If it is triggered via its “item changed” trigger, I get:

2021-07-28 16:24:00.688 [ERROR] [e.automation.internal.RuleEngineImpl] - Failed to execute rule '8a5d30fc3f': Fail to execute action: 3

In Python you usually need to import the actions. I don’t know if the Helper Libraries import the HABot Actions.

Import org.openhab.ui.habot.notification.WebPushNotificationAction and see if that helps it find the action.

Helper libs import the actions automatically. You can see in the stack trace that the action gets called but fails in javax.ws.rs.client.ClientBuilder.newBuilder - a method already implemented in Java.

I don’t think this is related to missing imports but I have not much experience with openhab internals…

I also added the suggested import to my test rule.
It now reads


import org.openhab.ui.habot.notification.WebPushNotificationAction

rule "habot.notify"
when 
    Item TestSwitch1 changed to ON
then

    WebPushNotificationAction.sendHABotNotification("foo")

end

But I still get an error as soon as it is triggered:

2021-07-28 18:58:46.409 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'test-1' failed: java.lang.ClassNotFoundException in test

Searching the top frame from my exceptions stack brings up other openhab 3 related topics:

[neeo] Can Not Add Brain - OH3 · Issue #8984 · openhab/openhab-addons · GitHub
[tesla] Failed to find JAX-RS Client · Issue #7775 · openhab/openhab-addons · GitHub

Perhaps this is helpful for someone with a little more insight into openhab mechanics…

After a lot of playing around I suspect a bug in HABot.
I think notification are broken for openhab 3.x. Can anyone confirm that notifications are working on a similar OH 3 installation?

runtimeInfo:
  version: 3.1.0
  buildString: Release Build
locale: de-AT
systemInfo:
  configFolder: /etc/openhab
  userdataFolder: /var/lib/openhab
  logFolder: /var/log/openhab
  javaVersion: 11.0.11
  javaVendor: Azul Systems, Inc.
  javaVendorVersion: Zulu11.48+21-CA
  osName: Linux
  osVersion: 5.4.73-1-pve
  osArchitecture: amd64
  availableProcessors: 2
  freeMemory: 90867176
  totalMemory: 702545920

[tesla] Failed to find JAX-RS Client · Issue #7775 · openhab/openhab-addons · GitHub appears really similar indeed.
Looking at the fix ([tesla] Use CXF JAX-RS client builder, if available. by kaikreuzer · Pull Request #7789 · openhab/openhab-addons · GitHub) it seems that instead of ClientBuilder.newClient() here:

It should get a ClientBuilder instance via dependency injection and call build() instead now. This supposes some refactoring…

While this looks like an easy change, I see no way I could do that alone with my level of experience regarding openhab internals.

How could this get more attention so we might get a fix soon? Perhaps it would be enough to give me some guidance on the dependency injection systems used here so I might get a PR together…