SlideShare une entreprise Scribd logo
1  sur  10
Naming and Directory Services:
Rationale
A fundamental element in every application is the capability
to find and locate components and services.
A client looking for a component/service
usually knows its name, but not its physical location.
The component name correspond to the actual name,
typically much more difficult to remember and manage.
A well-known naming service is provided on Internet by DNS.
For applications, a naming/directory service is the way
to get a reference to a required service
(e.g. a JDBC data source, a JMS connection factory,
an EJB home interface, etc.)
www.apache.org 64.208.42.41DNS
Naming and Directory Services
A naming service is an application that contains
a set of objects, or references to objects,
with corresponding names
(usually easy to remember).
Such correspondances are called bindings.
A directory service allows for the association
of attributes to a binding.
Some popular directory implementations:
• Lightweight Directory Access Protocol (LDAP)
• Network Directory Service (NDS)
• Network Information Servis Plus (NIS+)
•RMI Registry
•CORBA Naming Service (COS
Naming)
•Domain Name Service (DNS)
•File system
Cont…
JNDI Overview
JNDI (Java Naming Directory Interface) provides Java clients
with the capability to access naming and directory services.
JNDI is subdivided in the following packages:
• javax.naming
• javax.naming.directory
• javax.naming.event
• javax.naming.ldap
• javax.naming.spi
JDBC APIs
JDBC Driver
JNDI APIs
SPI
Service Provider Interface
JNDI Configuration
JNDI configuration could be a quite difficult task.
Whenever we use an EJB server,
JNDI is started automatically
at the same time of the server itself.
Such a service is usually already configured
for the specific server.
Also the client applications using JNDI
must be configured, and this task
is up to the programmer/assempler/deployer.
JNDI Environment Properties
A client (object) uses JNDI to locate remote services;
but JNDI might be a remote service as well.
Thus, how to locate a naming service
without using a naming service?
We can do it using environment properties.
Some standard JNDI properties:
java.naming.factory.initial
java.naming.provider.url
Java.naning.security.authentication
etc.
Context and InitialContext
Context (interface) is used to deal with objects
that have been bind to a JNDI name.
javax.naming.Context contains methods to put
objects in the naming service, and to retrieve them.
All the naming services have an access point,
and in JNDI it is named InitialContext.
To obtain an InitialContext, three steps are required:
1. Select the service provider
2. Specify every configuration needed
3. Call the InitialContext constructor,
providing the environment properties.
!!! A unique InitialContext is not thread-safe!
Use of InitialContext
InitialContext must be closed after its usage,
as it happens for any resource, e.g. a JDBC connection.
The best way to do it is to insert the invocation
of the close method inside a finally block.
The method getEnvironment of Context
returns an Hashtable with all the active properties
for the context.
The method lookup(name) returns a reference
to the Object corresponding to name.
This way, also EJB “home factories” are looked up.
Access to the
Environment of an EJB
As an EJB usually must not access files,
how can an EJB access its configuration properties?
A smart way to pass a configuration value to a bean is
through its deployment descriptor, adding an env-entry tag, e.g.
<env-entry>
<description>what a beautiful entry!</description>
<env-entry-name>theNicestGirl</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>”Anne”</env-entry-value>
</env-entry>
An EJB accesses environment properties
using an InitialContext object,
and looking up the desired property by its name.
Jndi (1)

Contenu connexe

Tendances

Tendances (19)

Easy data-with-spring-data-jpa
Easy data-with-spring-data-jpaEasy data-with-spring-data-jpa
Easy data-with-spring-data-jpa
 
Map-Reduce and Apache Hadoop
Map-Reduce and Apache HadoopMap-Reduce and Apache Hadoop
Map-Reduce and Apache Hadoop
 
Spring Data JPA
Spring Data JPASpring Data JPA
Spring Data JPA
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
Doctrine MongoDB Object Document Mapper
Doctrine MongoDB Object Document MapperDoctrine MongoDB Object Document Mapper
Doctrine MongoDB Object Document Mapper
 
Symfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODMSymfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODM
 
JDBC
JDBCJDBC
JDBC
 
Simple Jdbc With Spring 2.5
Simple Jdbc With Spring 2.5Simple Jdbc With Spring 2.5
Simple Jdbc With Spring 2.5
 
LDAP Integration
LDAP IntegrationLDAP Integration
LDAP Integration
 
JDBC Part - 2
JDBC Part - 2JDBC Part - 2
JDBC Part - 2
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!
 
Oracle 10g
Oracle 10gOracle 10g
Oracle 10g
 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2
 
Lecture17
Lecture17Lecture17
Lecture17
 
