RE:problema con JNDI y EJB's porcierto
aqui esta el codigo fuente:
//LOCAL
import java.rmi.RemoteException;
import javax.ejb.EJBHome;
import javax.ejb.CreateException;
public interface PerfectTimeHome extends EJBHome
{
public PerfectTime create() throws CreateException, RemoteException;
}
//REMOTA
import java.rmi.RemoteException;
import javax.ejb.EJBObject;
public interface PerfectTime extends EJBObject
{
public long getPerfectTime() throws RemoteException;
}
//BUSSINES LOGIC
import java.rmi.*;
import javax.ejb.*;
public class PerfectTimeBean implements SessionBean
{
private SessionContext sessionContext = null;
//return current time
public long getPerfectTime()
{
return System.currentTimeMillis();
}
// EJB methods
public void ejbCreate()
throws CreateException {}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void
setSessionContext(SessionContext ctx)
{
sessionContext = ctx;
}
}
//cliente (APLICACION)
public class PerfectTimeClient
{
public static void main(String[] args) throws Exception
{
// Get a JNDI context using
// the JNDI Naming service:
javax.naming.Context context = new javax.naming.InitialContext();
// Look up the home interface in the
// JNDI Naming service:
Object ref = context.lookup("perfectTime");
// Cast the remote object to the home interface:
PerfectTimeHome home = (PerfectTimeHome)
javax.rmi.PortableRemoteObject.narrow(ref, PerfectTimeHome.class);
// Create a remote object from the home interface:
PerfectTime pt = home.create();
// Invoke getPerfectTime()
System.out.println("Perfect Time EJB invoked, time is: " +
pt.getPerfectTime() );
}
}
<!-- ejb:jar -->
<?xml version="1.0" encoding="US-ASCII" ?>
<!DOCTYPE ejb-jar (View Source for full doctype...)>
<ejb-jar>
<description>Example for Chapter 15</description>
<display-name />
<small-icon />
<large-icon />
<enterprise-beans>
<session>
<ejb-name>PerfectTime</ejb-name>
<home>PerfectTimeHome</home>
<remote>PerfectTime</remote>
<ejb-class>PerfectTimeBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<ejb-client-jar />
</ejb-jar>
GRACIAS