X

Sundararajan's Weblog

  • Java
    June 27, 2006

AJAX and Mustang

Guest Author

AJAX and Mustang

If you are reading about (and trying!) Mustang (Java SE 6), then you probably know this: Mozilla Rhino based javax.script (JSR-223) script engine is included in Mustang. And you can access Java platform API classes from JavaScript.

You may want to run JavaScript files available "out there" with Mustang's JavaScript engine (i.e., you don't want to modify/debug/test and then, use it). For example, there are many useful AJAX based scripts. The main building block of AJAX is the XMLHttpRequest constructor (and sometimes XMLSerializer
and DOMParser
for handling XML). I've just checked-in ajax.js
to the http://scripting.dev.java.net
project
- this includes pure-JavaScript (well, not so pure - I call Java APIs!) implementation of XMLHttpRequest, partial implementations of XMLSerializer and DOMParser and few browser "emulating" variables (just to "fool" scripts into believing that they are running as part browser -- so that access to "window", "document" etc. work partially atleast).

What is the point?

Few use-cases for this:

  • To unit test AJAX "networking" part by "standalone" command line Java clients (or jrunscript) Because this implementation uses java.net and other Java APIs, it could be debugged by the standard Java debuggers/IDEs. Also, it is possible to instrument ajax.js for additional debugging/tracing.
  • DWR - remote objects can uniformly accessed by browser scripts and as well as rich-clients written in Java/swing. I managed to run a (simple) DWR client using ajax.js (see test.js.)
  • In Probos webcontainer, a server-side JavaScript code can call a web-service using DWR or may even directly use XMLHttpRequest.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.