login();
Object obj = getInitialContext().lookup("spec.StatefulSession");
obj = PortableRemoteObject.narrow(obj, StatefulSessionHome.class);
StatefulSessionHome home = (StatefulSessionHome) obj;
log.debug("Found StatefulSession");
StatefulSession bean = home.create("testStatefulHandle");
log.debug("Created spec.StatelessSession");
Handle h = bean.getHandle();
log.debug("Obtained handle: " + h);
bean = (StatefulSession) h.getEJBObject();
log.debug("Obtained bean from handle: " + bean);
log.debug("Bean.echo('Hello') -> " + bean.echo("Hello"));
logout();
/*
* Attempting to obtain the EJB fron the handle without security association present should fail
*/
try
{
bean = (StatefulSession) 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 = (StatefulSession) h.getEJBObject();
log.debug("Obtained bean from handle: " + bean);
log.debug("Bean.echo('Hello') -> " + bean.echo("Hello"));
logout();
}