InitialContext ctx = new InitialContext();
ExampleProducerRemote remote = (ExampleProducerRemote) ctx.lookup(ExampleProducerRemote.class.getName());
// you can typecast the returned proxy to obtain a ProducerManager interface that allows you to manage
// interaction with JMS.
ProducerManager manager = ((ProducerObject) remote).getProducerManager();
// connect
manager.connect();
try
{
// Call method1
remote.method1("Remote method1 called", 1);
// Call method2
Map<String, String> map = new HashMap<String, String>();
map.put("hello", "world");
map.put("great", "ejb3");
remote.method2("Remote method2 called", map);
}
finally
{
// instead of typecasting, you can use a helper class that does everything for you.
ProducerConfig.close(remote);
}
// Try out local producers by interfacing with Session bean
Tester tester = (Tester) ctx.lookup("TesterBean/remote");
tester.testLocal();
tester.testXA();