Presentation is loading. Please wait.

Presentation is loading. Please wait.

Quantum Quantum Enterprise Solutions, Inc. Quantum JNDI Unleashed Java Conference 2000 March 29, 2000 Peter Fischer Director of Technical Services.

Similar presentations


Presentation on theme: "Quantum Quantum Enterprise Solutions, Inc. Quantum JNDI Unleashed Java Conference 2000 March 29, 2000 Peter Fischer Director of Technical Services."— Presentation transcript:

1 Quantum Quantum Enterprise Solutions, Inc. Quantum JNDI Unleashed Java Conference 2000 March 29, 2000 Peter Fischer Director of Technical Services

2 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services JNDI API n 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 n Allows Java applications to access multiple directory services independent of implementation n Using JNDI applications can store and retrieve named Java objects of any type n Provides methods for performing standard directory operations – associating attributes with objects – searching for objects using those attributes as search keys n 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

3 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services JNDI Architecture Java Applications CORBA COS LDAPRMINDSWebLogic JNDI API JNDI SPI JNDI Implementation Manager

4 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services Naming Service n Naming Service – Map names to objects or object references – Maps a logical, easy-to-read name to a physical endpoint Naming Service Logical Name Physical Name CustomerData URL=jdbc:odbc:customer ColorPrinter machine:xxx.yyy.zzz.aaa Database CustomerDatabase; Printer myPrinter; CustomerDatabase = lookup (CustomerData); myPrinter = lookup (ColorPrinter);

5 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services Directory Service n Directory Service – Extends a naming service by allowing association of attributes with an object – Allows lookup based upon attribute values Directory Service Attr. 1 Dir Object Attr. 2 Attr. 3 Attr. 4 // Search for objects based on attributes // Modifying attributes on directory // Store objects in directory

6 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services Definitions n NameSpace – Set of names that are all unique n Compound Name – Sequence of naming elements that conform to the naming convention of a namespace n Composite Name – A name that spans multiple namespaces n Service Provider – Provides naming and directory functionality and supports the JNDI SPI

7 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services Service Providers Service ProviderDescription COS NamingProvides access to CORBA naming service. File SystemProvides access to file system in a platform-independent manner. Even allows storage of object references. LDAPSupports versions 2 and 3. NISProvides access to UNIX machines running NIS. NIS+Provides better support for security, scalability and dynamic updates. NovellProvides access to Novells 3.x bindery, Novell File System as well as other Novell services. RMI RegistryProvides access to objects stored in the RMI Registry. SLPProvides a dynamic framework for selection of networks services. WebLogic JNDIProvides interface for java application server services, including RMI, JDBC, EJB. Includes toolkits for building customized naming an directory providers.

8 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services Composite Namespace

9 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services LDAP n Provides a light-weight version of the X.500 directory service that runs on TCP/IP. n 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 -

10 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services JNDI Packages javax.naming classes and interfaces for accessing naming services. javax.naming.directory classes that extend javax.naming to provide access to directories javax.naming.event Classes and interfaces that support event notification in naming and directory services javax.naming.ldap Classes and interfaces that support LDAP v3 extensions and controls javax.naming.spi Classes and interfaces that support the addition of new services providers

11 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services JNDI Constructs n Context – Specifies naming context operations – Interface that is implemented by InitialContext and InitialDirContext classes n NameClassPair – Contains an objects name and the name of the objects class n Binding – Contains the name of the bound object, name of the objects class, and the object n Reference – Represents an object that is not stored in the directory service n JNDI Environment – Contains the setting for JNDI run-time n 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

12 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services JNDI Environment Variables n 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 n Environment is passed into InitialContext and InitialDirContext constructors CategoryDescription Standard JNDI PropertiesDefined 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-SpecificCommon across all service providers that implement a particular service or protocol. DNS_URL, PROVIDER_URL Feature-SpecificCommon across all service providers that support a particular feature. SECURITY_PRINCIPAL, SECURITY_PRINCIPAL Provider-SpecificApply to a particular service provider.

13 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services JNDI Object Operations OperationDescription LookupLocates an object by name Store objectObject stored in directory service if directory service support object storage and the object is serializable. Uses Context.bind method Store object referenceObject reference stored in directory service. Object stored in external data source. Add ObjectObject can be added to namespace. Rename ObjectObject can be renamed in namespace. Move ObjectObject can be moved around namespace. Delete ObjectObject can be deleted from namespace.

14 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services Working with References Naming Service Logical Name Physical Name Fred Jones physical address reference … Customer customer; CustomerDatabase = lookup (CustomerData); customer = (Customer)lookup (Fred Jones); Object Repository locate Instantiate

15 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services Naming Package CompositeName CompoundName InitialContext NameClassPair Binding NamingEnumeration Context Name

16 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services Programming Model n Read in Environment – Configuration of the JNDI environment n Everything starts with a Context – Either InitialContext or DirContext n Use Context to add, delete, rename and move entries

17 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services JNDI Context Operations // Step 1 - Setup Environment using File System provider Hashtable env = new Hashtable(); env.put (Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); env.put (Context.PROVIDER_URL, "file:/company"); // Step 2 - Get InitialContext Context ctx = new InitialContext (env); // Step 3 – Add an object File myFile; // Create the physical file and add info Ctx.bind (marketing/brochure.txt, myFile); // Step 4 – Locate an object File myFile = (File)ctx.lookup (marketing/brochure.txt); Setup the environment for a specific service provider Create the initial context Uses the jndi environment Locating a specific file uses lookup method Adding a file uses bind method

