-
1. Re: JNDI Properties
jonlee Apr 22, 2003 11:39 AM (in response to catharine)Your code fragment would run something like this to get a reference to the bean:
Properties jndiProps = new Properties();
jndiProps.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
// Replace this with the URL to the JBoss JNDI if on a remote machine
jndiProps.setProperty("java.naming.provider.url", "jnp://localhost:1099");
jndiProps.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
try
{
// Get a naming context
InitialContext jndiContext = new InitialContext(jndiProps);
// Get a reference to the Bean by it's declared JNDI ref
Object ref = jndiContext.lookup("Entries");
// Get a reference from this to the Bean's Home interface
BeanHome home = (BeanHome)PortableRemoteObject.narrow(ref, BeanHome.class);
// Create a Bean object from the Home interface
Bean beanObject = home.create();
}
catch(Exception e)
{
System.out.println("Unable to create Bean home");
System.out.println(e.toString());
e.printStackTrace();
}
BeanHome should be substituted with your Bean's Home class.
Bean is the interface class to your bean. To remotely use methods of your bean, the client only needs to know the interface and the home and does not nead the class with the actual bean code. Usually when building your EJBs for deployment, you pack what I call a client jar which holds these two classes, while the EJB jar has these and the implemented bean code class (as well as any other support classes). Hope that gives you a start. -
2. Re: JNDI Properties
catharine Apr 23, 2003 4:56 AM (in response to catharine)Thanks for your help with this, it worked fine.
Catharine