Object URLs
CORBA defines a number of uniform resource locator (URL) formats that can be used to specify the location of a CORBA object. The allowed URL formats are summarized in Table 5.
Table 5 Object URL Formats
Format |
Description |
IOR: |
A stringified IOR. The prefix IOR: is followed by a string of hexadecimal numbers. |
corbaloc:rir: |
Specifies an object reference that is implicitly resolved using resolve_initial_references(). |
corbaloc:iiop: or corbaloc:: |
Specifies the location of a CORBA object in a form that is appropriate for the IIOP protocol. |
corbaname:rir: |
Specifies a name that is resolved relative to the initial naming context. |
corbaname:iiop: or corbaname:: |
Specifies a name that is resolved relative to the given naming context. |
file:// |
Indicates a file that may contain a URL or a stringified IOR of a CORBA object. |
ftp:// |
Indicates a file retrieved using FTP that may contain a URL or a stringified IOR for a CORBA object. |
http:// |
An HTTP URL that can be used to retrieve a URL or a stringified IOR for a CORBA object. |
The first five URL formatsIOR:, corbaloc:rir:, corbaloc:iiop:, corbaname:rir:, and corbaname:iiop:must be supported by a CORBA 3 ORB. However, support for the URL formats file://, ftp://, and http:// is currently optional.
Converting an Object URL to an Object Reference
Any of the previous object URLs can be passed as an argument to the function CORBA::ORB::string_to_object(). You are not restricted to passing the format IOR:..., as was the case with versions of CORBA prior to CORBA 3. The way to convert an object URL to an object reference is:
//C++ // Given: // 'orbV' -- a reference to a CORBA::ORB instance // 'objectURLString' -- an arbitrary object URL string CORBA::Object_var objV; objV = orbV->string_to_object(objectURLString); ... //Java // Given: // 'orb' -- a reference to a org.omg.CORBA.ORB instance // 'objectURLString' -- an arbitrary object URL string org.omg.CORBA.Object obj; obj = orb.string_to_object(objectURLString); ...
The object reference has to be narrowed to the correct type after it is returned by string_to_object().
The ORB may need to carry out a number of steps internally to resolve the object URL passed to string_to_object(). This can include making one or more remote invocations.
URL Escape Mechanism for Strings
An escape mechanism is needed to encode data in a URL. There are two reasons the escape mechanism is needed:
Object URLs frequently need to include binary data. The binary data must be mapped to printable characters before it can be included in a URL.
Certain nonalphanumeric characters can become garbled when transmitted across the Internet.
For these reasons, an escape mechanism is defined by the Internet Engineering Task Force (IETF) RFC 2396 specifically for URLs. The escape mechanism ensures that arbitrary strings and binary data can be sent across the Internet without being corrupted. The URL escape mechanism is defined as follows:
ASCII-encoded alphanumeric characters remain unchanged.
The following printable ASCII characters remain unchanged:
;, /, :, ?, @, &, =, +, $, ,, -, _, ., !, ~, *, ', (, ).
All other characters are escaped. The escaped characters are represented as a % (percent sign) followed by a two-digit hexadecimal number.
corbaloc:rir: Object URL
The corbaloc:rir: URL has the following general form:
corbaloc:rir:[/ObjectId]
The protocol identifier rir stands for resolve initial references. It indicates that URLs of this form are resolved by making an implicit call to the method resolve_initial_references(). The optional part ObjectId is used to select one of the initial reference types, listed in Table 4. For example, ObjectId might be NameService or RootPOA. If ObjectId is omitted, it is assumed to be NameService by default.
Some examples of corbaloc:rir: URLs are given in Table 6.
Table 6 Examples of corbaloc:rir: Object URLs
Object URL |
Description |
corbaloc:rir:/TradingService |
Resolves to an object reference of type CosTrading::Lookup |
corbaloc:rir:/NameService |
Resolves to an object reference of type CosNaming::NamingContext |
corbaloc:rir: |
Resolves to an object reference of type CosNaming::NamingContext |
For example, the following invocation of the string_to_object() method
//C++ // Given orbV initialized to an instance of CORBA::ORB CORBA::Object_var objV = orbV->string_to_object("corbaloc:rir:"); //Java // Given orb initialized to an instance of org.omg.CORBA.ORB org.omg.CORBA.Object obj = orb.string_to_object("corbaloc:rir:");
is equivalent to an invocation of the resolve_initial_references() method:
//C++ // Given orbV initialized to an instance of CORBA::ORB CORBA::Object_var objV = orbV->resolve_initial_references("NameService"); //Java // Given orb initialized to an instance of org.omg.CORBA.ORB org.omg.CORBA.Object obj = orb.resolve_initial_references("NameService");
The corbaloc:rir: URL can be used in any context where a stringified object reference is expected.
corbaloc:iiop: Object URL
The corbaloc:iiop: URL is used to specify the location of a CORBA object in a relatively readable form. It has the following general form:
corbaloc:[iiop]:[version@]host[:port][/URL_escaped_object_key]
The protocol identifier iiop is optional. A blank protocol identifier is taken to be iiop by default. The version refers to the IIOP version supported by the object. Currently, it can be 1.0, 1.1, or 1.2. The default is 1.0. The host and port of the server process can be specified. If port is omitted, it is set to 2089 by default. URL_escaped_object_key is derived from the object_key that is part of an IOR. The octets of the original object_key are converted to characters using the URL escape mechanism described previously.
Some examples of corbaloc:iiop: URLs are shown in Table 7.
Table 7 Examples of corbaloc:iiop: Object URLs
Object URL |
Description |
corbaloc:iiop:1.2@myhost:1234/xyz |
A server that supports IIOP 1.2, located on host myhost and listening on port 1234. The object_key is xyz. |
corbaloc::myhost:1234/xyz |
A server that supports IIOP 1.0, located on host myhost and listening on port 1234. The object_key is xyz. |
corbaloc::myhost/xyz |
A server that supports IIOP 1.0, located on host myhost and listening on port 2089. The object_key is xyz. |
The corbaloc:iiop: URL can be used in place of a stringified IOR in calls to string_to_object(). The URL contains the same sort of location information that is found in an IIOP profile. However, unlike the IOR, the URL cannot encode IOR components, so it is not an exact replacement for the IOR.
Fault-Tolerant corbaloc:iiop: Object URL
It is possible to specify a comma-separated list of addresses in place of a single address in the corbaloc:iiop: URL. For example:
corbaloc::1.2@myhost:1200,:1.2@mybackuphost:1200,iiop:1.2@myotherbackup:1240/xy
Note that the protocol specifier (iiop: or :) is considered to be part of an address. In this case, the ORB has three different servers to choose from, with each of them running on a different host. If the ORB fails to contact the first host, it can try the second or third one.
corbaname:rir: Object URL
The corbaname:rir: URL has the following general form:
corbaname:rir:[/NameService][#URL_escaped_string_name]
This URL is used to specify an object reference by giving a stringified name that is resolved relative to the initial naming context. The protocol identifier rir: indicates that the initial naming context is resolved by invoking resolve_initial_references("NameService"). The ObjectId, specified as /NameService, can be omitted from the URL. The URL_escaped_string_name is a stringified name that has been subjected to the URL escape mechanism.
Some examples of corbaname:rir: URLs are shown in Table 8.
Table 8 Examples of corbaname:rir: Object URLs
Object URL |
Description |
corbaname:rir:/NameService#Foo/Bar |
Resolves the object with the stringified name Foo/Bar relative to the initial naming context. |
corbaname:rir:#Foo/name%20with%20spaces |
Resolves the object with the stringified name Foo/name with spaces relative to the initial naming context. |
corbaname:rir:#Foo%5c%5cwith%20backslash |
Resolves the object with the stringified name Foo\\with backslash relative to the initial naming context. Note that \\ is an escaped backslash that represents a single backslash. |
corbaname:rir: |
Resolves to the initial naming context. |
A sample URL of the form corbaname:rir:#Foo/Bar and the following invocation of the string_to_object() method
//C++ // Given orbV initialized to an instance of CORBA::ORB CORBA::Object_var objV = orbV->string_to_object("corbaname:rir:#Foo/Bar"); //Java // Given orb initialized to an instance of org.omg.CORBA.ORB org.omg.CORBA.Object obj = orb.string_to_object("corbaname:rir:#Foo/Bar");
yields a result similar to the following code fragment:
//C++ // Given orbV initialized to an instance of CORBA::ORB CORBA::Object_var objV = orbV->resolve_initial_references("NameService"); CosNaming::NamingContextExt_var rootCtxV = CosNaming::NamingContextExt::_narrow(objV.in() ); if (CORBA::is_nil(rootCtxV.in()) ) { cerr << "Error: Failed to narrow to type NamingContextExt" << endl; exit(1); } objV = rootCtxV->resolve_str("Foo/Bar"); //Java // Given orb initialized to an instance of org.omg.CORBA.ORB org.omg.CosNaming.NamingContextExt rootCtx = null; org.omg.CORBA.Object obj = orb.resolve_initial_references("NameService"); rootCtx = org.omg.CosNaming.NamingContextExtHelper.narrow(obj); obj = rootCtx.resolve_str("Foo/Bar");
For simplicity, the error handling is not shown in the above example. The object reference obtained needs to be narrowed to the appropriate type before it can be used.
corbaname:iiop: Object URL
The corbaname:iiop: URL has the following general form:
corbaname:[iiop]:[version@]host[:port][/URL_escaped_object_key] [#URL_escaped_string_name]
This URL format is closely related to the corbaloc:iiop: object URL. The address portion of the URL
[iiop]:[version@]host[:port][/URL_escaped_object_key]
is identical to the address used in a corbaloc:iiop: URL. In the context of a corbaname:iiop: URL, the address is taken to specify the location of a CosNaming::NamingContext object. The URL_escaped_string_name is a stringified name that has been subjected to the URL escape mechanism. The stringified name is resolved relative to the specified naming context to yield the object reference to which the URL refers.
Some examples of corbaname:iiop: URLs are shown in Table 9.
Table 9 Examples of corbaname:iiop: Object URLs
Object URL |
Description |
corbaname::1.2@myhost:1234/xyz#Foo/Bar |
An object reference given by the stringified name Foo/Bar, resolved relative to the naming context given by :1.2@myhost:1234/xyz |
corbaname::myhost/xyz#Foo/Bar |
An object reference given by the stringified name Foo/Bar, resolved relative to the naming context given by :myhost/xyz |
Fault-Tolerant corbaname:iiop: Object URL
In a manner similar to the corbaloc:iiop: URL, it is possible to specify a comma-separated list of addresses in place of a single address in the corbaname:iiop: URL. For example:
corbaname::1.2@myhost:1200,:1.2@mybackuphost:1200,iiop:1.2@myotherbackup:1240 /xyzxyzxyz#Foo/Bar
If the ORB fails to contact the first host, it can try the second or third one. This is particularly valuable in the case of the naming service. If clients locate all application services using the naming service, it is potentially a single point of failure. Using multiple addresses in a URL provides a simple way of redirecting clients to a backup naming host.