Java / JNDI
JNDI stands for Java Naming and Directory Interface. JNDI allows distributed applications to look up services in an abstract, resource-independent way.
It is an API that provides naming and directory functionality to applications written using Java. It is independent of any specific directory service implementation so it can be accessed in a common way.
It is used to set up a database connection pool on a Java EE application server. Any application that's deployed on that server can gain access to the connections they need using the JNDI name java:comp/env/FooBarPool without having to know the details about the connection.
- javax.sql.DataSource,
- javax.jms.Connection-Factory,
- javax.jms.QueueConnectionFactory,
- javax.jms.TopicConnectionFactory,
- javax.mail.Session, java.net.URL,
- javax.resource.cci.ConnectionFactory.
The association of a name with an object is called a binding while context is a set of name-to-object bindings. Every context has an associated naming convention. A context provides resource lookup.
Yes.
- Lightweight Directory Access Protocol (LDAP),
- Common Object Request Broker Architecture (CORBA) Common Object Services (COS) name service,
- Java Remote Method Invocation (RMI) Registry,
- Domain Name Service (DNS).
A naming service maintains a set of bindings. Bindings maps names to objects. All objects in a naming system are named in the same way and follow the same naming convention. Clients use the naming service to locate objects by name.
javax.naming package.
Context interface is the core interface for looking up, binding/unbinding, renaming objects and creating and destroying subcontexts.
Lightweight Directory Access Protocol (LDAP) is a protocol for locating organizations, individuals, and other resources such as files and devices in a network, whether on the public Internet or on a corporate intranet.
LDAP is developed by the University of Michigan.
All naming operations are relative to a context. The InitalContext implements the Context interface and provides an entry point for the resolution of names.
JNDI provides an excellent object-oriented abstraction of directory and naming. Developers using JNDI can produce queries that use LDAP or other access protocols to retrieve results.
Yes. JNDI allows for applications to work in conjunction with directory-specific security systems.
lookup() attempts to find the specified object in the given context. It looks for a single, specific object and either finds it in the current JNDI context or it fails.
The JNDI architecture consists of an API and a service provider interface (SPI). Java applications use the JNDI API to access a variety of naming and directory services.
Naming Interface organizes information hierarchically and maps human-friendly names to addresses or objects that are machine-friendly. It allows access to named objects through multiple namespaces.
JNDI includes a directory service interface that provides access to directory objects, which can contain attributes, thereby providing attribute-based searching and schema support.
Service Provider Interface(SPI) supports the protocols provided by third parties.
JNDI provides lookup of resources like a database or a message queue enabling a uniform way to access directory services.
lookup() finds the specified object in the given context or it fails.
search() attempts to return an enumeration of all of the objects matching a given set of search criteria and also it can search across multiple contexts.
lookup find and return single object in one context while search may return multiple objects even from different contexts.
list() attempts to return an enumeration of all of the objects in the current context as NameClassPair.
listBindings() attempts to return an enumeration of all the object bindings in the current context.