Search code examples
javajavascriptscriptingrhinourchin

scripting in java - javascript from a server-side class file in Java 1.5


I have three types of get requests that are delivered to a class file on web application from a mobile device. Because the mobile device provides no cookies, the log file hit only has

in.ter.nal.ip   ser.ver.i.p:port    2009-06-05  09:14:44    GET /applicationname/mobiledevicexml    reqtype=login&userid=xx###  200 87  -   MercuryMobile/1.0 CFNetwork/342.1 Darwin/9.4.1  cookieArrayLength=0;

If I can instantiate javascript in my class file, and generate a javascript function call to urchinTracker() from inside the class file, I can replace that useless cookieArrayLength=0; with some useful data urchin can read from the log file into analytics reports. We have been looking at scripting in Java with Rhino; Safari Bookshelf has:

Scripting in JavaTM: Languages, Frameworks, and Patterns

which helped us immediately demo that we can run javascript in class files --this works out-of-the-box on Java 6.

Anyone know any resources for scripting with Rhino on Java 1.5 or 1.4?

Alternately, any suggestions for running javascript from java 1.5 would be appreciated.


Solution

  • [I'm posting in an answer, because I don't have enough points to post a comment on the question itself.]

    Are you sure that the urchinTracker() function will operate outside of a web browser? Running the Rhino JavaScript interpreter (which isn't too difficult) won't be enough if the function relies on various browser objects, like the Document Object Model (DOM) or XmlHttpRequest.

    I suggest that you at least scan the internals of the urchinTracker() function to see if this is the case.