aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes JNDI lookup errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JNDI lookup errors" Watch "JNDI lookup errors" New topic
Author

JNDI lookup errors

James White
Greenhorn

Joined: Apr 22, 2003
Posts: 23

I am using ant to build and compile a simple EJB. The EJB builds and deploys to jboss 4.0.2 fine, but when I try and run the client here is what I get:

C:\workbook\homework1>ant run.client_1
Buildfile: build.xml

prepare:

compile:
[javac] Compiling 1 source file to C:\workbook\homework1\build\classes

ejbjar:

run.client_1:
[java] log4j:WARN No appenders could be found for logger (org.jnp.interface
s.NamingContext).
[java] log4j:WARN Please initialize the log4j system properly.
[java] javax.naming.CommunicationException: Receive timed out [Root excepti
on is java.net.SocketTimeoutException: Receive timed out]
[java] at org.jnp.interfaces.NamingContext.discoverServer(NamingContext
.java:1302)
[java] at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:
1382)
[java] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:57
9)
[java] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:57
2)
[java] at javax.naming.InitialContext.lookup(InitialContext.java:347)
[java] at com.SE554.clients.Client_1.main(Client_1.java:19)
[java] Caused by: java.net.SocketTimeoutException: Receive timed out
[java] at java.net.PlainDatagramSocketImpl.receive(Native Method)
[java] at java.net.DatagramSocket.receive(DatagramSocket.java:711)
[java] at org.jnp.interfaces.NamingContext.discoverServer(NamingContext
.java:1272)
[java] ... 5 more

BUILD SUCCESSFUL
Total time: 7 seconds
C:\workbook\homework1>

I am using this code to access the EJB:

package com.SE554.clients;
import com.SE554.homework1.PersonHomeRemote;
import com.SE554.homework1.PersonRemote;
import javax.naming.InitialContext;
import javax.naming.Context;
import java.util.Properties;
import javax.naming.NamingException;
import java.rmi.RemoteException;
import javax.rmi.PortableRemoteObject;

public class Client_1
{

public static void main(String [] args)
{
try
{
Context jndiContext = getInitialContext();
Object ref = jndiContext.lookup("PersonHomeRemote");
PersonHomeRemote home = (PersonHomeRemote)
PortableRemoteObject.narrow(ref,PersonHomeRemote.class);
PersonRemote person_1 = home.create(new Integer(1));
person_1.setFirstName("James");
person_1.setLastName("White");
person_1.setCity("Chicago");
person_1.setState("IL");
person_1.setAddress("123 Main Street");
person_1.setZipCode("60600");

Integer pk = new Integer(1);

PersonRemote person_2 = home.findByPrimaryKey(pk);
System.out.println(person_2.getFirstName());
System.out.println(person_2.getLastName());
System.out.println(person_2.getState());
System.out.println(person_2.getAddress());
System.out.println(person_2.getZipCode());

}
catch (java.rmi.RemoteException re){re.printStackTrace();}
catch (javax.naming.NamingException ne){ne.printStackTrace();}
catch (javax.ejb.CreateException ce){ce.printStackTrace();}
catch (javax.ejb.FinderException fe){fe.printStackTrace();}
}

public static Context getInitialContext()
throws javax.naming.NamingException
{
//return new InitialContext();
/**** context initialized by jndi.properties file */
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
p.put(Context.URL_PKG_PREFIXES, "jboss.naming rg.jnp.interfaces");
p.put(Context.PROVIDER_URL, "localhost:1099");
return new javax.naming.InitialContext(p);


}


}

The line of code that is erroring out is the jndi lookup (Object ref = jndiContext.lookup("PersonHomeRemote") . I have this interface (PersonHomeRemote) in both my ejb-jar.xml and jboss.xml files, but I'm still not sure why the client is unable to find my EJB. Any other suggestions?

Thanks,

JW
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
The interface is not enough. The lookup is returning a stub, so you must place the stub class onto the client's classpath as well.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
James White
Greenhorn

Joined: Apr 22, 2003
Posts: 23

The interface is not enough. The lookup is returning a stub, so you must place the stub class onto the client's classpath as well.


I am not sure how I do that. I am testing from the same machine I am calling the stub from. I know I don't necessarily need a remote interface for this particular example. I still would like to know how I can add the stub to the classpath.

Thanks,

JW
 
jQuery in Action, 2nd edition
 
subject: JNDI lookup errors