Sun logo      Previous      Contents      Next     

Sun Java™ System Application Server Platform Edition 8 Administration Guide

Chapter 6
The Naming and Directory Service

This 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 JNDI

JNDI 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 be java: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.

Table 6-1  JNDI Subcontexts for Various Resources

JNDI Subcontext

Resource

External System

java:comp/env/jdbc

JDBC

database

java:comp/env/jms

JMS

messaging system

java:comp/env/mail

JavaMail

email

java:comp/env/eis-specific

connector

EIS (enterprise information system)


Admin Console Tasks for Custom Resources

Creating 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:

  1. In the tree component, expand the JNDI node.
  2. Select the Custom Resource node.
  3. On the Custom Resources page, click New.
  4. On the Create Custom Resource page, specify the resource’s settings:
    1. In the JNDI Name field, type a unique name in the format subcontext/name. The value of the subcontext depends on the specific resource.
    2. In the Resource Type field, type the name of the interface that the Factory Class entry implements.
    3. In the Factory Class field, type the name of the class that provides connections. This class must implement javax.naming.spi.ObjectFactory.
    4. 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.
    5. If the resource requires additional properties, click Add Properties.
  5. Click OK.

Equivalent asadmin command: create-custom-resource

Editing a Custom Resource

  1. In the tree component, expand the JNDI node.
  2. Select the Custom Resources node.
  3. On the Custom Resources page, click the resource you want to edit.
  4. On the Edit Custom Resource page, you can perform these tasks:
    1. In the Resource Type field, type the name of the interface that the Factory Class entry implements.
    2. In the Factory Class field, type the name of the class that provides connections. This class must implement javax.naming.spi.ObjectFactory.
    3. Select or deselect the checkbox to enable or disable the resource.
    4. Add or delete resource properties.
  5. Click Save to apply the edits you have made.

Deleting a Custom Resource

  1. In the tree component, expand the JNDI node.
  2. Expand the Custom Resources node.
  3. On the Custom Resources page, select the checkbox for the resource that you want to delete.
  4. Click Delete.
  5. Restart the domain.

Equivalent asadmin command: delete-custom-resource


Admin Console Tasks for External Resources

Creating 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:

  1. In the tree component, expand the JNDI node.
  2. Select the External Resources node.
  3. On the External Resources page, click New.
  4. On the Create External Resource page, specify the resource’s settings:
    1. In the JNDI Name field, type a unique name in the format subcontext/name. The value of the subcontext depends on the specific resource.
    2. Example: test/myResource.

    3. In the JNDI Lookup field, type the name that the application uses to look up the resource.
    4. Example: cn=myResource.

    5. In the Resource Type field, type the name of the interface that the Factory Class entry implements.
    6. Example: test.myResource

    7. In the Factory Class field, type the name of the class that provides connections.
    8. Example: com.sun.jndi.ldap.LdapCtxFactory

    9. 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.
    10. If the resource requires additional properties, click Add Properties.

      For the addtional properties of an LDAP example, see Table 6-2.

      Table 6-2  Additonal Properties for an LDAP External Resource

      Name

      Value

      PROVIDER-URL

      ldap://ldapserver:389/o=myObjects

      SECURITY_AUTHENTICATION

      simple

      SECURITY_PRINCIPAL

      cn=joeSmith, o=Engineering

      SECURITY_CREDENTIALS

      changeit

  5. Click OK.

Editing an External Resource

  1. In the tree component, expand the JNDI node.
  2. Select the External Resources node.
  3. On the External Resources page, click the resource you want to edit.
  4. On the Edit External Resource page, you can perform these tasks:
    1. In the Resource Type field, type the name of the interface that the Factory Class entry implements.
    2. In the JNDI Lookup field, type the name that the application uses to look up the resource.
    3. In the Factory Class field, type the name of the class that provides connections. This class must implement javax.naming.spi.ObjectFactory.
    4. Select or deselect the checkbox to enable or disable the resource.
    5. Add or delete resource properties.
  5. Click Save to apply the edits you have made.

Deleting an External Resource

  1. In the tree component, expand the JNDI node.
  2. Expand the External Resources node.
  3. On the External Resources page, select the checkbox for the resource that you want to delete.
  4. Click Delete.
  5. Restart the domain.



Previous      Contents      Next     


Copyright 2004 Sun Microsystems, Inc. All rights reserved.