This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes InitialContext lookup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "InitialContext lookup" Watch "InitialContext lookup" New topic
Author

InitialContext lookup

L Goundalkar
Ranch Hand

Joined: Jul 05, 2001
Posts: 395
Hi,
I have some basic clarifications.
1. What exactly happens when I say new InitialContext.lookup("mybean");
2. How can i look up a EJB residing in different machine from a web component.
3. What do you mean by java:comp\env ??
4. How does my JVM know about the JNDI server? Do we need to specify the IP address and other details of JNDI server while looking up for home object?

Thanks for the time.


SCJP, SCWCD
Edward Kenworthy
Ranch Hand

Joined: Oct 05, 2003
Posts: 66
Basically it's performing a name lookup. It matches the name you give in the lookup method call to a list held by a nameserver and returns a reference to the "thing" it found- in your case I guess an EJB of some kind's home interface.
What's significant about the java/compblahblahblah bit?- not much. It's simply a naming convention to separate java names from any other kind of 'thing' that the name server knows about.
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
1. What exactly happens when I say new InitialContext.lookup("mybean");
- An Object that is bound to the name "mybean" is returned from the JNDI Server.Usually we use calls like this, to get a reference to the home reference of an EJB, from an EJBClient.
2. How can i look up a EJB residing in different machine from a web component.
- By creating a different InitialContext Object. The InitialContext Object takes Hashtable or Properties Object in the constructor. You will fill in the details like IP Address, Port number etc of the other EJB Server in the Hashtable.
3. What do you mean by java:comp\env ??
- As Edward said, it is bean's own private name space, in which you store constants used by the bean.
4. How does my JVM know about the JNDI server? Do we need to specify the IP address and other details of JNDI server while looking up for home object?
- Yes. While creating the InitialContext, you specify these details including the JNDI Driver.
For example, to retrieve an EJB home reference in an EJBClient program:

[ March 03, 2004: Message edited by: Vish Kumar ]
L Goundalkar
Ranch Hand

Joined: Jul 05, 2001
Posts: 395
Thanks edward and vish.
Manoj Raghuwanshi
Ranch Hand

Joined: Jun 20, 2004
Posts: 75
I am having a EJB server and client running on different jvm.

Lookup code is-

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, jndiUrl);
env.put("java.naming.factory.url.pkgs", "org.jboss.naming rg.jnp.interfaces");

try
{
InitialContext jndiContext=new InitialContext(env);
Object ref=jndiContext.lookup("PDFHandler");

some code


JndiUrl is->jnp://192.168.0.5:1099

what i am getting is-
javax.naming.CommunicationException [Root exception is java.rmi.NoSuchObjectException: no such object in table]



where I am going wrong?

Thanks
[ March 11, 2005: Message edited by: Manoj Raghuwanshi ]
arunij katiliyar
Greenhorn

Joined: Mar 09, 2005
Posts: 26
Please check whether the JNDI url string is vaild and points to the jndi server or appserver hosting the JNDI service .

If its valid then check the JNDI name that you used for lookup . Check in the appserver whether the ejb is pinned to this name . I believe its the JNDI url string problem .


Murugan
Manoj Raghuwanshi
Ranch Hand

Joined: Jun 20, 2004
Posts: 75
my problem is not solved please help me

I made some changes in jboss.xml

Earlier version was this:-

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd">

<jboss>

<unauthenticated-principal>nobody</unauthenticated-principal>

<enterprise-beans>

<session>
<ejb-name>StringProcessorBean</ejb-name>
<jndi-name>StringProcessor</jndi-name>
</session>

</enterprise-beans>

<resource-managers>
</resource-managers>

</jboss>



changes made:-

<ejb-name>StringProcessorBean</ejb-name>
<jndi-name>StringProcessorBean</jndi-name>


setup is same ejb deployed on 192,168.0.5(linux box) and client on
192.168.0.245(linux box)

now I am getting following exception

java.rmi.ConnectException: Connection refused to host: 127.0.0.1

[ March 15, 2005: Message edited by: Manoj Raghuwanshi ]
[ March 15, 2005: Message edited by: Manoj Raghuwanshi ]
Manoj Raghuwanshi
Ranch Hand

Joined: Jun 20, 2004
Posts: 75
ok at last i solved the problem.

change /etc/hosts file

192.168.0.5 gladiator
127.0.0.1 localhost

now it is a distributed application
thanks any way
 
Don't get me started about those stupid light bulbs.
 
subject: InitialContext lookup
 
Similar Threads
Find JNDI name in Neteans 6.8 ???
Use of JNDI
Accessing external DataSource
JNDI in websphere
Setting up the JNDI name of a data source in JBuilder