Last 2 days i was facing a problem with CORBA environment, as the client was providing us incorrect corba names. Running the application and load everything to get a not found error was a big deal for me (lazy i am ).

so i have developed a very small program that checks the corba name in the corba Naming service.

the usage of the program is as the following:

Usage: java -jar corbaPing.jar host port namingService contextPath

Example: java -jar corbaPing.jar 192.168.122 20000 NameService all/product/bundle/manager

if the there is something registered in the provided context path, you will get the IOR for this reference. or you got an error for the problem you face.

you can download the jar from this URL: http://www.nile-sys.com/tools/corba/corbaPing.jar

i wish this small tool could make your life easier.

In this post will explain how to create a CORBA Java server using the Java sdk.

here a pref. description of what needed to be done:

1- create an idl (Interface Description Language) file that will be the contract between the Server and client regarding the object that needed to be referenced from the client and implemented on the server.

2- generate java skeleton from the idl by using idltojava compiler or idlj.

3- create the concrete class that will be instantiated by the server and its objects referenced by the client.

4- instantiate an ORB object to handle all Marshalling and un-Marshalling for the object calls and all IIOP stuff.

5- create naming context object.

6- create naming component for the object that will be exposed by CORBA.

7- bind the object with the name component in the name context.

the following the a sample code for the above steps:

1- create an IDL file: create a file and name it helloWorld.idl and add the following lines into it:

——————————————————-

module helloWorld {
interface Greetings {
string sayHello();
};
};

———————————————————————

in this idl we define one interface called Greetings that interface has one method or operation called sayHello and will return a String.

2- generate server skeleton from the idl by idlj:

in your terminal go to the directory contains the idl file and run the following command

$ idlj  -fserver -oldImplBase helloWorld.idl

the idlj will create the following:

– Greetings interface.

– GreetingsOperations class.

– _GreetingsImplBase class.

3- create a concrete class contains your business:

you need now to create the concrete class which you need its objects to be exposed through CORBA. To do so you need to create GreetingsServer class that extend the _GreetingsImplBase class.

by extending _GreetingsImplBase class you need to implement the sayHello method, here is code sample:

——————————————————————————————–

public class GreetingsServer extends _GreetingsImplBase {

public String sayHello () {

return ” Hello CORBA”;

}

}

———————————————————————————————–

save this class and create a new class the will run as the server for IIOP calls name the new class CorbaServer

————————————————————————————————–

package Corba;

import org.omg.CORBA.ORB;
import org.omg.CORBA.Object;
import org.omg.CORBA.ORBPackage.InvalidName;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextHelper;
import org.omg.CosNaming.NamingContextPackage.AlreadyBound;
import org.omg.CosNaming.NamingContextPackage.CannotProceed;
import org.omg.CosNaming.NamingContextPackage.NotFound;

public class CorbaServer {

/**
* @param args
*/
public static void main(String[] args) {
// 4- create ORB object
ORB orb = ORB.init(args, null);

// create an instance of the GreetingsServer , this instance will be exposed by the ORB

GreetingsServer greetings = new GreetingsServer();
// register the instance to ORB object
orb.connect(greetings);

try {
// create naming context root, the NameService is the root NameService for any ORB
Object initNameService = orb.resolve_initial_references(“NameService”);
// narrowing the naming service object
NamingContext ncRef = NamingContextHelper.narrow(initNameService);
// create a name component for the GreetingsServer object
NameComponent nc = new NameComponent(“Greetings”,””);
// create name component array that will hold the greeting name component

NameComponent[] path = {nc};

// bind the greetings object with name component
ncRef.rebind(path, greetings);
// to keep the application waiting for calls

Thread.currentThread().join();

} catch (InvalidName e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NotFound e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CannotProceed e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) {
// TODO Auto-generated catch block
e.printStackTrace();
}  catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}
————————————————————————————-

now you have the CORBA server we need to run the naming service that will be used by the CORBA server

$ tnameserv

this will start the naming service

at last you can start your CORBA server name and wait for calls from corba clients that used your idl.

references:

http://members.tripod.com/gsraj/corba/chapter/javaidl_1.html — this was very helpful to me.

http://java.sun.com/j2se/1.4.2/docs/guide/corba/index.html