AJAX and Mustang

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.

Comments:

Post a Comment:
Comments are closed for this entry.
About

sundararajan

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
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
   
       
Today
Bookmarks
Links

No bookmarks in folder

Blogroll

No bookmarks in folder

News

No bookmarks in folder