Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g (10.1.3.5.0)

Part Number E13981-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

Configuring the Initial Context Factory

You use an initial context factory to obtain an initial context–a reference to a JNDI namespace. Using the initial context, you can use the JNDI API to look up an enterprise bean, resource manager connection factory, environment variable, or other JNDI-accessible object.

The type of initial context factory you use depends on the type of client in which you are using it, as Table 19-2 shows.

Table 19-2 Client Initial Context Requirements

Client Type Relationship to Target EJB Initial Context Factory

Any Client

Client and target enterprise bean are collocated

Default (see "Configuring the Default Initial Context Factory")

Any Client

Client and target enterprise bean are deployed in the same application

Default (see "Configuring the Default Initial Context Factory")

Any Client

Target enterprise bean deployed in an application that is designated as the client's parentFoot 1 

Default (see "Configuring the Default Initial Context Factory")

EJB Client

Servlet or JSP Client

Client and target enterprise bean are not collocated, not deployed in the same application, and target EJB application is not client's parentFootref 1.

oracle.j2ee.rmi. RMIInitialContextFactory (see "Configuring an Oracle Initial Context Factory")

Standalone Java Client

Client and target enterprise bean are not collocated, not deployed in the same application, and target EJB application is not client's parentFootref 1.

oracle.j2ee.naming. ApplicationClientInitialContextFactory see "Configuring an Oracle Initial Context Factory")


Footnote 1 See the Oracle Containers for J2EE Developer's Guide for more information on how to set the parent of an application.

Note:

In this release, note the new package names for the RMI and application client initial context factories.

For more information, see the following:

Configuring the Default Initial Context Factory

A client that is collocated with the target bean (see Table 19-2) automatically accesses the JNDI properties for the node. Thus, accessing the enterprise bean is simple: no JNDI properties are required.

Example 19-21 Configuring the Default Initial Context

//Get the Initial Context for the JNDI lookup for a local EJB
InitialContext ic = new InitialContext();
//Retrieve the Home interface using JNDI lookup
Object helloObject = ic.lookup("java:comp/env/ejb/HelloBean");

Configuring an Oracle Initial Context Factory

If your client requires an Oracle initial context factory (see Table 19-2), you must set the following JNDI properties:

For more information about setting JNDI properties, see "Setting JNDI Properties in an Enterprise Bean".

  1. Define the java.naming.factory.initial property with the Oracle initial context factory appropriate for your client (see Table 19-2).

  2. Define the java.naming.provider.url property with the naming provider URL appropriate for your OC4J installation:

  3. Create a HashTable and populate it with the required properties using javax.naming.Context fields as keys and String objects as values, as Example 19-22 shows.

    Example 19-22 Specifying Initial Context Factory Properties

    Hashtable env = new Hashtable(); 
    env.put("java.naming.factory.initial",
            "oracle.j2ee.server.ApplicationClientInitialContextFactory"); 
    env.put("java.naming.provider.url",
            "opmn:ormi://opmnhost:6004:oc4j_inst1/ejbsamples"); 
    
  4. When you instantiate the initial context, pass the HashTable into the initial context constructor, as Example 19-23 shows.

    Example 19-23 Instantiate the Initial Context Looking Up a JNDI-Accessible Resource

    Context ic = new InitialContext (env); 
    
  5. Use the initial context to look up a JNDI-accessible resource:

Configuring the Naming Provider URL for OC4J and Oracle Application Server

In an Oracle Application Server install, OPMN manages one or more OC4J instances. In this case the value for java.naming.provider.url should be of the format:

opmn:ormi://<hostname>:<opmn-request-port>:<oc4j-instance-name>/<application-name>

The fields in this provider URL are defined as follows:

  • <hostname>: The name of the host, on which the Oracle Application Server is running.

  • <opmn-request-port>: In this configuration, you have to use the OPMN request port instead of using the ORMI port. You can find the OPMN request port in the opmn.xml file, as follows:

    <notification-server>
        <port local="6100" remote="6200" request="6003"/>
        ...
    </notification-server>
    

    The default OPMN request port is 6003.

  • <oc4j-instance-name>: In this configuration, you may have more than one OC4J process that OPMN uses for load balancing/failover. You use the name of the instance to which you deployed your application.

    The default instance name is home.

For example, if the host name is dpanda-us, request port is 6003, and instances name is home1, then the provider URL would be:

opmn:ormi://dpanda-us:6003:home1/ejbsamples

For more information, see the following:

Configuring the Naming Provider URL for OC4J Standalone

In a standalone OC4J install, the value for java.naming.provider.url should be of the format:

ormi://<hostname>:<ormi-port>/<application-name>

The fields in this provider URL are defined as follows:

  • <hostname>: The name of the host on which OC4J is running

  • <ormi-port>: The ORMI port as configured in the rmi.xml file, as follows:

    <rmi-server 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/rmi-server-10_0.xsd"
        port="23791"
        schema-major-version="10"
        schema-minor-version="0"
    >
    ...
    </rmi-server>
    

    The default port is 23791.

  • <application-name>: The application name as configured in the server.xml file.

For example, if the host name is dpanda-us, ORMI port is 23793, and the application name is ejb30slsb, then the provider URL would be:

ormi://dpanda-us:23793/ejb30slsb

For more information, see the following: