Saturday, May 22, 2010

Foreign JNDI provider - call remote EJB

Create two domains - base_domain and remote_domain.


Setup Foreign JNDI provider on base_domain pointing to remote_domain.


http://download.oracle.com/docs/cd/E12840_01/wls/docs103/ConsoleHelp/taskhelp/jndi/ConfigureForeignJNDIProvider.html






Create session EJB calling remote session EJB and deploy to base_domain.
package testEAR;

import javax.ejb.Stateless;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import remoteEAR.RemoteEJBRemote;

/**
* Session Bean implementation class CallRemoteBean
*/
@Stateless
public class CallRemoteBean implements CallRemoteBeanLocal {

public CallRemoteBean() {
}


public void callRemoteBean(){


RemoteEJBRemote remoteEJB = null;
try {
remoteEJB = (RemoteEJBRemote)new InitialContext().lookup("RemoteEJB");
} catch (NamingException e) {
e.printStackTrace();
}
System.out.println("Calling remote");
String response = remoteEJB.hello();

System.out.println("Response remote=" + response);

}

}


Create session bean on remote_domain

package remoteEAR;

import javax.ejb.Stateless;

/**
* Session Bean implementation class RemoteEJB
*/
@Stateless(mappedName = "RemoteEJB")
public class RemoteEJB implements RemoteEJBRemote {

/**
* Default constructor.
*/
public RemoteEJB() {
}

public String hello(){
System.out.println("In remote");
return "Hello from remote";
}

}


All projects created in Eclipse 3.5


EJB3 reference injection problems
http://forums.oracle.com/forums/thread.jspa?messageID=4030853

http://msikora.typepad.com/michael_sikora_on_java_ee/page/2/

http://m-button.blogspot.com/2008/07/reminder-on-how-to-use-ejb3-with.html

http://biese.wordpress.com/2008/02/20/how-to-call-ejb3-from-jsp-servlet-and-stand-alone-application/

1 comment:

  1. Hi, could you tell me how to configure the "Remote JNDI Name" field? In your snapshot the information is truncated.

    Thank you!
    Antonio

    ReplyDelete