Spring Data in 10 minutes
Spring Data in 10 minutesSpring Data in 10 minutes
Spring Data in 10 minutes
 
Ldap
LdapLdap
Ldap
 
Ldapsession 1217528612650451-9
Ldapsession 1217528612650451-9Ldapsession 1217528612650451-9
Ldapsession 1217528612650451-9
 
Ldapsession
LdapsessionLdapsession
Ldapsession
 
Wed 1630 greene_robert_color
Wed 1630 greene_robert_colorWed 1630 greene_robert_color
Wed 1630 greene_robert_color
 

En vedette

C%26D Military H %26 W Final Presentation
C%26D Military H %26 W Final PresentationC%26D Military H %26 W Final Presentation
C%26D Military H %26 W Final PresentationSal Salazar
 
Anthony Santa Maria is an Experienced Elementary School Teacher in Cornell
Anthony Santa Maria is an Experienced Elementary School Teacher in CornellAnthony Santa Maria is an Experienced Elementary School Teacher in Cornell
Anthony Santa Maria is an Experienced Elementary School Teacher in Cornellrocco010
 
01. Уводзіны
01. Уводзіны01. Уводзіны
01. УводзіныAnastasiyaF
 
20140327-S602-Mobile
20140327-S602-Mobile20140327-S602-Mobile
20140327-S602-MobileRussell Lewis
 
tareas del mundo real
tareas del mundo realtareas del mundo real
tareas del mundo realVane Muñoz
 
Fanny Lim Bee Teng_Nov 2014
Fanny Lim Bee Teng_Nov 2014Fanny Lim Bee Teng_Nov 2014
Fanny Lim Bee Teng_Nov 2014Fanny Lim
 
ở đâu làm video quảng cáo uy tín
ở đâu làm video quảng cáo uy tínở đâu làm video quảng cáo uy tín
ở đâu làm video quảng cáo uy tíndudley688
 
Giảm cân nhanh chóng không mang lại kết quả mong muốn
Giảm cân nhanh chóng không mang lại kết quả mong muốnGiảm cân nhanh chóng không mang lại kết quả mong muốn
Giảm cân nhanh chóng không mang lại kết quả mong muốnyasmin367
 
Foods for Optimal Health
Foods  for Optimal HealthFoods  for Optimal Health
Foods for Optimal HealthDeborah Ardolf
 
Administration specialist performance appraisal
Administration specialist performance appraisalAdministration specialist performance appraisal
Administration specialist performance appraisalcodyfred747
 
05. Барацьба з крыжацкай агрэсіяй
05. Барацьба з крыжацкай агрэсіяй05. Барацьба з крыжацкай агрэсіяй
05. Барацьба з крыжацкай агрэсіяйAnastasiyaF
 
21. Гаспадарчыя адносіны ў ХІІІ ст.
21. Гаспадарчыя адносіны ў ХІІІ ст.21. Гаспадарчыя адносіны ў ХІІІ ст.
21. Гаспадарчыя адносіны ў ХІІІ ст.AnastasiyaF
 
Top 8 counter server resume samples
Top 8 counter server resume samplesTop 8 counter server resume samples
Top 8 counter server resume samplesguadiolamed
 
RN_ASA_ Storyboard
RN_ASA_ StoryboardRN_ASA_ Storyboard
RN_ASA_ StoryboardBecky Sheely
 

En vedette (20)

State life
State lifeState life
State life
 
C%26D Military H %26 W Final Presentation
C%26D Military H %26 W Final PresentationC%26D Military H %26 W Final Presentation
C%26D Military H %26 W Final Presentation
 
Anthony Santa Maria is an Experienced Elementary School Teacher in Cornell
Anthony Santa Maria is an Experienced Elementary School Teacher in CornellAnthony Santa Maria is an Experienced Elementary School Teacher in Cornell
Anthony Santa Maria is an Experienced Elementary School Teacher in Cornell
 
Resume_Ambareesh
Resume_AmbareeshResume_Ambareesh
Resume_Ambareesh
 
01. Уводзіны
01. Уводзіны01. Уводзіны
01. Уводзіны
 
20140327-S602-Mobile
20140327-S602-Mobile20140327-S602-Mobile
20140327-S602-Mobile
 
Presentation Butinah I
Presentation Butinah IPresentation Butinah I
Presentation Butinah I
 
tareas del mundo real
tareas del mundo realtareas del mundo real
tareas del mundo real
 
Fanny Lim Bee Teng_Nov 2014
Fanny Lim Bee Teng_Nov 2014Fanny Lim Bee Teng_Nov 2014
Fanny Lim Bee Teng_Nov 2014
 
