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 the class file in a web application from a mobile device. Since the mobile device does not contain cookies, only the log file has

in.ter.nal.ip ser.ver.ip: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 create javascript in my class file and generate a javascript function call for urchinTracker () from inside the class file, I can replace this useless cookieArrayLength = 0; with some useful data, the hedgehog can read from the log file into analytics reports. We looked at Java scripts with Rhino; The Safari bookshelf has:

JavaTM Scripts: Languages, Frames, and Templates

which helped us to demonstrate right away that we can run javascript in class files - this works ready in Java 6.

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

Alternatively, any suggestions for running javascript from java 1.5 will be appreciated.

0
source share
3 answers

[I am posting the answer because I do not have enough points to post a comment on the question itself.]

Are you sure the urchinTracker () function will work outside of your web browser? Running the Rhino JavaScript interpreter (which is not too complicated) will be insufficient if the function depends on various browser objects, such as Document Object Model (DOM) or XmlHttpRequest.

I suggest you at least scan the internals of the urchinTracker () function to make sure that it is.

+1
source

Java Scripting API ( javax.scripting ) was introduced in Java 6, so it will not be available in Java 1.4 or 5. By default, Java SE 6 comes with a stripped-down version of Mozilla Rhino that interfaces via javax.scripting .

However, Mozilla Rhino itself does not require Java 6. On the requirements page:

Recent versions of Rhino have only been tested with JDK 1.4 and higher. Older versions support JDK as early as 1.1.

Therefore, to use Rhino, it seems that Java 1.4 is really enough.

As for resources, the documentation for Rhino has a lot of information. In particular, the Embedding Rhino section can be useful to see how scripts work.

Of course, the absence of the javax.scripting package means that pairing with Rhino itself will require the use of the Rhino API and not the Java 6 scripting API, but I would suggest that the functionality would be pretty similar. The only drawback that I see is that if in the future Java 6 will be supported on the target platform and / or using a different language, it may be necessary to rewrite the use of the Java Scripting API and not directly support Rhino.

+2
source

See Server- side JavaScript for a list of projects running JavaScript on the server side.

For your use, using Rhino seems like the way to go.

0
source

Source: https://habr.com/ru/post/1347309/


All Articles