Error while using http on trigger

98 views
Skip to first unread message

Emmanuele Prudenzano

unread,
Nov 29, 2016, 3:47:34 PM11/29/16
to mementodatabase
Hi all,
  First of all I love memento. Recently I implement a new trigger on save action for retrive some info using gmaps. the http request work fine on desktop version, but on my android app I got the error "org.mozilla.javascript.EvaluatorException: The http request not available for this runtime"

I missing something or is a bug of android?

Thanks in advance

Bill Crews

unread,
Nov 29, 2016, 6:56:27 PM11/29/16
to mementodatabase
If it is an HTTP post operation, I know that is not advertised to work on either platform; in that case, maybe you just got lucky on the desktop platform. If it is a get, I don't know. You could add some info and tell sup...@MementoDatabase.com. I'd add the entire text of the exception and the text of the HTTP request itself. Maybe they'll provide a response.

Emmanuele Prudenzano

unread,
Nov 30, 2016, 3:33:22 PM11/30/16
to mementodatabase
Hi Bill, thanks for replay. As you suggest I send this information also to support.

The request is an HTTP GET. Working fine on desktop (test from trigger and on save item) and on android 4.1.2 from test trigger.

if run after save (async) I got the error. 

Trigger:
var e = entry();
var da = e.field("da");
var a = e.field("a");
log(a);
log(da);
url = url.replace(/ /g, "+");
log(url);
result = http().get(url); 
log(result.code);
if ( result.code == 200 ) {
distance = JSON.parse(result.body)["routes"][0]["legs"][0]["distance"]["text"];
log(distance);
message("distance is "+ distance);
e.set("distanza",parseInt(distance)*2);
}

on Android 4.1.2 if run from test trigger
30/nov/2016 21:17:32 
INFO: parma
30/nov/2016 21:17:32 
INFO: Milano
30/nov/2016 21:17:32 
INFO: https://maps.googleapis.com/maps/api/directions/json?origin=Milano&destination=parma
30/nov/2016 21:17:33 
INFO: 200
30/nov/2016 21:17:33 
INFO: 125 km
30/nov/2016 21:17:33 
INFO: Successfully executed trigger Calcolate Distance for 1023 ms

if run on after save (so in normal usage)
30/nov/2016 21:18:38 
INFO: parma
30/nov/2016 21:18:38 
INFO: Milano
30/nov/2016 21:18:38 
INFO: https://maps.googleapis.com/maps/api/directions/json?origin=Milano&destination=parma
30/nov/2016 21:18:38 
INFO: Can't execute trigger Calcola Distanza on Create
org.mozilla.javascript.EvaluatorException: The http request not available for this runtime (Calcola Distanza on Create.js#18)
	at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:77)
	at org.mozilla.javascript.Context.reportRuntimeError(Context.java:954)
	at org.mozilla.javascript.Context.reportRuntimeError(Context.java:1010)
	at com.luckydroid.droidbase.triggers.TriggerScriptScope.http(TriggerScriptScope.java:157)
	at java.lang.reflect.Method.invokeNative(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:511)
	at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:126)
	at org.mozilla.javascript.FunctionObject.call(FunctionObject.java:450)
	at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1479)
	at script(Calcola Distanza on Create.js:18)
	at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:815)
	at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:109)
	at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
	at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3282)
	at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:120)
	at org.mozilla.javascript.Context.evaluateString(Context.java:1219)
	at com.luckydroid.droidbase.triggers.TriggersManager.run(TriggersManager.java:91)
	at com.luckydroid.droidbase.triggers.TriggersManager.event(TriggersManager.java:55)
	at com.luckydroid.droidbase.EditLibraryItemActivity.save(EditLibraryItemActivity.java:717)
	at com.luckydroid.droidbase.EditLibraryItemActivity.access$000(EditLibraryItemActivity.java:102)
	at com.luckydroid.droidbase.EditLibraryItemActivity$1.onClick(EditLibraryItemActivity.java:261)
	at android.view.View.performClick(View.java:4191)
	at android.view.View$PerformClick.run(View.java:17229)
	at android.os.Handler.handleCallback(Handler.java:615)
	at android.os.Handler.dispatchMessage(Handler.java:92)
	at android.os.Looper.loop(Looper.java:137)
	at android.app.ActivityThread.main(ActivityThread.java:4963)
	at java.lang.reflect.Method.invokeNative(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:511)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
	at dalvik.system.NativeStart.main(Native Method)

Bill Crews

unread,
Nov 30, 2016, 5:15:11 PM11/30/16
to mementodatabase
Very good error reporting, Emmanuele. I didn't realize there is a difference between the synchronous and asynchronous cases on Android. That would seem to be a big clue.

I proofread your code, but it seems airtight; The only nit I would pick is to add var to result = http().get(url), which is not your problem. Yes, it appears to me that asynchronous triggers in the mobile edition have a runtime configuration issue, at least in Android 4.1.2. I should say, though, that that's not a very current Android; upgrading that might help. Let's see what support has to say. I'd appreciate your letting us know.

I didn't realize the desktop edition had triggers yet. I'm still mostly on the mobile edition. I should update my desktop software.

Emmanuele Prudenzano

unread,
Dec 14, 2016, 4:42:02 AM12/14/16
to mementodatabase
I guys, just an update after memento support.

http seems not working during "Befor Save Event".  Just moving it in "after save event" works fine.

many thanks to Vasya Egorov for support.

Bill Crews

unread,
Dec 14, 2016, 4:53:29 AM12/14/16
to mementodatabase
Thanks for reporting back!

Bill Crews

unread,
Dec 14, 2016, 4:58:36 AM12/14/16
to mementodatabase
I was going to update the Triggers wiki page about the requirement that the script be asynchronous, but it actually already says that! I thought it was a recommendation, rather than a requirement; I'll make that clearer. Now, thanks to you, we know.

Marco Dal Monte

unread,
Jun 19, 2017, 5:14:08 AM6/19/17
to mementodatabase
Buongiorno Emmanuele, avrei piacere a discutere con lei un possibile incarico lavorativo. Apprezzerei se volesse scrivermi in privato a marco.tra...@gmail.com con i suoi riferimenti telefonici, possibilmente oggi stesso.
Grazie
Marco Dal Monte
Reply all
Reply to author
Forward
0 new messages