Dear all,

This is to introduce how you could write a service entirely in _javascript_ and deploy it on Axis2. It's very simple and this is what you have to do:

1. Write the _javascript_ service:
This service should be implemented using E4X [1] , which extends the semantics of familiar _javascript_ operators to manipulate XML data. The input argument to the service function would be an xml and the output from the function should also be an xml.

2. Write the META-INF/services.xml:
This follows the axis2 convention of deploying a service. However the messageReceiver in this case should be "org.sample._javascript_._javascript_Receiver", and the ServiceClass parameter should include the _javascript_ source file instead of the service class.

3. Put js.jar [2] into the "lib" folder.

4. Package the _javascript_ source file, "META-INF", "lib" and the class files "org.sample._javascript_._javascript_Receiver" and " org.sample._javascript_._javascript_Engine" into an axis2 archive (aar) file.

The _javascript_Receiver processes the incoming message and extracts the following from the MessageContext :
---_javascript_ function name ( i.e. the operation the client requests)
---The arguments / payload to be sent to the _javascript_ service
---The _javascript_ source stream
It then calls the _javascript_Engine which uses the Mozilla Rhino API to process the _javascript_. The _javascript_Engine returns an xml string object to the _javascript_Receiver and the latter encodes the result and sends the outgoing MessageContext.

I have included a patch of _javascript_Receiver.java and _javascript_Engine.java at http://issues.apache.org/jira/secure/ManageAttachments.jspa?id=12332773 . A working service archive (_javascript_Service.aar) and a Java client (_javascript_Client.java) to test the service is also available from the same location.
I would very much appreciate it if someone could review it and apply the patch at ../axis2/archive/java/scratch/ .

Any comments and suggestions for improvements are highly appreciated.

Thank you.

Regards,
Oshani Seneviratne.

[1] http://www.ecma-international.org/publications/standards/Ecma-357.htm

[2] "js.jar" is available for download at http://www.mozilla.org/rhino/download.html .

Patch is available at http://issues.apache.org/jira/secure/ManageAttachments.jspa?id=12332773 .

Reply via email to