s of version 2.0, JAX-RPC has been renamed JAX-WS
. But the change is not in name alone. JAX-WS offers simplified development, better platform and language independence, and an end to the chaotic array of earlier Java Web services frameworks. This article explores the high-level architecture of JAX-WS, along with its low-level inner workings. It then walks you step by step through creating your first JAX-WS Web service.
The Architecture of JAX-WS 2.0
What is the JAX-WS? Essentially, it consists of the following four things:
- An API for developing Web services using Java and XML
- A standard implementation (SI, as in JAXWS-SI.jar) of the Web services servlet
- Annotations, such as @WebService, that are processed by
apt (annotation processing tool) to generate components for the service and client (A list of all JAX-WS annotations can be found here.)
- A set of tools (primarily
wsimport) for generating the "portable artifacts" (beans, stubs, and XML) for the client code. (
wsimport stands for Web service import, which reads in the descriptors of the published Web service and generates the client artifacts.)
Clearly, JAX-WS is more than just an API for building Web services. Figure 1 shows its high-level architecture.
JAX-WS Under the Hood
How does a JAX-WS application work? The developer need be exposed only to the client and service endpoint. The rest is generated and run automatically (see Figure 2
On the client side, the only Java file the developer supplies is the client class itself. The interface and JavaBeans are generated automatically by
wsimport. On the server side, the only Java file the developer supplies is the service implementation. The JavaBeans are generated by
apt, and the servlet is part of the JAX-WS library.
The generated JavaBeans (also known as a type of portable artifact) are responsible for marshaling/unmarshaling method invocations and responses, as well as service-specific exceptions. Marshaling and unmarshaling are the transformation from XML to Java objects and back using JAXB. Two JavaBeans are generated for each method in the Web service. One bean is for invoking the method and the other for handling the response. An additional JavaBean is generated for each service-specific exception. (JAX-WS 2.0 Beta User's Guide 220.127.116.11 Generate Portable Artifacts)