Wednesday, January 31, 2007

Websphere session bean remote invokation tips

Here is how to access remote session bean in Websphere 6.0 server.

For remote session bean lookup, use the following code:

public class RemoteTest {
public static void main(String[] args) {
try {
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY, "");
prop.put(Context.PROVIDER_URL, "corbaloc:iiop:localhost:2809");
Context initContext = new InitialContext(prop);
EchoHome echoHome = (EchoHome) PortableRemoteObject.narrow(
initContext.lookup("ejb/com/yuan/EchoHome"), EchoHome.class);
Echo echo = (Echo) PortableRemoteObject.narrow(
echoHome.create(), Echo.class);
System.out.println("AAA" + echo.print());

} catch (Exception e) {

Two Technical points:

1. All client side library must be in the classpath to avoid exception.
The easy way is to include all jars under the server/lib dir.

2. The lookup address should be the raw name of the session bean (including full class name).
It is different from the lookup in the container environment (java:comp/env/ejb/Echo).

No comments: