Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Calling remote EJB

  Asked By: Kerri    Date: Sep 11    Category: Java    Views: 877
  

I have a question about EJB. In EJB 3 , How to calling a remote stateless
session beans that located in another computer?

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Adal Fischer     Answered On: Sep 11

check this snippet:

Hashtable props = new Hashtable();
props.put("org.omg.CORBA.ORBInitialHost", "192.168.1.1"); // the IP address or name of the server
props.put("org.omg.CORBA.ORBInitialPort","3700"); //the port, ususally 3700
InitialContext ctx = new InitialContext(props);

ARemoteStatelessSessionBeanInterface service = (ARemoteStatelessSessionBeanInterface) ctx.lookup(ARemoteStatelessSessionBeanInterface.class.getName()); //JNDI name is usually the full package name but might be changed

//use the service
service.callAMethod();

 
Answer #2    Answered By: Devlan Jones     Answered On: Sep 11


Thanks for your consideration. I will test your snippet.

 
Answer #3    Answered By: Heru Chalthoum     Answered On: Sep 11

Unfortunately you have to use different ways to look up a remote   EJB 3 session bean using JNDI 'cause different application servers have different behavior.

For glassfish

Context context = new InitialContext();
HelloWorld helloWorld = (HelloWorld) context.lookup(HelloWorld.class.getName());

Context context = new InitialContext();
HelloWorldLocal helloWorld = (HelloWorldLocal) context.lookup(HelloWorldLocal.class.getName());

for JBoss



Context context = new InitialContext();
HelloWorld helloWorld = (HelloWorld) context.lookup("HelloWorldBean/remote");

HelloWorld helloWorld = (HelloWorld) context.lookup("HelloWorldBean/local");

for Weblogic

Context context = new InitialContext();
HelloWorld helloWorld = (HelloWorld) context.lookup("<your-mapped-name>#<your-session-bean-class-full-name>");

I couldn't find a way for Local looking up yet in weblogic

 
Didn't find what you were looking for? Find more on Calling remote EJB Or get search suggestion and latest updates.




Tagged: