Unit 2 - Java Naming and Directory Interface

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 19

JBoss AS Administration

Unit 2 – Java Naming and Directory Interface (JNDI)


Java Naming and Directory Interface (JNDI)

At the end of this module you will be able


• Describe naming and directory services
• Describe the high-level architecture of JNDI
• Defines basic terminology
• View the JNDI tree in JBoss AS
Road Map

1. Introduction to JNDI
• What are directory and naming services are
and how do they work
• The high-level architecture of JNDI
• The JNDI tree using the Administration Console
What Is JNDI?

• The Java Naming and Directory Interface is an


API for accessing different naming and
directory services uniformly.
• This is a major step forward because:
– Different services use vastly different
naming schemes
– Java applications will be able to navigate
seamlessly across files, directories, objects
and networks
Why Use JNDI?

• In JBoss Server, JNDI serves as a repository and


look-up service for J2EE objects, including
these:
– EJB home stubs
– JDBC DataSources
– JMS connection factories, queues and topics
– RMI stubs
JNDI Structure
Naming Service

• A naming service provides a method for


mapping identifiers to entities or objects.
• Naming Service terms include:
– Binding
– Namespace
– Compound name
– Composite name
Terminology

Term Definition Example

Binding Association of an atomic Jboss.org is bound


name to 192.168.0.1
and an object
Namespace A set of unique names in a Jboss.org/products
naming system
Compound A sequence of atomic names Jboss.org/products/
index.html
Name composed according to
naming system
Composite A name that spans http://jboss.org/pr
oducts/index.html
Name multiple name spaces
JNDI Tree Structure
Contexts and Subcontexts

• Subcontexts are referenced through dot


delimiters (.)
• Subcontexts must be created before objects
are placed into them
JNDI for Administrators

• An administrator needs to understand JNDI


because it will be their job to:
– Verify objects are bound in the JNDI tree
– Create, modify, and configure contexts of
J2EE objects indirectly using admin console
(Ex.: DataSource, ConnectionFactory, etc.)
– Set security on contexts within the JNDI
tree
Display a JNDI tree
Display a JNDI tree
JBoss JNDI Internal Architecture
Initial Context Config

• java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
• java.naming.provider.url=jnp://localhost:1099
• java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

• // Obtain the application component's ENC Context iniCtx = new


InitialContext(); Context compEnv = (Context)
iniCtx.lookup("java:comp/env");
Global JNDI vs. Java JNDI

• JNDI Structure

• Java SCOPE

• Global SCOPE

• ENC Scope
Example

Example 1. An example ejb-jar.xml env-entry fragment


<!-- ... -->
<session>
<ejb-name>ASessionBean</ejb-name>
<!-- ... --> <env-entry> <description>The maximum number of tax exemptions allowed
</description>
<env-entry-name>maxExemptions</env-entry-name> <env-entry-
type>java.lang.Integer</env-entry-type> <env-entry-value>15</env-entry-value>
</env-entry>
<env-entry> <description>The tax rate </description> <env-entry-name>taxRate</env-
entry-name> <env-entry-type>java.lang.Float</env-entry-type> <env-entry-
value>0.23</env-entry-value> </env-entry>
</session> <!-- ... -->
• Example 2.  ENC env-entry access code fragment
InitialContext iniCtx = new InitialContext();
Context envCtx = (Context) iniCtx.lookup("java:comp/env");
Integer maxExemptions = (Integer) envCtx.lookup("maxExemptions");
Float taxRate = (Float) envCtx.lookup("taxRate");
Section Review

• In this section we discussed:


– What directory and naming services are and
how they work
– The high level architecture of JNDI
– How to view the JNDI tree using the
Administration Console and the command
line
Module Review

• In this module we discussed:


– What naming and directory services are the
high level architecture of JNDI
– Terminology used in naming and directory
services
– How to view the JNDI tree in JBoss Server

You might also like