login();
Object obj = getInitialContext().lookup("spec.StatelessSession");
obj = PortableRemoteObject.narrow(obj, StatelessSessionHome.class);
StatelessSessionHome home = (StatelessSessionHome) obj;
log.debug("Found StatelessSessionHome");
StatelessSession bean = home.create();
log.debug("Created spec.StatelessSession");
Handle h = bean.getHandle();
log.debug("Obtained handle: " + h);
bean = (StatelessSession) h.getEJBObject();
log.debug("Obtained bean from handle: " + bean);
log.debug("Bean.echo('testHandle') -> " + bean.echo("testHandle"));
logout();
/*
* Attempting to obtain the EJB fron the handle without security association present should fail
*/
try
{
bean = (StatelessSession) h.getEJBObject();
fail("Should not be able to obtain a bean without login info");
}
catch (Exception e)
{
log.debug("Obtaining bean from handle failed as expected, e=" + e.getMessage());
}
// One should be able to obtain a handle without a login
h = bean.getHandle();
login();
// Now we should be able to obtain and use the secure bean
bean = (StatelessSession) h.getEJBObject();
log.debug("Obtained bean from handle: " + bean);
log.debug("Bean.echo('testHandle2') -> " + bean.echo("testHandle2"));
logout();
}