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