Deploying a Javascript (E4X) Service in Axis2

Archived Content
This article is provided for historical perspective only, and may not reflect current conditions. Please refer to relevant product page for more up-to-date product information and resources.
  • By Oshani .
  • 1 May, 2006

Implementation in a Nut-shell

Are you wondering how all this could happen? Then here's what you may want to know. It's highly recommended that you read Axis2 User's Guide before continuing with this tutorial.

To deploy a Javascript (E4X) [1] service, first you need to have JavaScriptReceiver, JavaScriptEngine classes and js.jar [2] library in your classpath. The JavaScriptReceiver 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 JavaScriptEngine which uses the Mozilla Rhino API to process the javascript. The JavaScriptEngine returns an xml string object to the JavaScriptReceiver and the latter encodes the result and sends the outgoing MessageContext.

Writing & Deploying a Javascript Service

So, now if you are interested in getting in to the action by writing and deploying a Javascript service in Axis2, here's what you have to do:

  1. Write the javascript service- 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.JavaScriptReceiver", 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.JavaScriptReceiver" and " org.sample.javascript.JavaScriptEngine" into an Axis2 archive (aar) file.
  5. Put the aar into your servlet container and test your service with a client.

If you prefer to skip the exercises, and go to the answers directly, a working example is available at [3]. Simply drop the JavaScriptService.aar into your webapps/axis2/WEB-INF/services and run the JavaScriptClient!


Applies To:

Apache Axis2/Java versions before 1.0