Rhino JavaScript working on App Engine Java Edition


I was super-excited this morning, when I saw the announcement that Google had released a Java version of their App Engine environment. My heart sank a bit when I read that they had a class white-list for security reasons, and told myself that I wouldn't be surprised if that means that you cant run Server-side JavaScript at all.

However, after reading Ola Bini's quick article on how to enable JRuby, I felt that it might be doable, after all, JS doesn't even have Threads (which more or less thankfully are disabled in GAE). It _should_ work.  

So I went and downloaded the eclipse plugin, created a new project, which came with its own "Hello World" servlet and dropped the Mozilla labs JS version 1.7 jar (from the Dojo Ajax Toolkit's util/shrinksafe folder) into the lib/ folder of the GAE project, added some paths here and there -- and it worked.

I tried something really simple like this;

...

String s = "var foo = {foo: 17, bar: 4711}; foo.foo;";

Object result = cx.evaluateString(scope, s, "", 1, null);

resp.getWriter().println(Context.toString(result));

...

And out I got a 

17

:)

I just saw that Google has limited the Java GAE SDK for the 10 first to register. I guess Sweden was the right place to be :)  If you want to see my sample project, you can download it from here;

http://genericwitticism.com/rhino.zip

Cheers,
PS

Comments

Roberto Saccon said…
Cool, Peter, now we got what we have been waiting for ! Was offline yesterday, and today, after googeling for appengine and rhino this was the top entry !
Ivan said…
i almost can't wait to get home to try this out. unfortunately, i'll have to :(
Script Uncle said…
@Roberto Saccon :) That's good to hear. Now I'll just try to find time to read in a file and to port the REST server interface I did for Babble/10gen.

@Ivan: Work is soon over! Time to play.
Sam said…
Nice to see another language work.

I wrote aboutn bringing up a sinatra app.
You can find it here.

http://blog.bigcurl.de

Thanks
Sam
hannes said…
This comment has been removed by the author.
hannes said…
It runs very well indeed. If you're seriously interested in running Rhino on App Engine, make sure you check out Helma NG, a compact yet powerful server-side JS runtime based on Rhino.

http://helma-ng.appspot.com/
Script Uncle said…
@Hannes Wallnoefer: You're right of course. I hadn't even thought of that yet, having a lot to do. It all depends on what kind of magic Helma does with Java under the hood, since the GAE/J has a class whitelist. No dojox.tools, for example, and so on. No Threads stuff. But either it would work directly, or it will be possibly to do a 'Helma lite' och 'Helma GAE' version, I'm sure.

Thanks for the idea!
Maksim Lin said…
Peter, I think what Hannes meant is that helma-ng is already running well on App Engine.

Hannes has posted a howto on itAnd in his comment above is the link to the demo app running on appspot.
Script Uncle said…
@Makrim Lin: You are right, of course. Maybe it wold help if I actually read what I was commenting :)