JNDI

Note: JNDI API can be used to access the Directory
servers. The directory servers like weblogic,
Web Sphere, oracle application server, jboss, etc..
Provides several facilities. One of the facility provided by these servers is
Directory service.
All
the above servers are developed in java language and supports J2EE technologies
like servlet /JSP,EJB,JMS etc.. These servers are also called as J2EE servers.
Procedure for setting up weblogic server:
1.
Choose windows Start àAll
programs à
BEA Weblogic platformàConfiguration
WizardàClick on next.
àClick on next. --> Click on next.
2.
In this provide the username and
password and click on the next button.
3.
Click on next.
4.
Provide configuration-name(Domain name)
and click on create button.
Note: When the create
button is pressed the directory with the name (domain name) will be created
under the c:\bea\user_projects\domains\directory and several files will be
copied
5.
Click on done.
Procedure to start weblogic server:
1.
Using the cd command move to the
directory created by configuration wizard
2.
run startWeblogic.cmd
Procedure for using weblogic console:
1.
Open the browser
2.
Use the url http://localhost:7001/console
3.
Provide the username and password and
click on sign in button
In order to see the content of
Weblogic directory service:
1.
Choose domainnameàserverà
myserver and right click on myserver to get a popup menu.
2.
Click on view JNDI tree.
A java application using jndi api must get the
reference of InitialContext object to deal with the directory server.
Note : Getting the reference of IC is equivalent to
establishing the connection with JDBC.
In order to get the reference of the IC a set of
properties must be used.
Note: We can get the details of the properties from
the manuals
Jndi.properties
java.naming.security.principal=ramu
java.naming.security.credentials=dayinaboyina
java.naming.provider.url=t3://localhost:7001
java.naming.Factory.initial=weblogic.jndi.WLInitialContextFactory
JAPP.javaimport
javax.naming.*;
import
java.io.*;
import
java.util.*;
class
JApp
{
public static void main(String
ars[]) throws Exception
{
FileInputStream
fis=new FileInputStream("jndi.properties");
Properties
props=new Properties();
props.load(fis);
Context ic=new
InitialContext(props);
System.out.println("..........got
Ic......");
}
}
àWe can use the above code to deal with
directory services of other server like JBOSS, Websphere etc.
è We
can create the subcontexts the
InitialContext object by using the following code.
import javax.naming.*;
import java.io.*;
import java.util.*;
class BatchDemo
{
public static void main(String ars[]) throws
Exception
{
FileInputStream fis=new
FileInputStream("jndi.properties");
Properties props=new Properties();
props.load(fis);
Context ic=new InitialContext(props);
System.out.println("..........got
Ic......");
ic.createSubcontext("mbatch");
ic.createSubcontext("abatch");
ic.createSubcontext("mbatch/malestudent");
ic.createsubContext("mbatch/femalestudent");
}
}
è We
can manage the data by using the
directory servers( store, retrieve, remove, modify) i.e directory is similar to
the database server but directory does not support SQL commands.
è destroySubcontext
method can be used to remove the subcontext.
Ic.destroySubcontext(“abatch”);
Ic.destorySubcontext(“mbatch/malestudent”);
è While
storing an object under a context in a directory server, we must give a name to
the object. Giving the name to the object is called as binding the name to the
object.
è Serializable
java objects can be stored in a directory server.
è By
using the bind method serializable java objects can be stored under a context.
Integer o1=new
Integer(100);
Float o2=new Float(200.22f);
Double o3=new
Double(300.22);
String o4=new String(“Ramu/crl”);
Ic.bind(“none”,o1);
Ic.bind(“ntwo”,o2);
Ic.bind(“nthree”,o3);
Ic.bind(“nfour”,o4);
è To
remove the bound object we can use unbind()
Ic.unbind(“none”);
Ic.unbind(“ntwo”);
è Rebind
method can be used to replace the existing object with a new object
Integer o1=new
Integer(100);
Ic.bind(“xxxx”,o1);
Float o2=new
Float(1000.11f);
Ic.rebind(“xxxx”,o2);
కామెంట్లు లేవు:
కామెంట్ను పోస్ట్ చేయండి