Quantum Quantum Enterprise Solutions, Inc. Quantum Quantum JNDI Unleashed Java Conference 2000 March 29, 2000 Peter Fischer Director of Technical Services
Mar 27, 2015
QuantumQuantum EnterpriseSolutions, Inc.
QuantumQuantum
JNDI Unleashed
Java Conference 2000
March 29, 2000
Peter Fischer
Director of Technical Services
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
JNDI API
Standard access for Java programs to naming and directory services and features– abstraction over naming and directory services APIs– Provides a key integration point between Java and enterprise naming and directory
service middleware Allows Java applications to access multiple directory services independent of
implementation Using JNDI applications can store and retrieve named Java objects of any type Provides methods for performing standard directory operations
– associating attributes with objects– searching for objects using those attributes as search keys
Consists of two API sets– JNDI API - application access to naming and directory services– JNDI SPI - interface that vendors use to wrap their implementation to conform to JNDI
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
JNDI Architecture
Java Applications
CORBACOS
LDAP RMI NDS WebLogic
JNDI API
JNDI SPI
JNDI Implementation Manager
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
Naming Service
Naming Service– Map names to objects or object references– Maps a logical, “easy-to-read” name to a physical endpoint
Naming ServiceLogical Name Physical Name
CustomerData URL=jdbc:odbc:customerColorPrinter machine:xxx.yyy.zzz.aaa
Database CustomerDatabase;Printer myPrinter;
CustomerDatabase = lookup (“CustomerData”);
myPrinter = lookup (“ColorPrinter”);
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
Directory Service
Directory Service– Extends a naming service by allowing association of attributes with an object– Allows lookup based upon attribute values
Directory ServiceAttr. 1
DirObject
Attr. 2
Attr. 3
Attr. 4
// Search for objects based on attributes
// Modifying attributes on directory
// Store objects in directory
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
Definitions
NameSpace– Set of names that are all unique
Compound Name– Sequence of naming elements that conform to the naming convention of a
namespace
Composite Name– A name that spans multiple namespaces
Service Provider– Provides naming and directory functionality and supports the JNDI SPI
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
Service Providers
Service Provider Description
COS Naming Provides access to CORBA naming service.
File System Provides access to file system in a platform-independent manner. Even allows storage of object references.
LDAP Supports versions 2 and 3.
NIS Provides access to UNIX machines running NIS.
NIS+ Provides better support for security, scalability and dynamic updates.
Novell Provides access to Novell’s 3.x bindery, Novell File System as well as other Novell services.
RMI Registry Provides access to objects stored in the RMI Registry.
SLP Provides a dynamic framework for selection of networks services.
WebLogic JNDI Provides interface for java application server services, including RMI, JDBC, EJB. Includes toolkits for building customized naming an directory providers.
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
Composite Namespace
DNS
LDAP NDS
File System PrinterService
Files Printers
User Objects
InitialContext
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
LDAP
Provides a light-weight version of the X.500 directory service that runs on TCP/IP.
Allows networked users access to information and resources in a simple and clean manner
– Prides simple searching facility that allows you to search and modify entries based upon their position in the hierarchy – context
– Attributes can be associated with entries -
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
JNDI Packages
javax.namingclasses and interfaces for accessing naming services.
javax.naming.directoryclasses that extend javax.naming to provide access to directories
javax.naming.eventClasses and interfaces that support event notification in naming and directory services
javax.naming.ldapClasses and interfaces that support LDAP v3 extensions and controls
javax.naming.spiClasses and interfaces that support the addition of new services providers
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
JNDI Constructs
Context– Specifies naming context operations– Interface that is implemented by InitialContext and InitialDirContext classes
NameClassPair– Contains an object’s name and the name of the object’s class
Binding– Contains the name of the bound object, name of the object’s class, and the object
Reference– Represents an object that is not stored in the directory service
JNDI Environment– Contains the setting for JNDI run-time
Directory Object– Represents the variety of information in a computing environment– Provides operations for creating attributes, adding, removing and modifying
attributes associated with the directory object
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
JNDI Environment Variables
Environment properties can be specified in:– Hashtable that is programmatically setup– Read in from a stored JNDI resource file that stores name/value pairs– Application resource files located in CLASSPATH
Environment is passed into InitialContext and InitialDirContext constructors
Category Description
Standard JNDI Properties Defined by JNDI and are common across all service providers.
Individual service providers map these to an interpretation appropriate for their service. INITIAL_CONTEXT_FACTORY
Service-Specific Common across all service providers that implement a particular service or protocol. DNS_URL, PROVIDER_URL
Feature-Specific Common across all service providers that support a particular feature.
SECURITY_PRINCIPAL, SECURITY_PRINCIPAL
Provider-Specific Apply to a particular service provider.
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
JNDI Object Operations
Operation Description
Lookup Locates an object by name
Store object Object stored in directory service if directory service support object storage and the object is serializable. Uses Context.bind method
Store object reference Object reference stored in directory service. Object stored in external data source.
Add Object Object can be added to namespace.
Rename Object Object can be renamed in namespace.
Move Object Object can be moved around namespace.
Delete Object Object can be deleted from namespace.
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
Working with References
Naming ServiceLogical Name Physical Name
Fred Jones physical address reference… …
Customer customer;
CustomerDatabase = lookup (“CustomerData”);
customer = (Customer)lookup (“Fred Jones”);
Object Repository
locate
Instantiate
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
Naming Package
CompositeName
CompoundName
InitialContext
NameClassPair
Binding
NamingEnumeration
Context
Name
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
Programming Model
Read in Environment– Configuration of the JNDI environment
Everything starts with a Context– Either InitialContext or DirContext
Use Context to add, delete, rename and move entries
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
JNDI Context Operations
// Step 1 - Setup Environment using File System providerHashtable env = new Hashtable();
env.put (Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");env.put (Context.PROVIDER_URL, "file:/company");
// Step 2 - Get InitialContextContext ctx = new InitialContext (env);
// Step 3 – Add an objectFile myFile;
// Create the physical file and add info
Ctx.bind (“marketing/brochure.txt”, myFile);
// Step 4 – Locate an objectFile myFile = (File)ctx.lookup (“marketing/brochure.txt”);
Setup the environment for a specific service provider
Create the initial contextUses the jndi environment
Locating a specific file useslookup method
Adding a file usesbind method
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
JNDI Context Operations
// Step 1 - Setup EnvironmentHashtable env = new Hashtable();
env.put (Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");env.put (Context.PROVIDER_URL, "file:/company");
// Step 2 - Get InitialContextContext ctx = new InitialContext (env);
// Rename an objectctx.rename ("Feb", "Feb2000");
// Create an objectctx.createSubcontext ("Feb2000");
// Delete an objectctx.unbind ("Feb2000");
Setup the environment for a specific service provider
Create the initial context
Renaming a specific file usesbind method
Deleting a file usesunbind method
Creating a file directory usescreateSubcontext method
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
JNDI Context Operations – List Entries
// Step 1 - Setup EnvironmentHashtable env = new Hashtable();
env.put (Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");env.put (Context.PROVIDER_URL, "file:/company");
// Step 2 - Create initial contextContext ctx = InitialContext(env);
// Step 3 - setup list criteriaNamingEnumeration list = ctx.list (“presentations");
// Step 4 - Process Listwhile (list.hasMore()){ NameClassPair entry = (NameClassPair)list.next(); System.out.println(entry);}
Setup the environment for a specific service provider
Create the initial contextUses the jndi environment
Each entry in NamingEnumerationis a NameClassPair
Use the list method to return a NamingEnumeration
for a certain directory
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
JNDI Context Operations – List Bindings
// Step 1 - Setup EnvironmentHashtable env = new Hashtable();
env.put (Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");env.put (Context.PROVIDER_URL, "file:/company");
// Step 2 - Create initial contextContext ctx = InitialContext(env);
// Step 3 - setup list criteriaNamingEnumeration bindings = ctx.listBindings ("presentation");
// Step 4 - Process Listwhile (list.hasMore()){ Binding binding= (Binding)bindings.next(); System.out.println(binding.getName() + ":" + binding.getObject());}
Setup the environment for a specific service provider
Create the initial contextUses the jndi environment
Each entry in NamingEnumerationis a Binding
Use the listBindings method to return a NamingEnumeration
for a certain directory
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
Service Provider Differences
// Step 1 - Setup EnvironmentHashtable env = new Hashtable();
env.put (Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");env.put (Context.PROVIDER_URL, "file:/company");
// Step 2 - Get InitialContextContext ctx = new InitialContext (env);
// Step 3 – Add an objectFile myFile;
// Create the physical file and add info
Ctx.bind (“marketing/brochure.txt”, myFile);
// Step 4 – Locate an objectFile myFile = (File)ctx.lookup (“marketing/brochure.txt”);
// Step 1 - Setup EnvironmentHashtable env = new Hashtable();
env.put (Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");env.put (Context.PROVIDER_URL, “ldap://marketing.qes.com");
// Step 2 - Get InitialContextContext ctx = new InitialContext (env);
// Step 3 – Add an objectFile myFile;
// Create the physical file and add info
Ctx.bind (“cn=marketing/brochure.txt”, myFile);
// Step 4 – Locate an objectFile myFile = (File)ctx.lookup (“cn=marketing/brochure.txt”);
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
JNDI and JDBC - Storing JDBC URLs
// Step 1 - Setup Environment
env.put (Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.T3InitialContextfactory");env.put (Context.PROVIDER_URL, "t3://marketing:7001");env.put (Context.SECURITY_PRINCIPAL user);env.put (Context.SECURITY_CREDENTIALS, password);
// Step 2 - Create initial contextContext ctx = InitialContext(env);
// Step 3 - Store the URL using JNDIString strJDBCUrl = new String;
strJDBCUrl = "jdbc:inetdae:marketing:1433database=marketing";
ctx.bind ("MarketingDB", strJDBCUrl);
Store the URL using MarketingDB
as logical name
Using weblogic jndi provider
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
JNDI and JDBC - Retrieving JDBC URLs
// Step 1 - Setup Environment
env.put (Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.T3InitialContextfactory");env.put (Context.PROVIDER_URL, "t3://marketing:7001");env.put (Context.SECURITY_PRINCIPAL user);env.put (Context.SECURITY_CREDENTIALS, password);
// Step 2 - Create initial contextContext ctx = InitialContext(env);
// Step 3 - Retrieve the URL using JNDIString strJBDCUrl = new String;
strJDBCUrl = (String)ctx.lookup ("MarketingDB");
// Step 4 - Open the databaseConnection con = DriverManager.getConnection (strJDBCUrl,
env.SECURITY_PRINCIPAL env.SECURITY_CREDENTIALS);
Using weblogic jndi provider
Lookup the MarketingDB URL
Pass the URL to JDBCTo create connection
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
Directory Package
BasicAttributes
ModificationItem
BasicAttribute
InitialContext
InitialDirContext
DirContext
Attribute
Attributes
Context
SearchControls
NameClassPair
Binding
SearchResult
java.io.Serializable
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
Read Attributes from a Directory Entry
// Step 1 - Setup Environment
env.put (Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.T3InitialContextfactory");env.put (Context.PROVIDER_URL, "t3://marketing:7001");env.put (Context.SECURITY_PRINCIPAL user);env.put (Context.SECURITY_CREDENTIALS, password);
// Step 2 - Create initial contextContext dirCtx = InitialDirContext(env);
// Step 3 - setup list criteriaAttributes attrList = dirCtx.getAttributes (“cn=name“, “ou=marketing”);
// Step 4 - Process Listwhile (attrList.hasMore()){ Attribute attr = (Attribute )attrList.next(); for (NamingEnumeration ne = attr.getAll() ; ne.hasMore(): System.out.println( “value: “ + ne.next() ) );}
Use getAttributes to get attributes
for an entry
Use next and hasMore to loop through attributes
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
Search Entries by Attributes
// get input from userString strLastName;strLastName = …
// Step 1 – Specify attributes to match// Search by Last NameAttributes matchAttrs = new BasicAttributes (true);matchAttrs.put(new BasicAttribute(“sn”, strLastName) );
// Step 2 – Search for objects within a contextNamingEnumeration results = ctx.search(“ou=Marketing”, matchAttr);
// Step 3 - Process Listwhile (result.hasMore()){ SearchResult result = (SearchResult )result.next(); System.out.println( “name: “ + result.getName()) ); printAttributes (result.getAttributes());}
Use next and hasMore to loop through results
Use search and pass the attribute to search on
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
Working with Events
Uses an event model similar to that of AWT and JavaBeans Can be used for the following
– Notification of namespace changes adding, changing, renaming objects
– Notification of object changes Changing object
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
Event Package
ObjectChangeListener
EventContext
NamingListener
NamespaceChangeListener
Java.util.EventObject
NamingEventjava.io.Serializable
Uses an event model similar to that of AWT and JavaBeans
Can be used for the following– Notification of namespace changes
adding, changing, renaming objects
– Notification of object changes Changing object
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
Working with Events
NamingListeners
NamespaceChangeListener
ObjectChangeListener
Context Object
Register
Register
Event
Event
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
Wrap Up
JNDI is full-featured– We touched the tip of the iceberg
Storage of objects– Can store all types of objects
Location Service for system objects– Store JBDC URLs– EJB
Event support provide event-driven programming and notifications– Create “proactive environments” that respond to events
QuantumQuantum
© Quantum Enterprise Solutions, Inc.2000Peter FischerDirector of Technical Services
Questions
Peter Fischer
Director of Technical Services
115 Route 46
Suite A4
Mountain Lakes, New Jersey 07046
Phone - 973-263-0722
email - [email protected]