Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Chapter 5 Remote Procedure Call From Coulouris, Dollimore, Kindberg and Blair Distributed Systems: Concepts and Design Request-Reply Protocol Client doOperation Server Request message (wait) Reply message getRequest select object execute method sendReply (continuation) 2 Request-Reply Protocol public byte[] doOperation (RemoteRef s, int operationId, byte[] arguments) sends a request message to the remote server and returns the reply. The arguments specify the remote server, the operation to be invoked and the arguments of that operation. public byte[] getRequest (); acquires a client request via the server port. public void sendReply (byte[] reply, InetAddress clientHost, int clientPort); sends the reply message reply to the client at its Internet address and port. 3 Request-Reply Protocol messageType int (0=Request, 1= Reply) requestId int remoteReference RemoteRef operationId int or Operation arguments array of bytes 4 RPC Architecture client process server process Request client stub procedure client program Communication module Reply server stub procedure Communication dispatcher module service procedure 5 JAX-RPC JAX-RPC: Java API for XML-based Remote Procedure Call (RPC). An API for building Web Services and Web Services clients. JAX-RPC is designed to provide a simple way for developers to create Web services server and Web services client. Based on remote procedure calls; so the programming model is familiar to Java developers. 6 Web Service Client and Servers JAX-RPC maps a web service operation to a java method call. service endpoint to a Java Interface. Thus one way to begin implementation of a web service in JAX-RPC is to define a Java interface with a method for each operation of the service along with a class that implements the interface, following the rules of remote invocation etc. 7 JAX-RPC Service Creation A service definition describes the operations that it provides and the data types that they require as argument and provide as return values. This definition can be made available as a document written in WSDL. From a WSDL document, JAX-RPC can generate the Java code required to connect a client to a server leaving one to write only the logic of the client application itself. Since WSDL is language independent the server can be in .net, Jaxrpc or any other compatible platform. Define the service a Java interface. Generate WSDL using the tools provided with JAX-RPC package. Advertise it in a registry for the client to lookup and import it. For publication and lookup any other technology such as J2EE can be used 8 Interface Method Invocation Interface must extend java.rmi. Remote Must declare that it throws java.rmi.RemoteException May declare other service-dependent exceptions such as java.lang.Exception May be derived as extensions from other interfaces. 9 Client and Server Programming Environment JAX-RPC API is distributed over a set of packages: javax.xml.rpc javax.xml.rpc.encoding javax.xml.rpc.handler javax.xml.rpc.handler.soap javax.xml.rpc.holders javax.xml.rpc.server javac.xml.rpc.soap 10 Stubs and Ties Client Side: Stub object has the same methods as the service implementation class. Client application is linked with the stub. When it invokes a method stub delegates the call to the JAX-RPC runtime so that appropriate SOAP message can be sent to the server. On completion the result return back in the reverse path as above. Server side: Message received must be converted into a method call on actual service implementation. This functionality is provided by another piece of glue called tie. Tie extracts method name and parameter from SOAP message. Tie also converts the result of the method call back into a response message to be returned to client JAX-RPC runtime. Developer need not write these classes (tie and stub) since JAX-RPC comes with tools to generate them. 11 JAX-RPC Architecture for Hello Example Hello Client Hello Service Endpoint Impl JAX-WS Stub JAX-WS Ties JAX-WS Runtime (APIs) JAX-WS Runtime (APIs) Transport SOAP/HTTP Transport 14 JAX-RPC Procedures 1. To call a remote procedure, the Client program invokes a method on a stub, a local object that represents the remote service. 2. The stub invokes routines in the JAX-RPC runtime system. 3. The runtime system converts the remote method call into a SOAP message and then transmits the message as an HTTP request. 4. When the server receives the HTTP request, the JAX-RPC runtime system extracts the SOAP message from the request and translates it into a method call. 5. The JAX-RPC runtime system invokes the method on the tie object. 6. The tie object invokes the method on the implementation of the service. 7. The runtime system on the server converts the method's response into a SOAP message and then transmits the message back to the client as an HTTP response. 8. On the client, the JAX-RPC runtime system extracts the SOAP message from the HTTP response and then translates it into a method response for the program. 13 Building and Deploying Service 1. Code the service definition interface, implementation and publisher class. 2. Compile the service definition code of step 1. 3. Package the code in a WAR file. 4. Generate the ties and the WSDL file. 5. Deploy the service. 14 Coding the Interface and Implementation Class The interface extends java.rmi.Remote interface. No constant declarations allowed. Methods must throw java.rmi.RemoteException Method parameters and return types must be supported by JAX-RPC types. 15 Create Endpoint Interface 16 Create Endpoint Implementation 17 Create Endpoint Publisher 18 Compiling and Packaging To compile: ant compile-server To package: ant setup-web-inf ant package Note: These two commands will generate and place the executables in appropriate directories. 19 Generating Ties and WSDL Files and Deploy Service To generate Ties and WSDL: ant process-war Will invoke wsdeploy to generate the tie classes and the WDSL file MyHello.wsdl To deploy the service: ant deploy To verify deployment: http://localhost:8080/hello-jaxrpc/hello To undeploy: ant undeploy 20 Building and Running Client Generate the stubs. Code the client. Compile the client code. Package the client classes into a JAR file. Run the client. 21 Generating Stubs and Coding the Client To generate stubs: ant generate-stubs Before generating stubs, be sure to install the Hello.wsdl file Unpack the WAR file using wsdeploy and location WSDL file in WEB-INF directory or use command: wsimport –keep http://localhost:9999/ws/hello?wsdl Coding the client: is a stand alone program. It calls the service through the generated stub which acts as a proxy for the remote service. 22 Compiling, Packaging and Running Compile the client code: ant compile-client Package the client: ant jar-client Running the client: ant run 23 Iterative Development Test the application. Edit the source files. Execute ant build to create and deploy war files. Execute ant redeploy to undeploy and deploy the service. Execute ant build-static to create jar files with static stubs. Execute ant run to run the client. 24