Using URL for CORBA Applications

CORBA defines two URLs corbaname and corbaioc to provide a human readable/editable way to specify a location where an IOR can be obtained. The following sections describe how to use these two URLS.

1. Using corbaloc

The corbaioc URL is used to specify the location of a CORBA object in a hu^ran-readable for^rat with the minimum amount of information necessary. A corbaioc URL has the following format:

corbcaloc:[iiop]:[Version@]Host[:Port][/ObjectKey]

A brief description of different components is given below:

iiop

(Optional) Specifies that the transport protocol should be IIOP. If not present, the protocol defaults to IIOP. So, corbaloc:iiop: and corbaloc:: are equivalent.

Version

(Optional) Specifies the GIOP version supported by the server. The allowed values are 1.0, 1.1 and 1.2; if not present, it defaults 1.0.

Host

Specifies the server’s hostname or IP address in dotted decimal format.

Port

(Optional) Specifies the IP port to be used to connect to the server. The default is 900.

ObjectKey

(Optional) A name of the CORBA object on the remote server.

Here is a typical example of a corbaloc URL corbaloc:iiop:1.2@172.16.4.248:6789/NameService

This refers to the initial naming context of the name service running on a port 6789 in a machine having IP address 172.16.4.248. The following program gets a reference to the initial context of a remote name service using corbaloc.

import CalculatorApp.*;

import org.omg.CosNaming.*;

import org.omg.CosNaming.NamingContextPackage.*;

import org.omg.CORBA.*;

public class CalculatorClientLoc {

public static void main(String args[]) {

try{

ORB orb = ORB.init(args, null);

org.omg.CORBA.Object objRef =

orb.string_to_object(”corbaloc:iiop:1.2@172.16.4.248:6789/NameService”);

NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

org.omg.CORBA.Object ref = ncRef.resolve_str(”Calculator”);

Calculator calc = CalculatorHelper.narrow(ref);

int x =2, y = 3;

System.out.println(”Sent :” + x + ” and ” + y);

int result = calc.add(x, y);

System.out.println(”Received : ” + result);

} catch (Exception e) {e.printStackTrace();}

}

}

Unlike IOR that contains essentially the complete state of an object reference, the corbaloc URL contains only the object’s address. Hence, object references constructed with a corbaloc URL will not have same state as the remote servant; instead they are initialized in a provisional state. The corbaloc URL can be used as a command line argument. The calculator client can be started using the following command:

java CalculatorClient -ORBInitRef

NameService=corbaloc:iiop:1.2@172.16.4.248:6789/NameService

This tells that the program should contact the name service running on 6789 in a machine having IP address 172.16.4.248.

2. Using corbaname

The corbaname “U”R.L provides a ^mechanis^Q for a client to bootstrap directly. It is typically used to resolve the stringified name from the root naming context.

It is similar to the corbaloc, except that it adds the ability to specify an entry within the Naming Service. A corbaname URL to an object has two parts. The first part obtains a reference to the naming service and the second part refers to object key within that naming service. These two parts are separated by #. Consider the following example:

corbaname:iiop:1.2@172.16.4.248:6789#Calculator

Here 172.16.4.248 is the host and 6789 is the port. The part corbaname:iiop:1.2@172.16.4.248:6789 refers to the root naming context. The part after # refers to the name of the object in question. So, a corbaname URL is used to locate a name service and to resolve a name. The following program resolves the calculator servant using corbaname URL.

import CalculatorApp.*;

import org.omg.CORBA.*;

public class CalculatorClientURL {

public static void main(String args[]) {

try{

ORB orb = ORB.init(args, null);

org.omg.CORBA.Object ref =

orb.string_to_object(“corbaname:iiop:1.2@172.16.4.248:6789#Calculator”);

Calculator calc = CalculatorHelper.narrow(ref);

int x =2, y = 3;

System.out.println(”Sent :” + x + ” and ” + y);

int result = calc.add(x, y);

System.out.println(”Received : ” + result);

} catch (Exception e) {e.printStackTrace();}

}

}

Source: Uttam Kumar Roy (2015), Advanced Java programming, Oxford University Press.

Leave a Reply

Your email address will not be published. Required fields are marked *