Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-1 Advanced Java Programming JNDI v2 Chris Wong

Slides:



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

Communicating in J2EE.
JNDI Java Naming Directory Interface JNDI is an API specified in Java that provides naming and directory functionality to applications written in Java.
Naming Computer Engineering Department Distributed Systems Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2014.
Notes to the presenter. I would like to thank Jim Waldo, Jon Bostrom, and Dennis Govoni. They helped me put this presentation together for the field.
Java Naming and Directory Interface JNDI. v001025JNDI2 Topics Naming and Directory Services JNDI Overview Features and Code Samples JNDI Providers References.
Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.
Name Services Jessie Crane CPSC 550. History ARPAnet – experimental computer network (late 1960s) hosts.txt – a file that contained all the information.
OCT 1 Master of Information System Management Organizational Communications and Distributed Object Technologies Lecture 14: Naming.
Directory & Naming Services CS-328 Dick Steflik. A Directory.
Application Server Lecture Paulo Barroso Kris Carver Todd Kitterman Eric Silva.
1 Build a Web Application on J2EE. 2 J2EE Scenario Client – Web Server – EIS Resources Client – Web Server – EIS Resources Client – Application Server.
Basics of JNDI Alessio Bechini June Naming and Directory Services: Rationale A fundamental element in every application is the capability to find.
70-293: MCSE Guide to Planning a Microsoft Windows Server 2003 Network, Enhanced Chapter 7: Planning a DNS Strategy.
Tomcat Configuration A Very, Very, Very Brief Overview.
LDAP LIGHT WEIGHT DIRECTORY ACCESS PROTOCOL PRESENTATION BY ALAKESH APURVA DHAN AND ASH.
1 CSIT 320. Just as the combination of a database and a database management system collects and organizes information about an institution/company/… as.
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
JNDI Java Naming and Directory Interface See also:
Database System Concepts and Architecture Lecture # 3 22 June 2012 National University of Computer and Emerging Sciences.
Ch-9: NAME SERVICES By Srinivasa R. Gudipati. To be discussed.. Fundamentals of Naming Services Naming Resolution The Domain Name System (DNS) Directory.
Chapter 4: Core Web Technologies
Introduction to distributed systems Dr. S. Indran 23 January 2004.
Corso di Formazione Sodalia “Enterprise Java Beans” JNDI Java Naming and Directory Interface.
Enterprise JavaBeans EJB Container Services. EJB container Enterprise JavaBeans are deployed in an EJB container within the application server EJB container.
Microsoft Active Directory(AD) A presentation by Robert, Jasmine, Val and Scott IMT546 December 11, 2004.
© D. Wong  Indexes  JDBC  JDBC in J2EE (Java 2 Enterprise Edition)
Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development.
Introduction to J2EE Architecture Portions by Kunal Mehta.
EJB Framework.  As we know, EJB is the center of the J2EE architecture that provides a sturdy framework for building enterprise applications. The major.
第十四章 J2EE 入门 Introduction What is J2EE ?
1 LDAP and Java Naming Services Murali. M.Nagendranath.
SUSE Linux Enterprise Desktop Administration Chapter 12 Administer Printing.
Topic : JNDI Kaster Nurmukan. JNDI2(c)CDAC(Formerly NCST) What is JNDI? Naming and Directory Services Naming Concepts Issues JNDI Architecture Programming.
Middleware Technology (J2EE/EJB) RMI-IIOP/JNDI. 2 Distributed Objects EJB components are based on distributed objects. A distributed object can be called.
Advanced Programming Rabie A. Ramadan 7.
Struts J2EE web application framework “ Model 2 ” Model View Controller Controller Servlet Key features XML metadata Struts taglib Simplified form validation.
Java Naming and Directory Interfaces. A naming service is an entity that performs the following tasks:  It associates names with objects. Similar to.
XML Registries Source: Java TM API for XML Registries Specification.
J2EE Overview Web Programming CSCI J2EE multi-tier architecture Servlet: Java class loaded into Web server JSP page: enhanced HTML page that is.
1 Schema Registries Steven Hughes, Lou Reich, Dan Crichton NASA 21 October 2015.
Ch 2 – Application Assembly and Deployment COSC 617 Jeff Schmitt September 14, 2006.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Enterprise Integration Patterns CS3300 Fall 2015.
CORBA Common Object Request Broker Architecture. Basic Architecture A distributed objects architecture. Logically, an object client makes method calls.
Java Naming and Directory Interface Matt. 2 What is JNDI.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Network Servers Chapter 13 Release 16/7/2009. Chapter Objectives Describe Client-server and Peer to Peer network model Explain server Explain Domain.
WEB SERVER SOFTWARE FEATURE SETS
Introduction to Active Directory
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
Java Naming and Directory Interface. Contents Naming and directory services JNDI RMI Conclusion.
JAVA LDAP Dima Ionut Daniel. Contents What is LDAP? LDAP Operations Directory Service JNDI as LDAP API Pooling Spring LDAP UnboundId LDAP SDK JAVA LDAP.
Directory Services CS5493/7493. Directory Services Directory services represent a technological breakthrough by integrating into a single management tool:
EJB. Introduction Enterprise Java Beans is a specification for creating server- side scalable, transactional, multi-user secure enterprise-level applications.
Active Directory Domain Services (AD DS). Identity and Access (IDA) – An IDA infrastructure should: Store information about users, groups, computers and.
Enterprise Java Beans. Contents  Understanding EJBs  Practice Section.
J2EE Lecture 10: EJB 3.0 Overview
Master of Information System Management
Introduction to J2EE Architecture
Knowledge Byte In this section, you will learn about:
Chapter 40 Remote Method Invocation
Bina Ramamurthy Chapter 9
Bina Ramamurthy Chapter 9
Bina Ramamurthy Chapter 9
Chapter 46 Remote Method Invocation
Chapter 46 Remote Method Invocation
COMPONENTS – WHY? Object-oriented source-level re-use of code requires same source code language. Object-oriented source-level re-use may require understanding.
Knowledge Byte In this section, you will learn about:
Presentation transcript:

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-1 Advanced Java Programming JNDI v2 Chris Wong based on notes by Wayne Brookes

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-2 JNDI - Introduction JNDI = Java Naming and Directory Interface JNDI provides a standard way for Java applications to interface with a variety of naming and directory services JNDI is defined independently of any specific naming or directory service implementation –Different naming and directory services providers can be plugged in under a common API

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-3 JNDI & J2EE

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-4 JNDI – Architecture JNDI is a core component of JDK 1.3 and a fundamental part of J2EE –JNDI was a Java extension for previous JDKs

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-5 JNDI – Packages JNDI is partitioned into the following packages: –javax.naming – Core JNDI API classes used by applications accessing naming services –javax.naming.directory – JNDI API classes for accessing directory services –javax.naming.event –JNDI API classes providing event notification services for naming and directory systems –javax.naming.ldap – JNDI API classes supporting advanced features of the LDAP v3 standard when using the LDAP directory SPI –javax.naming.spi – JNDI SPI (Service Provider Interface) classes used by implementors of SPIs to map JNDI API calls to a particular naming or directory service

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-6 Naming vs. Directories JNDI has two similar but not identical concepts: –Naming service look up an object by name only –Directory service look up an object by a set of properties Directory services are a superset of name services They have different uses in J2EE, as we will see

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-7 JNDI – Naming Services A naming service is a mechanism used in distributed and non-distributed applications to refer to objects via a name identifying that object The name used is generally human readable or easily converted into a human readable String The association between a name and an object is known as a name binding A name binding is always relative to a given naming context

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-8 Naming & J2EE J2EE applications need a naming service for finding references to objects –EJBs need to find container-managed data sources for databases they need to use lookup by the data source's JNDI name –EJBs themselves must be located by name, by servlets, by other EJBs, and even by non-web client apps lookup by the EJB's JNDI name

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-9 JNDI – Naming Services (cont) Examples of names and naming services are: –A filename  file in a filesystem –A Domain Name Service (DNS) host name  a machine on the internet –An RMI name  RMI server on a remote machine –A CORBA name  CORBA server on a remote machine –A URL  web page on a web server JNDI provides a naming service that maps Java interfaces to various underlying naming systems

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-10 JNDI – Naming Services JNDI supports naming services through Service Provider Interface (SPI) implementations JNDI supports a number of naming services by default: –RMI –LDAP –CORBA IIOP/COSNaming service –DNS –File system ** NOT IN JAVA SE5/6 ** Vendors of other naming services may create their own SPIs

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-11 JNDI – Naming Services To utilise a particular naming service, an application using JNDI must first obtain an “Initial Context” –The interface for this is called javax.naming.InitialContext The Initial Context is then used to look up objects based on their names When you create an Initial Context you need to specify a number of parameters about the naming service you wish to use, including the SPI implementation for the naming service

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-12 Initial Context Represents “where am I?” –eg: Web Application: Your “subdirectory” –eg: file system: Current current directory c:\workshop\autodeploy You need a provider to determine how to read/find/update your context root context subcontext object context subcontext JNDI provider

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-13 JNDI – setting a context There are 4 main ways to set an Initial Context 1. Create an InitialContext() that references the applications local JNDI environment by creating an InitialContext with no parameters 2. Create system properties by either using the java –D parameter eg: java -Djava.naming.factory.initial= com.sun.jndi.fscontext.RefFSContextFactory -Djava.naming.provider.url= ldap://ldap.uts.edu.au:389 JNDITest

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-14 JNDI – setting a context(2) 3. Create a jndi.properties file in the classpath with the above parameters in it eg 4. Create a Properties object with the above parameters in it (see next slide) and pass this to the InitialContext constructor. jndi.properties java.naming.factory.initial= com.sun.jndi.fscontext.RefFSContextFactory java.naming.provider.url= ldap://ldap.uts.edu.au:389

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-15 Example – File System Initial Context /* example.java */ import javax.naming.*; … // define props needed to create InitialContext for file system naming service Properties props = new Properties(); props.setProperty ("INITIAL_CONTEXT_FACTORY", "com.sun.jndi.fscontext.RefFSContextFactory"); props.setProperty ("PROVIDER_URL", "file:C:\\my_jndi"); // get JNDI initial context InitialContext ctx = new InitialContext(props); …

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-16 JNDI – Naming Services Once an InitialContext is obtained, references to objects that are bound to the naming service can be looked up and then used Object lookup is done using the InitialContext.lookup() method – for example, we could look up our RMI server object if we had obtained a JNDI InitialContext for the RMI naming service by: Thing t = (Thing) ctx.lookup("ThingService"); The contents of a JNDI naming service can also be listed using the InitialContext.list() and InitialContext.listBinding() methods

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-17 JNDI – Directory Services A directory service can be viewed as a sophisticated naming service that provides the capability of searching for objects based on many different attributes rather than simply a name Directory services also allow for the modification of object attributes Directory services typically have a hierarchical structure

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-18 Directory Services & J2EE Two uses in J2EE: –Writing applications which use directory information as part of their business logic e.g. if an organisation runs a directory server storing personnel information, a "staff phone book" application would query the directory server –Using a directory service as a source of security credentials e.g. when a user logs in to a web-based application, look up their username and password in a directory service

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-19 JNDI – Hierarchical Contexts Every entry in a directory belongs to a context –the InitialContext is at the root of a hierarchy Each context contains: –zero or more sub-contexts, and –zero or more directory entries A directory entry corresponds to a collection of attributes in the directory representing the object and perhaps the object itself (in serialised form for example)

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-20 JNDI – Directory Services Directory services are used in many enterprise settings where a set of objects are shared between multiple systems Objects are registered, modified and searched in the directory Examples of widely used directories are: –LDAP servers/Active Directory – usually contained user authentication and authorisation information –Novell Directory Service printing and network services

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-21 JNDI – Directory Services JNDI supports accessing of directory services via the javax.naming.directory package The JNDI directory service also uses Initial Context objects - the javax.naming.directory.InitialDirContext class InitialDirContext extends the basic naming InitialContext class, and implements the extended set of directory operations from the javax.naming.directory.DirContext interface

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-22 JNDI – Directory Services Directory searches are done using the DirContext.search() method –DirContext.search() returns a set of Attribute s. Directory objects can also be obtained directly via a lookup style call if the name of the directory object is known –In this case, the method is DirContext.getAttributes() The directory services API also provides methods to add, modify and delete objects from a directory

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-23 Example – JNDI Directory Search Hashtable ldapEnvironment = new Hashtable(); ldapEnvironment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); ldapEnvironment.put(Context.PROVIDER_URL, "ldap://ldap.uts.edu.au:389"); // create LDAP connection DirContext ldapContext = new InitialDirContext(ldapEnvironment); // Create LDAP query SearchControls searchControl = new SearchControls(); searchControl.setSearchScope(SearchControls.SUBTREE_SCOPE); NamingEnumeration searchResultSet = ldapContext.search("o=UTS", "(sn=brookes)", searchControl); // Loop through results and print while (searchResultSet.hasMore()) { SearchResult searchResult = (SearchResult) searchResultSet.next(); System.out.println(sr); }

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-24 JNDI & WebLogic WebLogic contains its own JNDI implementation –It functions as a naming and directory service –When EJBs are deployed, they register their "JNDI name" with the app server –Data Sources also have a "JNDI name" –Administrators (i.e. YOU!) can view the JNDI tree, showing the contexts and the bindings within a context –Use: java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory java.naming.provider.url=t3:// :7001

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-25 JNDI and Web applications By default, there is a top-level context for Web & EJB applications, called "java:comp/env" Allows web apps (servlets/jsp) to dynamically swap JNDI named resources by changing web.xml parameters  avoids namespace clashes/hardcoding when you run more than one web application with the same JNDI resource names

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-26 Sample web.xml We can map a "virtual" named object to a physical object via web.xml "resource-ref" element (Use realname ) jdbc/aDataSource javax.sql.DataSource Container

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-27 Sample code to access this We can then call this via JNDI context lookups: Or via Dependency Injection (only in managed container ie: JSF or Servlets) Context ctx = (Context) new InitialContext(). // Look up our data source DataSource ds = (DataSource) DataSource ds; // or directly via …

Faculty of Information Technology © Copyright UTS Faculty of Information Technology - JNDIJNDI-28 JNDI - Summary Naming services fulfill a basic need for obtaining object references in a given context based on a known name for the object Directory services are a key element in enterprise environments for storing shared enterprise resource information JNDI is the J2EE API for accessing naming and directory services