Scripting with servlets [sleep] - part IV (Sun Java System WebServer 7.0)
By blue on Jan 17, 2007
Using sleep (A perl like language over JVM) as servlet on Sun Java System WebServer 7.0.
About the language
Sleep is a language inspired by perl. Most of the syntax is same as that of the perl (with some
differences). This is the closest there is to perl on jvm and that makes this language worth
a better look (IMO). The language does offer higher order programming primitives like closures
but other stuff like exception handling feels somewhat primitive. The closures are invoked using
a syntax reminiscent of Objective C (with named parameters), and the Java Objects are treated
the same as closures.
The ScriptServlet developed in the previous entry is used here as the parent class.
Providing the handler
The Java objects are treated as closures as mentioned above. The syntax of accessing an object is
very reminiscent of Objective C.
ie: System.out.println("mystring") is written as [[$System out] println: "mystring"]
(see the ':' after println.)
($httpservlet) = @_;
The current instance of ScriptServlet is available as an argument in the local stack for the main closure. The 'get' and 'post'
symbols are also set to the '$do_get' closure so that both doGet and doPost gets redirected to $do_get.
An example js script that can get executed:
$date = [new java.util.Date];
The complete sleep-webapp can be downloaded here. Extract the contents to a directory called 'rhino'
inside samples in your installation (samples/java/webapps/rhino). It has to be in that directory to make use
of the common.xml during ant build.
Update the js.jar if required.
Your extracted directory will look like this.
The sleep-webapp.war will be created in the sleep directory when you run ant from inside
the src. This war file can be deployed on the webserver using the wadm.
wadm -u admin -f deploy.tcl
Once the deployment goes through, you will be able to access the js file using the urlhttp://yourserver:port/sleep/hello.sl