kamilfb / mqtt-spy

Please use the new Eclipse Paho GitHub repo instead.
https://github.com/eclipse/paho.mqtt-spy/wiki
346 stars 68 forks source link

unable to reference "message" object in script #90

Closed danielyjc closed 8 years ago

danielyjc commented 8 years ago

Hi Kamil,

I've been working on a simple script to enrich a message from mqtt-spy (with UI). However, I noticed that spy fails to find a reference for "message" object in script.

Here's an excerpt of my script: mqttspy.publish(message.getTopic(), message.getPayload(), message.getQoS(), message.isRetained());

Following is the log I captured:

2016-07-15 12:15:29,488 ERROR [ScriptRunner ] - Script execution exception javax.script.ScriptException: ReferenceError: "message" is not defined in at line number 2 at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:467) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:451) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:403) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:399) at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:150) at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249) at pl.baczkowicz.spy.scripts.ScriptRunner.runScript(ScriptRunner.java:145) at pl.baczkowicz.spy.scripts.ScriptRunner.run(ScriptRunner.java:106) at java.lang.Thread.run(Thread.java:745) Caused by: :2 ReferenceError: "message" is not defined at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57) at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:319) at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:291) at jdk.nashorn.internal.objects.Global.noSuchProperty(Global.java:1426) at jdk.nashorn.internal.scripts.Script$17$^eval_.:program(:2) at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:637) at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494) at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:446) ... 7 more

Can you take a look and tell me if I'm doing anything wrong?

kamilfb commented 8 years ago

Hi @danyj86! Could you tell me a bit more on how you are trying to run this script? Is it from the Publish with script button, from the script list, or on message received?

danielyjc commented 8 years ago

Hi Kamil,

I've been trying to run script from "Scripted Publications" pane.

mqtt-spy-publication-script

Normally, I'd have a topic and a plane string message on "Publish Message" pane, so each message I publish can be dynamically enriched.

kamilfb commented 8 years ago

I see - so the way to do it not to use "Start" from the Scripted publications pane, but use the Publish button instead (from the Publish message pane). Click on the arrow of the Publish button to see the menu, and change to "Publish with script", picking the script you want to use. If you simply start a script, it doesn't know about the "message" object. If you do it as "Publish with script" from the "Publish message" pane, it should pick it up. Let me know if that works for you.

danielyjc commented 8 years ago

Thanks, it works!

kamilfb commented 8 years ago

Cool, thanks for confirming!

MiaLinke commented 7 years ago

Hi Kamil, I am trying that Testcases Pubsub test with mqtt spy and that works very well. Thank you that is really very helpful. My question is that, is that possible to use protobuf for encoding and decoding the messages in that Test cases.

waiting for reply,,,:)

kamilfb commented 7 years ago

sure you can! could you raise a separate issue and i will try to explain...