18 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services JNDI Context Operations // Step 1 - Setup Environment Hashtable env = new Hashtable(); env.put (Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); env.put (Context.PROVIDER_URL, "file:/company"); // Step 2 - Get InitialContext Context ctx = new InitialContext (env); // Rename an object ctx.rename ("Feb", "Feb2000"); // Create an object ctx.createSubcontext ("Feb2000"); // Delete an object ctx.unbind ("Feb2000"); Setup the environment for a specific service provider Create the initial context Renaming a specific file uses bind method Deleting a file uses unbind method Creating a file directory uses createSubcontext method

19 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services JNDI Context Operations – List Entries // Step 1 - Setup Environment Hashtable 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 context Context ctx = InitialContext(env); // Step 3 - setup list criteria NamingEnumeration list = ctx.list (presentations"); // Step 4 - Process List while (list.hasMore()) { NameClassPair entry = (NameClassPair)list.next(); System.out.println(entry); } Setup the environment for a specific service provider Create the initial context Uses the jndi environment Each entry in NamingEnumeration is a NameClassPair Use the list method to return a NamingEnumeration for a certain directory

20 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services JNDI Context Operations – List Bindings // Step 1 - Setup Environment Hashtable 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 context Context ctx = InitialContext(env); // Step 3 - setup list criteria NamingEnumeration bindings = ctx.listBindings ("presentation"); // Step 4 - Process List while (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 context Uses the jndi environment Each entry in NamingEnumeration is a Binding Use the listBindings method to return a NamingEnumeration for a certain directory

21 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services Service Provider Differences // Step 1 - Setup Environment Hashtable env = new Hashtable(); env.put (Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); env.put (Context.PROVIDER_URL, "file:/company"); // Step 2 - Get InitialContext Context ctx = new InitialContext (env); // Step 3 – Add an object File myFile; // Create the physical file and add info Ctx.bind (marketing/brochure.txt, myFile); // Step 4 – Locate an object File myFile = (File)ctx.lookup (marketing/brochure.txt); // Step 1 - Setup Environment Hashtable 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 InitialContext Context ctx = new InitialContext (env); // Step 3 – Add an object File myFile; // Create the physical file and add info Ctx.bind (cn=marketing/brochure.txt, myFile); // Step 4 – Locate an object File myFile = (File)ctx.lookup (cn=marketing/brochure.txt);

22 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director 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 context Context ctx = InitialContext(env); // Step 3 - Store the URL using JNDI String 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

23 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director 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 context Context ctx = InitialContext(env); // Step 3 - Retrieve the URL using JNDI String strJBDCUrl = new String; strJDBCUrl = (String)ctx.lookup ("MarketingDB"); // Step 4 - Open the database Connection con = DriverManager.getConnection (strJDBCUrl, env.SECURITY_PRINCIPAL env.SECURITY_CREDENTIALS); Using weblogic jndi provider Lookup the MarketingDB URL Pass the URL to JDBC To create connection

24 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services Directory Package BasicAttributes ModificationItem BasicAttribute InitialContext InitialDirContext DirContext Attribute Attributes Context SearchControls NameClassPair Binding SearchResult java.io.Serializable

25 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director 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 context Context dirCtx = InitialDirContext(env); // Step 3 - setup list criteria Attributes attrList = dirCtx.getAttributes (cn=name, ou=marketing); // Step 4 - Process List while (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

26 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services Search Entries by Attributes // get input from user String strLastName; strLastName = … // Step 1 – Specify attributes to match // Search by Last Name Attributes matchAttrs = new BasicAttributes (true); matchAttrs.put(new BasicAttribute(sn, strLastName) ); // Step 2 – Search for objects within a context NamingEnumeration results = ctx.search(ou=Marketing, matchAttr); // Step 3 - Process List while (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

27 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services Working with Events n Uses an event model similar to that of AWT and JavaBeans n Can be used for the following – Notification of namespace changes n adding, changing, renaming objects – Notification of object changes n Changing object

28 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services Event Package ObjectChangeListener EventContext NamingListener NamespaceChangeListener Java.util.EventObject NamingEvent java.io.Serializable n Uses an event model similar to that of AWT and JavaBeans n Can be used for the following – Notification of namespace changes n adding, changing, renaming objects – Notification of object changes n Changing object

29 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services Working with Events NamingListeners NamespaceChangeListenerObjectChangeListener Context Object Register Event

30 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director of Technical Services Wrap Up n JNDI is full-featured – We touched the tip of the iceberg n Storage of objects – Can store all types of objects n Location Service for system objects – Store JBDC URLs – EJB n Event support provide event-driven programming and notifications – Create proactive environments that respond to events

31 Quantum © Quantum Enterprise Solutions, Inc.2000 Peter Fischer Director 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 - pfischer@qtrg.com


Download ppt "Quantum Quantum Enterprise Solutions, Inc. Quantum JNDI Unleashed Java Conference 2000 March 29, 2000 Peter Fischer Director of Technical Services."

Similar presentations


Ads by Google