Escolar Documentos
Profissional Documentos
Cultura Documentos
Massimiliano de Leoni
JAX-RPC (1)
JAX-RPC stands for Java API for XML-based RPC.
JAX-RPC is a technology for building Web services
and clients that use remote procedure calls (RPC)
and XML.
In JAX-RPC, a remote procedure call is represented
by an XML-based protocol such as SOAP. The SOAP
specification defines the envelope structure,
encoding rules, and conventions for representing
remote procedure calls and responses.
These calls and responses are transmitted as SOAP
messages (XML files) over HTTP.
JAX-RPC (2)
On the server side, the developer specifies
the remote procedures by defining methods in
an interface written in the Java programming
language. The developer also codes one or
more classes that implement those methods.
Client programs are also easy to code. A
client creates a proxy (a local object
representing the service) and then simply
invokes methods on the proxy.
JAX-RPC (3)
Although SOAP messages are complex, the JAX-
RPC API hides this complexity from the application
developer.
With JAX-RPC, the developer does not generate or
parse SOAP messages. It is the JAX-RPC runtime
system that converts the API calls and responses to
and from SOAP messages.
With JAX-RPC, clients and Web services have a big
advantage: the platform independence of the Java
programming language.
JAX-RPC (4)
In addition, JAX-RPC is not restrictive: a JAX-RPC
client can access a Web service that is not running
on the Java platform, and vice versa.
This flexibility is possible because JAX-RPC uses
technologies defined by the World Wide Web
Consortium (W3C): HTTP, SOAP, and the Web
Service Description Language (WSDL). WSDL
specifies an XML format for describing a service as a
set of endpoints operating on messages.
JAX-RPC Web service
The starting point for developing a JAX-RPC Web service is the
service endpoint interface.
A service endpoint interface (SEI) is a Java interface that
declares the methods that a client can invoke on the service.
You use the SEI, the wscompile tool, and two configuration files
to generate the WSDL specification of the Web service and the
stubs that connect a Web service client to the JAX-RPC runtime.
Together, the wscompile tool, the deploytool utility, and the
Application Server provide the Application Server’s
implementation of JAX-RPC.
Steps for creating the Web service
and client:
9 Server
1. Code the SEI and implementation class and interface
configuration file.
2. Compile the SEI and implementation class.
3. Use wscompile to generate the files required to deploy the
service tra cui il WSDL.
4. Use deploytool to package the files into a WAR file.
5. Deploy the WAR file. The tie classes (which are used to
communicate with clients) are generated by the Application
Server during deployment.
9 Client
1. Code the client class
2. Use wscompile to generate and compile the stub files.
3. Compile the client class.
4. Run the client.
Coding the SEI and Implementation
Class
A service endpoint interface must conform to a few
rules:
It extends the java.rmi.Remote interface.
It must not have constant declarations, such as public
final static.
The methods must throw the
java.rmi.RemoteException or one of its
subclasses.
Method parameters and return types must be supported
JAX-RPC types (Tutorial Pages 332-334)
Telefono Example: SEI
The service endpoint interface is named TelefonoIF
It declares a single method named
public String getNumero(String abbonato).
This method returns a string that is the concatenation of the
string Hello with the method parameter.
package Telefono;
import java.rmi.Remote;
import java.rmi.RemoteException;
package Telefono;
import java.rmi.Remote;
import java.rmi.RemoteException;
}
The wscompile tool / 1
The tool wscompile creates the WSDL and mapping
files. The WSDL file describes the Web service and is
used to generate the client stubs in Static Stub Client.
The mapping file contains information that correlates
the mapping between the Java interfaces and the
WSDL definition.
The files created in this example are
MyService.wsdl and mapping.xml
The wscompile tool / 2
wscompile is run with the following arguments: