CS 683 Emerging Technologies Spring Semester, 2003 IDL, RMI, CORBA, WSDL |
||
---|---|---|
© 2003, All Rights Reserved, SDSU & Roger Whitney San Diego State University -- This page last updated 13-Mar-03 |
Some Basic Questions
How do I find a service?
Where is the service?
What does the service do?
How does one interact with the service?
The Broker Pattern
A broker
Dynamics
Registering Server
Client Server Interaction
Variants
Direct Communication Broker System
Callback Broker System
Known Uses
CORBA
IBM's SOM/DSOM
Mircosoft OLE 2.x
RMI
Consequences
Benefits
Location Transparency
Clients (servers) do not care where servers (clients)are located
Changeability and extensibility of components
Changes to server implementations are transparent to clients if they don't change interfaces
Benefits - Continued
Interoperability between different Broker System
Different broker systems may interoperate if they have a common protocol for the exchange of messages
Liabilities
Restricted Efficiency
Lower fault tolerance compared to non-distributed software
Benefits and Liabilities
Testing and Debugging
A client application using tested services is easier to test than creating the software from scratch
Some RMI
A First Program - Hello World
Modified from "Getting Started Using RMI"
The Remote Interface
public interface Hello extends java.rmi.Remote { String sayHello() throws java.rmi.RemoteException; }
The Server Implementation
// Required for Remote Implementation import java.rmi.*; import java.rmi.server.UnicastRemoteObject; // Used in method getUnixHostName import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class HelloServer extends UnicastRemoteObject implements Hello { public HelloServer() throws RemoteException { } // The actual remote sayHello public String sayHello() throws RemoteException { return "Hello World from " + getUnixHostName(); }
// Works only on UNIX machines
protected String getUnixHostName() { try { Process hostName; BufferedReader answer; hostName = Runtime.getRuntime().exec( "hostname" ); answer = new BufferedReader( new InputStreamReader( hostName.getInputStream()) ); hostName.waitFor(); return answer.readLine().trim(); } catch (Exception noName) { return "Nameless"; } }
// Main that registers with Server with Registry
public static void main(String args[]) { // Create and install a security manager System.setSecurityManager(new RMISecurityManager()); try { HelloServer serverObject = new HelloServer (); Naming.rebind("//roswell.sdsu.edu/HelloServer", serverObject ); System.out.println("HelloServer bound in registry"); } catch (Exception error) { System.out.println("HelloServer err: "); error.printStackTrace(); } } }
The Client Code
import java.rmi.*; import java.net.MalformedURLException; public class HelloClient { public static void main(String args[]) { try { Hello remote = (Hello) Naming.lookup( "//roswell.sdsu.edu/HelloServer"); String message = remote.sayHello(); System.out.println( message ); } catch ( Exception error) { error.printStackTrace(); } } }Note the multiple catches are to illustrate which exceptions are thrown
Running The Example
Server Side
Step 1 . Compile the source code
Step 3 . Insure that the RMI Registry is running
For the default port number
Client Side
The client can be run on the same machine or a different machine than the server
Step 1 . Compile the source code
Proxies
How do HelloClient and HelloSever communicate?
Client talks to a Stub that relays the request to the server over a network
Server responds via a skeleton that relays the response to the Client
Some Corba
A Simple CORBA Example using OrbixWeb
Step 1 Create an interface for the server using the CORBA interface definition language (IDL)
Place the following code in the file Hello.idl
interface Hello { string sayHello(); };
Step 2 Compile the IDL interface
idl Hello.idl
This creates a directory called java_output which contains:
Hello.java | HelloPackage/ | _HelloSkeleton.java |
HelloHelper.java | _HelloImplBase.java | _HelloStub.java |
HelloHolder.java | _HelloOperations.java | _tie_Hello.java |
IDL output Hello
Step 3 Implementing the Server using Inheritance
Classes generated by OrbixWeb IDL compiler Hello public interface Hello extends org.omg.CORBA.Object { public String sayHello() ; public java.lang.Object _deref() ; }
_HelloImplBase import IE.Iona.OrbixWeb._OrbixWeb; public abstract class _HelloImplBase extends _HelloSkeleton implements Hello { public _HelloImplBase() { org.omg.CORBA.ORB.init().connect(this); } public _HelloImplBase(String marker) { _OrbixWeb.ORB(org.omg.CORBA.ORB.init()).connect(this,marker); } public _HelloImplBase(IE.Iona.OrbixWeb.Features.LoaderClass loader) { _OrbixWeb.ORB(org.omg.CORBA.ORB.init()).connect(this,loader); } public _HelloImplBase(String marker, IE.Iona.OrbixWeb.Features.LoaderClass loader) { _OrbixWeb.ORB(org.omg.CORBA.ORB.init()).connect(this,marker,loader); } public java.lang.Object _deref() { return this; } }
Programmer Implemented ClassesHelloImplementation public class HelloImplementation extends _HelloImplBase { public String sayHello() { return "Hello World"; } }HelloServer import IE.Iona.OrbixWeb._CORBA; import IE.Iona.OrbixWeb.CORBA.ORB; public class HelloServer { public static void main (String args[]) { org.omg.CORBA.ORB ord = org.omg.CORBA.ORB.init(); try { Hello server = new HelloImplementation(); _CORBA.Orbix.impl_is_ready( "HelloServer" ); System.out.println("Server going Down"); } catch ( org.omg.CORBA.SystemException corbaError) { System.out.println("Exception " + corbaError); } } }Step 4 Compiling the Server
The classpath must include the following:
Hello.java _HelloSkeleton.java _HelloImplBase.java HelloImplementation.java HelloServer.java
Step 5 Registering and running the Server
Make sure that the OrbixWeb daemon (orbixdj) is running on the server machine
You start the deamon by the command:
orbixdj -textConsole
Now register the server via:
putit HelloServer -java HelloServer
Now run the server via
java HelloServer
Note running the server is not normally required, however, since the server is not in a package it is hard to get the ORB to activate the server. We will address this issue later
Details of the above process will be discussed later
Step 6 Writing the client
HelloClient.java
import IE.Iona.OrbixWeb._CORBA; import org.omg.CORBA.ORB; public class HelloClient { public static void main(String args[]) { ORB.init(); String hostname = "eli.sdsu.edu"; String serverLabel = ":HelloServer"; Hello server = HelloHelper.bind( serverLabel, hostname); System.out.println( server.sayHello() ); } }
Step 7 Compiling and Running the client
Compile the classes:
_HelloStub.java HelloClient.java
Now run the client with the command:
java HelloClient
Output - Client Window [New IIOP Connection (eli.sdsu.edu,IT_daemon, null,null,pid=0) ] [New IIOP Connection (eli.sdsu.edu,HelloServer, null,null,pid=0) ] Hello World
Output - Server Window [ HelloServer: New Connection (eli.sdsu.edu:59201) ] [ HelloServer: End of IIOP connection (eli.sdsu.edu:59201) ]
Output - Daemon Window [ IT_daemon: New Connection (eli.sdsu.edu:59200) ] [ IT_daemon: End of IIOP connection (eli.sdsu.edu:59200) ]
IDL
Interface Definition language
RMI
public interface Hello extends java.rmi.Remote { String sayHello() throws java.rmi.RemoteException; }
CORBA
interface Hello { string sayHello(); };
WSDL
WSDL Elements
Standard WSDL Namespaces
Namespace |
URI |
Definition
|
wsdl |
http://schemas.xmlsoap.org/wsdl/ |
WSDL
framework
|
soap |
http://schemas.xmlsoap.org/wsdl/soap/ |
WSDL
SOAP binding
|
http |
http://schemas.xmlsoap.org/wsdl/http/ |
WSDL
HTTP GET & POST binding
|
mime |
http://schemas.xmlsoap.org/wsdl/mime/ |
WSDL
MIME binding
|
soapenc |
http://schemas.xmlsoap.org/soap/encoding/ |
SOAP
1.1Encoding
|
soapenv |
http://schemas.xmlsoap.org/soap/envelope/ |
SOAP
1.1 Envelope
|
xsi |
http://www.w3.org/2000/10/XMLSchema-instance
|
XSD
Instance namespace
|
xsd |
http://www.w3.org/2000/10/XMLSchema |
Schema
namespace
|
tns |
Varies
|
This
namespace
|
Example
<?xml version="1.0"?> <definitions name="BabelFishService" xmlns:tns="http://www.xmethods.net/sd/BabelFishService.wsdl" targetNamespace="http://www.xmethods.net/sd/BabelFishService.wsdl" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/"> <message name="BabelFishRequest"> <part name="translationmode" type="xsd:string"/> <part name="sourcedata" type="xsd:string"/> </message> <message name="BabelFishResponse"> <part name="return" type="xsd:string"/> </message> <portType name="BabelFishPortType"> <operation name="BabelFish"> <input message="tns:BabelFishRequest" name="BabelFish"/> <output message="tns:BabelFishResponse" name="BabelFishResponse"/> </operation> </portType> <binding name="BabelFishBinding" type="tns:BabelFishPortType"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="BabelFish"> <soap:operation soapAction="urn:xmethodsBabelFish#BabelFish"/> <input> <soap:body use="encoded" namespace="urn:xmethodsBabelFish" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input>
<output> <soap:body use="encoded" namespace="urn:xmethodsBabelFish" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </output> </operation> </binding> <service name="BabelFish"> <documentation> Translates text of up to 5k in length, between a variety of languages. </documentation> <port name="BabelFishPort" binding="tns:BabelFishBinding"> <soap:address location="http://services.xmethods.net:80/perl/soaplite.cgi"/> </port> </service> </definitions>
Copyright ©, All rights reserved.
2003 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.
Previous    visitors since 13-Mar-03    Next