Lookup and invoke a _local_ EJB via a remote EJB by a remote client
virtuellesnugat Jun 19, 2012 10:40 AMHi there,
I'm new to the jboss AS and the EJB. The book I've read doesn't help me, since the new JNDI naming changes so much.
But during the last days I've managed to setup the server, deploy some remote stateful and stateless session beans. But now I'm trying something different:
- Local stateless session bean named "TimeBean", with it's interface "ITimeLocal"
- Remote stateless session bean named "CallerBean", with it's interface "ICallerRemote"
- and a remote Client named "CallerClientBean"
ITimeLocal
package test.jboss.umweg.server.local; import javax.ejb.Local; @Local public interface ITimeLocal { public long getTime(); }
TimeBean
package test.jboss.umweg.server.local; import java.util.Date; import javax.ejb.Local; import javax.ejb.Stateless; @Stateless @Local(ITimeLocal.class) public class TimeBean implements ITimeLocal { @Override public long getTime() { return new Date().getTime(); } }
So that's just the local bean. It was deployed successfully and the JNDI Bindings where created.
The call from the CallerClientBean to the CallerBean works fine (I tested with "return 0").
But when I tried the real call it wouldn't work:
Extracted from CallerBean
@Override public long askTime() { // lookup and invoke Local Bean, return time try { Context context = getInitialContext(); ITimeLocal szb = (ITimeLocal) context.lookup(getJndiName()); long time = szb.getTime(); System.out.println("Time: " + time); return time; } catch (NamingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return 0; }
I build the InitialContext like this (though I didn't set a "jboss-ejb-client.properties" on server side, maybe that's a problem):
private InitialContext getInitialContext() throws NamingException { Hashtable p = new Hashtable(); p.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); return new InitialContext(p); }
And I tried two different JNDI names:
- the same I've been building the other ones:
ejb:/TimeBean//TimeBean!test.jboss.umweg.server.local.ITimeLocal - and the global JNDI binding I got from the deploy:
java:global/TimeBean/TimeBean!test.jboss.umweg.server.local.ITimeLocal
But I guess my main-problem is, that I'm not aware of howto call a local bean. And I couldn't find anything really helpful. I didn't post the Exceptions (first runtime, the illegalState), but I bet my faults are obvious to most people here
Thanks!!