Bill Clementson's Blog

Bits and pieces (mostly Lisp-related) that I collect from the ether.

September 2004
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
Aug  Oct

Another CL to Java option - Lisplets

Thursday, September 30, 2004

I posted a quite popular 4-part series on "CL to Java" a few months ago (at least, it was "popular" in terms of relative number of hits on my weblog, not "popular" in the Slashdot sense ;-)) In that series, I discussed different alternatives for using CL together with Java (the previous articles are here: Part1, Part2, Part3, and Part4). One of the more interesting options that I discussed in this series was Rich Hickey's JFLI, a mechanism for embedding a JVM instance in a Lisp process using JNI. Well, Rich has just come out with another alternative for working with both Lisp (either CL or Scheme) and Java: Lisplets - a Lisp-friendly interface to Java servlets. Lisplets provide a lightweight mechanism for communicating between a Java servlet and Common Lisp or Scheme using s-expressions over sockets. Here is a description from Rich's Sourceforge page:

"Lisplets are Java Servlets that forward their requests, and gather their response headers, using s-expressions over sockets. They enable easy integration of Common Lisp or Scheme into a Java-based web environment.

The library consists of a single Java class which implements HTTPServlet. It packages the request header, parameters, cookies, session, application, and user info into an s-expression and sends it over a TCP socket that can be read from Lisp using read. The Lisp process returns status, headers, session and application state as an s-expression, followed by the document content. This servlet should work with any servlet container, such as Tomcat, Resin, Jetty, JRun and many others.

The advantages for Lisp developers are plentiful. The various servlet container implementations span the full range of cost (including free), embed-ability, scalability, platform support etc. Several provide a full HTTP server implementation and all can integrate with the industry standard web servers. Thus the Lisp developer is spared the re-inventing of an HTTP server, SSL support etc. In addition, these platforms support the sending of only specific requests to the servlet, allowing for static content to be handled directly by the web server, or a mix of Lisp-generated content and JSP content. The servlet API goes beyond HTTP services by providing for session management, authentication, access control, user roles, session and application state, declarative configuration and logging, all of which are reflected in the Lisplet API. In addition to the convenience, this means that Lisp application servers can interoperate with Java Server Pages, Java Servlets and other Java-based web technologies in a single web application."
Rich provides a simple demo that illustrates how to use the code.

In some ways, this approach reminded me of Franz's jLinker (which also uses sockets to communicate between CL and Java programs); however, jLinker provides a more general-purpose mechanism for communicating between any Java program (not just servlets) and any CL program.

Actually, Lisplets is more like a Java web server equivalent of Marc Battyani's mod_lisp. While mod_lisp works with the popular Apache web server by communicating HTTP requests/responses over a socket interface, Lisplets provides the same type of interaction with Java-based web servers. Since mod_lisp is quite a popular option for people who want to use the Apache web server and CL together, Lisplets might also prove to be popular for those people who need/want to work with Java-based web servers.

emacs Copyright © 2005 by Bill Clementson