Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g Release 3 (10.1.3)
B14428-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

Configuring an Environment Reference to a URL Resource Manager Connection Factory

You can access a URL connection by creating a resource manager connection factory reference to it.


Note:

In EJB 3.0, an environment reference to a resource manager connection factory is not needed. You can access a resource manager connection factory directly using annotations and resource injection (see "Looking Up an EJB 3.0 Resource Manager Connection Factory").

For information on looking up a resource manager connection factory, see:

To define a reference to a URL resource manager connection factory:

  1. Create a logical name within the <res-ref-name> element in the EJB deployment descriptor.

    It is a best practice to start the reference name with "url" but it is not required. In the bean code, the lookup of this reference is always prefaced by "java:comp/env" (for example, "java:comp/env/url/myURL")

  2. Map the logical name within the EJB deployment descriptor to the URL within the OC4J-specific deployment descriptor.

  3. Lookup the object reference within the bean with the "java:comp/env/url" preface and the logical name defined in the EJB deployment descriptor.

As shown in Figure 19-4, the URL object was bound to the URL "http://www.myURL.com". The logical name that the bean knows this resource as is "url/testURL". These names are mapped together within the OC4J-specific deployment descriptor. Thus, within the bean's implementation, the bean can retrieve a reference to the URL object by using the "java:comp/env/url/testURL" environment element.

Figure 19-4 URL Resource Manager Mapping

Description of Figure 19-4  follows
Description of "Figure 19-4 URL Resource Manager Mapping"

This environment element is defined with the following information:

Element Description
<res-ref-name> The logical name of the URL object to be used within the originating bean. The name should be prefixed with "url/". In our example, the logical name for our URL is "url/testURL".
<res-type> The Java type of the resource. For the Java URL object, this is java.net.URL.
<res-auth> Define who is responsible for signing on to the database. At this time, the only value supported is "Application". The application provides the authentication information.

Example 19-12 Defining an Environment Element for a URL

The environment element is defined within the EJB deployment descriptor by providing the logical name, "url/testURL", its type of java.net.URL, and the authenticator of "Application".

Description of advanc12.gif follows
Description of the illustration advanc12.gif

The environment element of "url/testURL" is mapped to the URL "http://www.myURL.com" within the OC4J-specific deployment descriptor.

Description of advanc13.gif follows
Description of the illustration advanc13.gif

Once deployed, the bean can retrieve the URL object reference as follows:

InitialContext ic = new InitialContext();
URL url = (URL) ic.lookup("java:comp/env/url/testURL");

//The following uses the URL object
URLConection conn = url.openConnection();