ở đâu làm video quảng cáo uy tín
ở đâu làm video quảng cáo uy tínở đâu làm video quảng cáo uy tín
ở đâu làm video quảng cáo uy tín
 
Samir-Senior
Samir-SeniorSamir-Senior
Samir-Senior
 
Giảm cân nhanh chóng không mang lại kết quả mong muốn
Giảm cân nhanh chóng không mang lại kết quả mong muốnGiảm cân nhanh chóng không mang lại kết quả mong muốn
Giảm cân nhanh chóng không mang lại kết quả mong muốn
 
Foods for Optimal Health
Foods  for Optimal HealthFoods  for Optimal Health
Foods for Optimal Health
 
Administration specialist performance appraisal
Administration specialist performance appraisalAdministration specialist performance appraisal
Administration specialist performance appraisal
 
05. Барацьба з крыжацкай агрэсіяй
05. Барацьба з крыжацкай агрэсіяй05. Барацьба з крыжацкай агрэсіяй
05. Барацьба з крыжацкай агрэсіяй
 
21. Гаспадарчыя адносіны ў ХІІІ ст.
21. Гаспадарчыя адносіны ў ХІІІ ст.21. Гаспадарчыя адносіны ў ХІІІ ст.
21. Гаспадарчыя адносіны ў ХІІІ ст.
 
Top 8 counter server resume samples
Top 8 counter server resume samplesTop 8 counter server resume samples
Top 8 counter server resume samples
 
RN_ASA_ Storyboard
RN_ASA_ StoryboardRN_ASA_ Storyboard
RN_ASA_ Storyboard
 
Poster images
Poster images Poster images
Poster images
 
Did race change?
Did race change?Did race change?
Did race change?
 

Similaire à Jndi (1)

JNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLJNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLKumar
 
Java Web Programming Using Cloud Platform: Module 3
Java Web Programming Using Cloud Platform: Module 3Java Web Programming Using Cloud Platform: Module 3
Java Web Programming Using Cloud Platform: Module 3IMC Institute
 
Free Hibernate Tutorial | VirtualNuggets
Free Hibernate Tutorial  | VirtualNuggetsFree Hibernate Tutorial  | VirtualNuggets
Free Hibernate Tutorial | VirtualNuggetsVirtual Nuggets
 
Java Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet AdvancedJava Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet AdvancedIMC Institute
 
Session 1 Tp1
Session 1 Tp1Session 1 Tp1
Session 1 Tp1phanleson
 
Final Database Connectivity in JAVA.ppt
Final Database Connectivity in JAVA.pptFinal Database Connectivity in JAVA.ppt
Final Database Connectivity in JAVA.pptTabassumMaktum
 
JDBC java for learning java for learn.ppt
JDBC java for learning java for learn.pptJDBC java for learning java for learn.ppt
JDBC java for learning java for learn.pptkingkolju
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)suraj pandey
 
Collaborative Cuisine's 1 Hour JNDI Cookbook
Collaborative Cuisine's 1 Hour JNDI CookbookCollaborative Cuisine's 1 Hour JNDI Cookbook
Collaborative Cuisine's 1 Hour JNDI CookbookKen Lin
 
SHOW104: Practical Java
SHOW104: Practical JavaSHOW104: Practical Java
SHOW104: Practical JavaMark Myers
 
Hibernate training at HarshithaTechnologySolutions @ Nizampet
Hibernate training at HarshithaTechnologySolutions @ NizampetHibernate training at HarshithaTechnologySolutions @ Nizampet
Hibernate training at HarshithaTechnologySolutions @ NizampetJayarajus
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversKumar
 

Similaire à Jndi (1) (20)

Name services
Name servicesName services
Name services
 
Name Services
Name Services Name Services
Name Services
 
JNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLJNDI, JMS, JPA, XML
JNDI, JMS, JPA, XML
 
Java Web Programming Using Cloud Platform: Module 3
Java Web Programming Using Cloud Platform: Module 3Java Web Programming Using Cloud Platform: Module 3
Java Web Programming Using Cloud Platform: Module 3
 
Free Hibernate Tutorial | VirtualNuggets
Free Hibernate Tutorial  | VirtualNuggetsFree Hibernate Tutorial  | VirtualNuggets
Free Hibernate Tutorial | VirtualNuggets
 
Java Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet AdvancedJava Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet Advanced
 
Session 1 Tp1
Session 1 Tp1Session 1 Tp1
Session 1 Tp1
 
Final Database Connectivity in JAVA.ppt
Final Database Connectivity in JAVA.pptFinal Database Connectivity in JAVA.ppt
Final Database Connectivity in JAVA.ppt
 
