== Scripting JAX-WS ==

The JAX-WS 2.0 specification—the new version of the Java API for XML-Based RPC (JAX-RPC)—defines standard APIs and approaches for building Java-based Web services. As its name implies, JAX-RPC was concerned mostly with how to implement RPC-oriented Web services in Java. JAX-WS expands and improves on the specification in several ways, including

 * tying together and updating its support for several base Web services specifications, such as SOAP 1.2 
 * providing a coherent design for using Java annotations to specify Web services metadata; 
 * providing support for document-oriented Web services, asynchronous services, and services that use transports other than HTTP; 
 * addressing implementation issues surrounding handlers, which are interceptors that provide hooks into message flows between senders and receivers; and 
 * describing practices for dealing with versioning in Web services. 

Implementing the underpinnings for JavaScript Web service implementations in JAX-WS obviously requires supporting infrastructure for both JAX-WS and JavaScript. In developing a JAX-WS implementation, I chose the Celtix open-source enterprise service bus—in part because, as of this writing, it’s less than a year old, and its design and implementation are both very clean. This helps simplify the job of figuring out how to integrate JavaScript into it. Another reason I chose Celtix is that some of the primary developers sit a couple rows away from me at my office, so answers are readily available if I have any questions about the code.

Given that Celtix is implemented in Java, it’s best to use a Java-based JavaScript engine such as the very popular Mozilla Rhino open-source engine. Nearly a decade old, it supports JavaScript and E4X and is readily embeddable into Java applications. With Rhino, it’s relatively easy to invoke Java methods from JavaScript and vice versa.

Support for JavaScript service implementations in Celtix is relatively straightforward. First, Celtix provides an application class that accepts the names of JavaScript files, E4X files, or the directories containing them. For each JavaScript file (with a .js suffix) or E4X file (with a .jsx suffix) specified on the command line, the application calls Rhino to compile the file; assuming that this succeeds, the application class then creates JAX-WS Provider instances and publishes them as service endpoints.

 See Also::
 * [[http://dsonline.computer.org/portal/site/dsonline/menuitem.9ed3d9924aeb0dcd82ccc6716bbe36ec/index.jsp?&pName=dso_level1&path=dsonline/2006/06&file=w3tow.xml|Steve Vinoski, "Scripting JAX-WS", IEEE Internet Computing, vol. 10, no. 3, 2006, pp. 91-94.]]
