Sun Java™ System Application Server Platform Edition 8 Administration Guide |
Chapter 6
The Naming and Directory ServiceThis chapter briefly discusses the naming of resources that applications can locate with calls to the Java Naming and Directory Interface (JNDI) API. This chapter contains these sections:
About JNDIJNDI Names and Resources
JNDI is the acronym for the Java Naming and Directory Interface API. By making calls to this API, applications can locate resources and other program objects. A resource is a program object that provides connections to sytems such as database servers and messaging systems. (A JDBC resource is sometimes referred to as a data source.) Each resource object is identified by a unique, people-friendly name: the JNDI name. A resource object and its JNDI name are bound together by the naming and directory service, which is included with the Application Server. When you create a new resource, a new name-object binding is entered into the JNDI repository.
JNDI Subcontexts
JNDI names are organized hierarchically, much like a file system. In a file system, you can organize your files into subdirectories. In JNDI, resource names are organized into subcontexts. For example, all JDBC resource names must be in
java:comp/env/jdbc
subcontext. The JNDI name for the resource of a payroll database could bejava:comp/env/jdbc/payrolldb
.Table 6-1 lists the subcontexts for the various resources. In the table, the External System column lists the type of system that an application accesses through the connection provided by the resource.
Admin Console Tasks for Custom ResourcesCreating a Custom Resource
The J2EE architecture includes standard resources, such as JDBC, JMS, and JavaMail resources. (For a full list of resources, see Table 6-1.) The flexibility of the architecture also allows developers to create custom resources. Because these resources are non-standard, the application developer must provide the administrator with the names of the JNDI subcontext, resource type, and factory class.
To create a custom resource:
- In the tree component, expand the JNDI node.
- Select the Custom Resource node.
- On the Custom Resources page, click New.
- On the Create Custom Resource page, specify the resource’s settings:
- In the JNDI Name field, type a unique name in the format subcontext/name. The value of the subcontext depends on the specific resource.
- In the Resource Type field, type the name of the interface that the Factory Class entry implements.
- In the Factory Class field, type the name of the class that provides connections. This class must implement
javax.naming.spi.ObjectFactory.
- By default, the resource is available (enabled) as soon as it is created. If you want the resource to be unavailable, deselect the Enabled checkbox.
- If the resource requires additional properties, click Add Properties.
- Click OK.
Equivalent
asadmin
command:create-custom-resource
Editing a Custom Resource
- In the tree component, expand the JNDI node.
- Select the Custom Resources node.
- On the Custom Resources page, click the resource you want to edit.
- On the Edit Custom Resource page, you can perform these tasks:
- In the Resource Type field, type the name of the interface that the Factory Class entry implements.
- In the Factory Class field, type the name of the class that provides connections. This class must implement
javax.naming.spi.ObjectFactory.
- Select or deselect the checkbox to enable or disable the resource.
- Add or delete resource properties.
- Click Save to apply the edits you have made.
Deleting a Custom Resource
Equivalent
asadmin
command:delete-custom-resource
Admin Console Tasks for External ResourcesCreating an External Resource
The Application Server includes a naming and directory service that accesses a local JNDI repository. However, an application might need to locate a resource that is named in an external JNDI repository. For example, an application might need to locate an external resource object in a Lightweight Directory Access Protocol (LDAP) repository. The instructions that follow include example values for LDAP.
To create an external resource:
- In the tree component, expand the JNDI node.
- Select the External Resources node.
- On the External Resources page, click New.
- On the Create External Resource page, specify the resource’s settings:
- In the JNDI Name field, type a unique name in the format subcontext/name. The value of the subcontext depends on the specific resource.
Example:
test/myResource
.- In the JNDI Lookup field, type the name that the application uses to look up the resource.
Example:
cn=myResource
.- In the Resource Type field, type the name of the interface that the Factory Class entry implements.
Example:
test.myResource
- In the Factory Class field, type the name of the class that provides connections.
Example:
com.sun.jndi.ldap.LdapCtxFactory
- By default, the resource is available (enabled) as soon as it is created. If you want the resource to be unavailable, deselect the Enabled checkbox.
- If the resource requires additional properties, click Add Properties.
For the addtional properties of an LDAP example, see Table 6-2.
- Click OK.
Editing an External Resource
- In the tree component, expand the JNDI node.
- Select the External Resources node.
- On the External Resources page, click the resource you want to edit.
- On the Edit External Resource page, you can perform these tasks:
- In the Resource Type field, type the name of the interface that the Factory Class entry implements.
- In the JNDI Lookup field, type the name that the application uses to look up the resource.
- In the Factory Class field, type the name of the class that provides connections. This class must implement
javax.naming.spi.ObjectFactory.
- Select or deselect the checkbox to enable or disable the resource.
- Add or delete resource properties.
- Click Save to apply the edits you have made.
Deleting an External Resource