Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 746
  • Last Modified:

jndi basics

hi experts

have this question

In ejbs,  the client program (which is trying to access an ejb) has the jndi lookup which goes like this

InitialContext ic = new InitialContext()
Object obj = ic.lookup("blabla");
StudentHome home =(StudentHome) PortableRemoteObject.narrow(blabla,StudentHome.class);
StudentRemote remote= home.create();


my question is ,
I know jndi is used to look up different resources, but what exactly does jndi look up in the above statement.
i want to know how exactly  jndi ( in above program) communicates with the component deployed in the server.


thanks

J
0
jaggernat
Asked:
jaggernat
  • 4
  • 3
  • 2
  • +1
2 Solutions
 
objectsCommented:
It looks up the object named "blabla".
Where this look up is done (the context) needs to be defined in your system properties
0
 
jaggernatAuthor Commented:
ok , but where is "blabla" in the component. Is it the HomeInterface or is it the RemoteInterface or anything else.

thanks for prompt response,
J
0
 
objectsCommented:
It could be anything

the following should help

http://java.sun.com/products/jndi/tutorial/
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
jaggernatAuthor Commented:
thats a huge tutorial .   ok , how is jndi   related to homeinterface or remote interface that we create in the ejb component .


thanks,
J
0
 
objectsCommented:
jndi is the lookup mechanism used to locate the required objects

http://java.sun.com/products/jndi/tutorial/getStarted/examples/naming.html
0
 
JavatmCommented:
> how is jndi related to homeinterface or remote interface that we create in the ejb component.

Actually Context lookup is looking for the " jndi name " of the ejb class that you want to run. The properties that
you set for your initial context will vary to the type of server that you use, here is an example :

Properties home = new Properties();

// This will be different depending on your server. WAS for WSAD
home.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
home.put(Context.PROVIDER_URL, "corbaloc:iiop:localhost:2809");
                  
Context prop = new InitialContext(home);
Object obj = prop.lookup("ejb/com/package/HelloHome");
System.out.println(obj);

Hope that helps . . .
Javatm
0
 
jaggernatAuthor Commented:
so ejb/com/package/HelloHome is the jndi name of ejb class.  right

0
 
objectsCommented:
> Object obj = prop.lookup("ejb/com/package/HelloHome");

that should be the following shouldn't it?

Object obj = prop.lookup("java:comp/ejb/com/package/HelloHome");


if you are more intested in EJB as opposed to JNDI then theres an example here:

http://publib.boulder.ibm.com/infocenter/ws60help/index.jsp?topic=/com.ibm.websphere.nd.doc/info/ae/ae/rnam_example_prop3.html
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> that should be the following shouldn't it?

It could be anything, depending upon the server. For example, in Websphere, you could perform look-up on "WFInd.MaintenanceService" where WFInd.MaintenanceService is defined in ibm-ejb-jar-bnd.xmi as:

  <ejbBindings xmi:id="MaintenanceService_Bnd" jndiName="WFInd.MaintenanceService">
    <enterpriseBean xmi:type="ejb:Session" href="META-INF/ejb-jar.xml#MaintenanceService"/>
  </ejbBindings>

This would search for <ejb-name>MaintenanceService</ejb-name> in ejb-jar.xml.
0
 
JavatmCommented:
>  so ejb/com/package/HelloHome is the jndi name of ejb class.  right

Yes thats correct =)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now