Properties env = new Properties();
env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.NamingContextFactory");
InitialContext ctx = new InitialContext(env);
StatefulSessionHome home = ( StatefulSessionHome ) ctx.lookup("ejbcts/BMTStatefulSessionBean");
StatefulSession bean = home.create("testBMTSessionHandleNoDefaultJNDI");
Handle beanHandle = bean.getHandle();
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(out);
oos.writeObject(beanHandle);
oos.flush();
byte[] bytes = out.toByteArray();
Properties sysProps = System.getProperties();
Properties newProps = new Properties(sysProps);
newProps.setProperty("java.naming.factory.initial", "badFactory");
newProps.setProperty("java.naming.provider.url", "jnp://badhost:12345");
System.setProperties(newProps);
try
{
getLog().debug("Unserialize bean handle...");
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(in);
beanHandle = (Handle) ois.readObject();
bean = (StatefulSession) beanHandle.getEJBObject();
bean.method1("Hello");
getLog().debug("Called method1 on handle session bean");
}
finally
{
System.setProperties(sysProps);