CORBA - C++ Client (ACE TAO) Java Server (JacORB) A simple example

Step 1
I downloaded the binary relaease of JacOrb
Extracted the zip file to
E:\Program Files\JacORB-2.2.4\
Step 2
Then also downloaded Ant
Also jdk was downloaded and installed
Step 3
Then created the batch file (to set the path)
Set ANT_HOME=E:\Program Files\Java_Ant\apache-ant-1.6.5
Set JAVA_HOME=E:\Program Files\Java\jdk1.5.0_03
Set JACORB_HOME=E:\Program Files\JacORB-2.2.4
Set Path=%ANT_HOME%\bin;%JAVA_HOME%\bin;%JACORB_HOME%\bin;%JACORB_HOME%;
Set CLASSPATH=%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib;%JAVA_HOME%;%JACORB_HOME%\lib;
----now to configure JacORB -
In the command promt
E:\Program Files\Java_Ant\apache-ant-1.6.5>ant jaco
E:\Program Files\Java_Ant\apache-ant-1.6.5>ant idlcmd
okay that’s done
Now write the idl

--- test1.idl------
module Quoter1
{
//a test interface
interface Stock
{
double price(); //to get the quote of the stock
readonly attribute string symbol;
readonly attribute string fullname;
};
//interface to get the stock object
exception InvalidStockSymbol {};
//to get the desired stock object by looking up the symbol name
interface Stock_Factory
{
Stock get_stock(in string stock_symbol)
raises (InvalidStockSymbol);
};
};
----------

You can do the steps in the programming guide
E:\Program Files\JacORB-2.2.4\doc\ProgrammingGuide\ ProgrammingGuide.pdf


Generating the Java server from the idl

1. First to generate the necessary .java files from the idl .
For this first run antconfig.bat (in zip) fie and then from the command promt type
E:\Coding\corba\Javaserver>idl -d ./generated2 test1.idl

This will generate the necessar tao classses

2. Second import all these files o Eclipse
Create an empty java project and use File -> Import o import the file system

3. Now youy can see that based on this idl there are two *POA classes defined
StockPOA and Stock_FactoryPOA

We have to extend from the POA class and then implement the methods which were not
implemented.

A) For this create a class name 'StockImpl' and give the base class as StockPOA.
You have to fill in the inplementation of the methods that eclipse has created
public class StockImpl extends StockPOA

B) Similary create a new class Stock_FactoryImpl with the base class as Stock_FactoryPOA
and fill in the parts

--------------
public class Stock_FactoryImpl extends Stock_FactoryPOA
{
public Stock get_stock(String stock_symbol) throws InvalidStockSymbol {
// TODO Auto-generated method stub
return null;
}
}
-----------
//Check out the StockPOA.java and Stock_FactoryPOA.java file in the source zip for implementaion

Then compile the jave parts and
Run the java server
first run the following batch file to set the path

antconfig.bat
-------------------
Set ANT_HOME=E:\Program Files\Java_Ant\apache-ant-1.6.5Set JAVA_HOME=E:\Program Files\Java\jdk1.5.0_03Set JACORB_HOME=E:\Program Files\JacORB-2.2.4
Set Path=%ANT_HOME%\bin;%JAVA_HOME%\bin;%JACORB_HOME%\bin;%JACORB_HOME%;Set CLASSPATH=%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib;%JAVA_HOME%;%JACORB_HOME%\lib;
------------------------------

E:\Coding\corba\Javaserver\generated\Quoter1\CorbaServer>java Quoter1.Server "E:\Temp\j_testior3.ior"


Creating the C++ client form the idl

First download the TAO_1.4.1.1_2.
Installation is just extracting this to a directory of your choise.

We use the test.idl specified above (obviously)

1.Generate the files needes using TAO idl

You can see the tutorial that comes with TAO for this
E:\Program Files\TAO_1.4.1.1_2\index.html
(\docs\release\TAO\tutorials\Simple\Client\index.html)

A. Set the TAO paths, use the batch files in taoconfig.bat
-----------------------------
taoconfig.bat
set ACE_ROOT="E:\Program Files\TAO_1.4.1.1_2"set TAO_ROOT="E:\Program Files\TAO_1.4.1.1_2"set TAO_IDL="E:\Program Files\TAO_1.4.1.1_2\bin\tao_idl.exe"set Path=%Path%;E:\Program Files\TAO_1.4.1.1_2\bin;E:\Program Files\TAO_1.4.1.1_2\lib;
-------------------------

B. In the command prompt type
%TAO_IDL% test1.idl
voila this will create the necessary files

2. Create a empty console project and fill in
See the source attached

Note - Add the generated test1C.cpp to the project ( generated from test.idl)

------main source----------
CORBA::ORB_var orb = CORBA::ORB_init(argc,argv,"");
printf("Initialised the ORB\n");
//do the work
//get the remote object
CORBA::Object_var factory_object = orb->string_to_object(argv[1]);
printf("Object string_to_object\n");
//now test if this object is actually the type that we need
Quoter1::Stock_Factory_var factory
= Quoter1::Stock_Factory::_narrow(factory_object.in() );
printf("Object Narrow over\n");
printf("Calling Quoter1::Stock get_stock \n");
CORBA::Object_var stockobj = factory->get_stock ("Infy");
printf("got the object. Calling narrow\n");
Quoter1::Stock_var stock = Quoter1::Stock::_narrow(stockobj);
printf("Exit::Stock get_stock \n");
int price =stock->price();
printf("Infy pice =%d\n",price);


//destroy the orb
orb->destroy();
-------------------------------------------------------
3.Run the C++ client
fisrst run the following batch file (taoconfig.bat) to set the path

(we are not using naming service or anything, just IOR)

E:\Coding\corba\client\Release>client.exe file://E:\Temp\j_testior3.ior
4. That’s all folks !!

Also chek out this bug
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4780678

Comments

Ashwin said…
the attachment that you had given are not downloable. can you give me a new urls?
thanks a lot for great tutorial....

Popular posts from this blog

Long running Java process resource consumption monitoring , leak detection and GC tuning

OpenLayers Advanced Clustering and Setting dynamic images for OpenLayer Styles via Ajax

Compiling OpenCV with CUDA (GPU) using CMake (GUI)