JDBC java for learning java for learn.ppt
JDBC java for learning java for learn.pptJDBC java for learning java for learn.ppt
JDBC java for learning java for learn.ppt
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)
 
JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
 
Collaborative Cuisine's 1 Hour JNDI Cookbook
Collaborative Cuisine's 1 Hour JNDI CookbookCollaborative Cuisine's 1 Hour JNDI Cookbook
Collaborative Cuisine's 1 Hour JNDI Cookbook
 
Jdbc
JdbcJdbc
Jdbc
 
Spring jdbc dao
Spring jdbc daoSpring jdbc dao
Spring jdbc dao
 
SHOW104: Practical Java
SHOW104: Practical JavaSHOW104: Practical Java
SHOW104: Practical Java
 
Hibernate training at HarshithaTechnologySolutions @ Nizampet
Hibernate training at HarshithaTechnologySolutions @ NizampetHibernate training at HarshithaTechnologySolutions @ Nizampet
Hibernate training at HarshithaTechnologySolutions @ Nizampet
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC Drivers
 
Jdbc
JdbcJdbc
Jdbc
 
Spring database - part2
Spring database -  part2Spring database -  part2
Spring database - part2
 
Jdbc introduction
Jdbc introductionJdbc introduction
Jdbc introduction
 

Jndi (1)

  • 1. Naming and Directory Services: Rationale A fundamental element in every application is the capability to find and locate components and services. A client looking for a component/service usually knows its name, but not its physical location. The component name correspond to the actual name, typically much more difficult to remember and manage. A well-known naming service is provided on Internet by DNS. For applications, a naming/directory service is the way to get a reference to a required service (e.g. a JDBC data source, a JMS connection factory, an EJB home interface, etc.) www.apache.org 64.208.42.41DNS
  • 2. Naming and Directory Services A naming service is an application that contains a set of objects, or references to objects, with corresponding names (usually easy to remember). Such correspondances are called bindings. A directory service allows for the association of attributes to a binding. Some popular directory implementations: • Lightweight Directory Access Protocol (LDAP) • Network Directory Service (NDS) • Network Information Servis Plus (NIS+)
  • 3. •RMI Registry •CORBA Naming Service (COS Naming) •Domain Name Service (DNS) •File system Cont…
  • 4. JNDI Overview JNDI (Java Naming Directory Interface) provides Java clients with the capability to access naming and directory services. JNDI is subdivided in the following packages: • javax.naming • javax.naming.directory • javax.naming.event • javax.naming.ldap • javax.naming.spi JDBC APIs JDBC Driver JNDI APIs SPI Service Provider Interface
  • 5. JNDI Configuration JNDI configuration could be a quite difficult task. Whenever we use an EJB server, JNDI is started automatically at the same time of the server itself. Such a service is usually already configured for the specific server. Also the client applications using JNDI must be configured, and this task is up to the programmer/assempler/deployer.
  • 6. JNDI Environment Properties A client (object) uses JNDI to locate remote services; but JNDI might be a remote service as well. Thus, how to locate a naming service without using a naming service? We can do it using environment properties. Some standard JNDI properties: java.naming.factory.initial java.naming.provider.url Java.naning.security.authentication etc.
  • 7. Context and InitialContext Context (interface) is used to deal with objects that have been bind to a JNDI name. javax.naming.Context contains methods to put objects in the naming service, and to retrieve them. All the naming services have an access point, and in JNDI it is named InitialContext. To obtain an InitialContext, three steps are required: 1. Select the service provider 2. Specify every configuration needed 3. Call the InitialContext constructor, providing the environment properties. !!! A unique InitialContext is not thread-safe!
  • 8. Use of InitialContext InitialContext must be closed after its usage, as it happens for any resource, e.g. a JDBC connection. The best way to do it is to insert the invocation of the close method inside a finally block. The method getEnvironment of Context returns an Hashtable with all the active properties for the context. The method lookup(name) returns a reference to the Object corresponding to name. This way, also EJB “home factories” are looked up.
  • 9. Access to the Environment of an EJB As an EJB usually must not access files, how can an EJB access its configuration properties? A smart way to pass a configuration value to a bean is through its deployment descriptor, adding an env-entry tag, e.g. <env-entry> <description>what a beautiful entry!</description> <env-entry-name>theNicestGirl</env-entry-name> <env-entry-type>java.lang.String</env-entry-type> <env-entry-value>”Anne”</env-entry-value> </env-entry> An EJB accesses environment properties using an InitialContext object, and looking up the desired property by its name.