Advanced Internet Programming - Legacy 31242/32549/ AJPCPEAdvanced Internet Programming INFO: What's New FAQ Software Machines Oracle Assignments MODULES: 00 Admin 01 Intro 02 Architecture 03 Servlets 04 JSP 05 JDBC 06 RMI 06 JNDI 07 EJB 08 XML 08 Web Services 09 Security 10 Transactions 11 Legacy 12 Review 99 Design LINKS: START page Faculty of IT UTS Module: Legacy Lab exercise - Using CORBA Many legacy systems use CORBA as their main distributed systems model of programming. This is because CORBA provides an vendor-independent, language-neutral, platform agnostic and open standard. There even exists bridges between proprietary systems such as Microsoft DCOM and CORBA. CORBA can also be more efficient than the J2EE platform - sometimes due to the legacy code such as C being compiled. In the lab environment, a minimal CORBA ORB is provided - this is the open source ORBit and ORBit2 packages under Redhat Linux. Incidentally, this is also required for the GNOME GUI, which uses CORBA to manage the desktop! Level of Difficulty: 3 (medium, extra exercise is hard) Estimated time: 45 minutes Pre-requisites: Run 'wlenv' to set your environment correctly Ensure . is in your $CLASSPATH CORBA - C example We have provided a sample calculator application, written in C, which provides 2 simple functions - add and sub This can be found here as a zip file or alternatively, on /pub/aip/corba/src.zip. For the intrepid, this comes from the orbit documentation package http://www.gnome.org/projects/ORBit2/orbit-docs.tar.gz CORRECTION: There is a bug in Makefile, remove the reference to -llinc in the LDFLAGS= section You can also download the corrected Makefile here. You can also read the Orbit Documentation for this sample at (http://www.gnome.org/projects/ORBit2/orbit-docs/orbit/x478.html) if you are brave (and understand C). Unzip this into a subdirectory. Let's look at the IDL for this application //
// Calculator interface
//
interface Calculator
{
double add(in double number1, in double number2);
double sub(in double number1, in double number2);
};
Basically, this defines 2 functions called add() and sub(). Both a server (calculator-server.c) and a client (calculator-client.c) are provided. There is a Makefile available, so you can compile this example. make You can test this now by starting up the server in a seperate window and typing ./calculator-server Let's try the client - run this in your original window.. ./calculator-client Simple eh? 1+2 = 3 Look at the calculator.ref file. This is where the IOR of the server client is temporarily stored. In real life, it would be better to have a lookup mechanism for this object reference, and CORBA 2 provides a human readable naming mechanism based on the URI standard for this very purpose. The IOR is a string that looks something like
IOR:010000001300000049444c3a43616c63756c61746f723a312e3000000300000
00054424f5c0000000101020005000000554e495800000000170000006361747368
61726b2e69742e7574732e6564752e61750000280000002f746d702f6f726269742
d6368772f6c696e632d3431302d302d323730323739383736386434340000000000
caaedfba5400000001010200280000002f746d702f6f726269742d6368772f6c696
e632d3431302d302d3237303237393837363864343400000000001c000000000000
00c0fa8c60a80c68a86b70282828282828010000006f9971a101000000480000000
100000002000000050000001c00000000000000c0fa8c60a80c68a86b7028282828
2828010000006f9971a101000000140000000100000001000105000000000901010
000000000
If you want this decoded, copy this into your clipboard and enter it into the following URL: http://www2.parc.com/istl/projects/ILU/parseIOR (note: make sure the whole record is online line and has no spaces in it - this is common when you cut and paste the above IOR. Use your own is best!) Note that if you choose Parse(Brief) it shows the NIL object. This is because by default, ORBit does not use IIOP and uses unix domain sockets instead. Let's correct this. You need to create a file called ~/.orbitrc with the following contents ORBIIOPIPv4=1 Re-run the server, and get the IOR from calculator.ref and try the IOR parser again. You should get a response like
object key is <#00#00#00#00#1C#BCm#FC#A7#D8?#C2#B9#F7#0D#E2#16#FA
$#8E#01#00#00#00R#DE#C4#F0>;
no trustworthy most-specific-type info; unrecognized ORB;
reachable with IIOP 1.2 at host "catshark.it.uts.edu.au",
port 34286
Now we can develop CORBA IIOP clients, such as a Java based one. Java CORBA client We need to generate skeletons for the Java client. Type
idlj calculator.idl
You should get the following files generated CalculatorHelper.java CalculatorOperations.java Calculator.java CalculatorHolder.java _CalculatorStub.java We also need to write the client code itself. Create calculator_client.java
import org.omg.CORBA.*;
import java.io.*;
import java.util.*;
class Calculator_client {
public static void main( String args[] ) {
try{
Properties props = System.getProperties();
System.out.println( "Initializing the orb.");
// now get a new instance of an application ORB
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,props);
// read in the IOR reference file
BufferedReader in = new BufferedReader(
new FileReader("calculator.ref"));
String iorString = in.readLine();
// replace above with the following if you are running JDK 1.4.2
// org.omg.IOP.IORHolder ior_holder = new org.omg.IOP.IORHolder();
// String iorString = ior_holder.readIORFile("calculator.ref");
org.omg.CORBA.Object object = orb.string_to_object( iorString );
Calculator calc = CalculatorHelper.narrow( object );
System.out.println("Now calling add");
double res = calc.add((double)1.0,(double)2.0);
System.out.println("Call to Corba Calculator="+res);
} catch ( org.omg.CORBA.SystemException e ) {
System.err.println( "CORBA System Exception ");
System.err.println( e );
e.printStackTrace();
} catch (Exception e) {
System.err.println("Other java error "+e);
e.printStackTrace();
}
}
}
And compile the lot
javac *.java
(in the supplied Makefile, we have added an extra target called alljava, so you could also type make alljava) If you had errors, correct them, or check that you have '.' in the classpath. Start the calculator-server again, then
java Calculator_client
Hopefully, you should see the correct result come out. Additional exercises If you sufficiently skilled in C, you could add extra functions to this application, such as mult or div. Here is the process to follow: Edit calculator.idl file and add the extra definitions. Clear the old code make distclean Edit the calculator-skelimpl.c - you add your methods at the bottom of this file. Use add or sub as a template. Re-generate the code make all You can then also edit the calculator-client.c file to call these extra methods. Don't forget to make all each time you make changes! Finally, you can follow the above steps and modify/compile/run the Java client. One more exercise is to run the client and server on different machines. Since you will be logging onto different machines with the same userid, you should make sure you run the server and client from the same directory, so as to have the same calculator.ref file present. © 2008 University of Technology, Sydney. All Rights Reserved. Redistribution without permission prohibited.