14
I am starting studies on corporate applications, and according to my teacher I will need this java technology and I would like to know what exactly is the JNDI.If possible wanted an example of its use.
14
I am starting studies on corporate applications, and according to my teacher I will need this java technology and I would like to know what exactly is the JNDI.If possible wanted an example of its use.
13
What is?
JNDI is an API used in applications that access external resources, it allows getting these resources through the name. It specifies the SPI service interface and this mechanism allows the support of various directory services such as ldap, dns, nis, rmi, corba, among others. The application that uses JNDI searches the resources through a method called lookup.This API has a configuration environment, and through it we can pass various information, these must be informed in creating a context, it can be by a file.properties or a Hashtable.
If a Hashtable is used we can insert the following parameters:
Context.INITIAL_CONTEXT_FACTORY Used to inform the class responsible for creating Initialcontext. It usually depends on the application server used in the application; Context.PROVIDER_URL Used to inform the Provider URL. It also depends on the application server used;
If it is a service with authentication, we use the parameters below to inform them to the configuration environment:
Context.SECURITY_PRINCIPAL To inform user; Context.SECURITY_CREDENTIALS To enter the password;
If a properties file is used we should define the names :
java.naming.Factory.initial Used to inform the class responsible for creating Initialcontext. It usually depends on the application server used in the application; java.naming.Provider.url Used to inform the Provider URL; java.naming.security.main To inform user; java.naming.security.credentials To enter the password;
The names placed in the properties file are the same as those represented by the attributes of the context or Initialcontext class. The parameters shown above are the most used, but we have several others that can be found in the documentation of the class javax.naming.Context; It is possible to define a class that creates Initialcontext instead of using a class provided by an application server, for this you should extend the Initialdircontext class and also have an interface that implements the Dircontext interface. The resources are stored in an area that can be called namespace, and in it we can seek such resources for use in our application, through the lookup. There are 3 types of namespace:
java:global It is the portable way of remote search of an EJB using JNDI lookup. It follows the following pattern: java:global[/application name]/module name/Enterprise bean name[/interface name] java:module It’s the EJB’s way of searching within the same module. java:module/Enterprise bean name/[interface name] java:app It is the EJB’s way of searching within the same application. java:app[/module name]/Enterprise bean name[/interface name]
Example use:
For example, if an EJB , mybean, is packaged within a WAR myapp.War, the module name is myapp. The name portable JNDI is java:module/mybean An equivalent JNDI name using java: global namespace is java:global/myapp/mybean. Now it’s time to understand how the lookup works, as we already know it is used to make calls from external resources like Entitymanager, Ejbs, among others.
To access any of the above mentioned namespaces we have to use the lookup and this method can be direct, that is, it can directly access the address of the resource in the global namespace of the application or portatil, that is, a logical address is defined in the application for the resource call, for this you must use the address as follows "java:comp/env/logical name_name."
Now with an understanding about the lookup we will discuss about the difference between using a portable or direct lookup. Direct and Portable Lookup respectively:
Through the images we can get an idea of the problem of using a direct lookup, if there are multiple servers or multiple EJB containers in a corporate environment may be necessary to reset the JNDI names, which can lead to great work at the time of deployment and especially integration of the application developed with systems that are already in operation.
NOTE: I found a very simple and objective explanation. So I made a copy & Past. I removed the content from the site: http://www.pognao.com.br/2012/05/entendo-o-funcionamento-do-metodo.html
Browser other questions tagged java-ee api java
You are not signed in. Login or sign up in order to post.