Why and when to perform this task
To access an enterprise bean, a CORBA C++ client needs to locate the EJB home. The client obtains the root naming context from the naming service and uses it to locate the EJB home. Obtaining the naming context can be done explicitly by the client or implicitly by the Object Request Broker's (ORB's) string_to_object method.Steps for this task
In WebSphere, the JNDI name for a bean is mapped to the home class for that bean. The JNDI name is specified in the ibm-ejb-jar-bnd.xmi file generated for the deployed bean's JAR file. If you run the command WAS_HOME/bin/dumpNameSpace, you can see the mapping of the JNDI name to the corresponding Java class. For an enterprise bean, the JNDI name (top)/ejbhome is mapped to the home class. The enterprise bean is located in (top), which is the WebSphere Application Server equivalent to the server's root.
If the EJB home is located on a known server, such as server1, the three components of (top) are "cell", "server", and "server1". In this case, (top) can be specified as cell/servers/server1.
For example, if the EJB home for the valuetype sample class com.ibm.websphere.vtlib.sample.Person is on server1, the full EJB home JNDI name is cell/servers/server1/com/ibm/websphere/vtlib/sample/Person.
char * home_url = "corbaname::localhost/NameService#cell/servers/server1/com/ibm/websphere/vtlib/sample/Person"; ::CORBA::Object_var homeObj = NULL; homeObj = orb->string_to_object( home_url ); if (CORBA::is_nil(homeObj)) { // handle error }
// Obtain the naming context. (where op is a valid ORB pointer) // CORBA::Object * objPtr = op->resolve_initial_references( "NameService" ); rootNameContext = ::CosNaming::NamingContext::_narrow(objPtr); if (CORBA::is_nil( rootNameContext )) { // handle error } // Create a CosNaming Name for the bean's full path // ::CosNaming::Name *ejbName = new ::CosNaming::Name; ejbName->length( 9 ); (*ejbName)[0].id = ::CORBA::string_dup( "cell" ); (*ejbName)[0].kind = ::CORBA::string_dup( "" ); (*ejbName)[1].id = ::CORBA::string_dup( "servers" ); (*ejbName)[1].kind = ::CORBA::string_dup( "" ); (*ejbName)[2].id = ::CORBA::string_dup( "server1" ); (*ejbName)[2].kind = ::CORBA::string_dup( "" ); (*ejbName)[3].id = ::CORBA::string_dup( "com" ); (*ejbName)[3].kind = ::CORBA::string_dup( "" ); (*ejbName)[4].id = ::CORBA::string_dup( "ibm" ); (*ejbName)[4].kind = ::CORBA::string_dup( "" ); (*ejbName)[5].id = ::CORBA::string_dup( "websphere" ); (*ejbName)[5].kind = ::CORBA::string_dup( "" ); (*ejbName)[6].id = ::CORBA::string_dup( "vtlib" ); (*ejbName)[6].kind = ::CORBA::string_dup( "" ); (*ejbName)[7].id = ::CORBA::string_dup( "sample" ); (*ejbName)[7].kind = ::CORBA::string_dup( "" ); (*ejbName)[8].id = ::CORBA::string_dup( "Person" ); (*ejbName)[8].kind = ::CORBA::string_dup( "" ); // Invoke resolve // ::CORBA::Object_var homeObj = NULL; homeObj = rootNameContext->resolve( ejbName ); if (CORBA::is_nil( homeObj )) { // handle error }
::com::ibm::websphere::vtlib::sample::PersonHome_ptr personHome = NULL; personHome = ::com::ibm::websphere::vtlib::sample::PersonHome::_narrow(homeObj); if (CORBA::is_nil(personHome)) { // handle error }
Example
What to do next
The object pointer to the EJB home can be used to create an enterprise bean object. For example:
ejbPtr = ejbHomePtr->create();
When the EJB object is created successfully, any of its methods can be called. For example:
msg = ejbPtr->message();