Nav
Nav

Reputation: 4540

Access to remote EJB running in another Glassfish(EJB-Container) from another Glassfish(Web-Container)

I want to use two separate servers, one for web-container and one for ejb-container. The both of these two containers are Glassfish V3.

But, How to use @EJB annotation in my web project to access to remote ejb-container's ejb(s).

In Ejb 2.0 we have to use ejb-descriptors but what happened in Ejb3.0 and glassfish v3?

thanks

Upvotes: 1

Views: 10060

Answers (1)

Pablo
Pablo

Reputation: 53

I've never personally done that because I prefer using local interfaces within the same JVM as it improves performance dramatically.

But you can check this out:

https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB

But you can give this a try:

    Properties props = new Properties();

  props.setProperty("java.naming.factory.initial",
                    "com.sun.enterprise.naming.SerialInitContextFactory");

  props.setProperty("java.naming.factory.url.pkgs",
                    "com.sun.enterprise.naming");

  props.setProperty("java.naming.factory.state",
                    "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");


  // optional.  Defaults to localhost.  Only needed if web server is running
  // on a different host than the appserver   
  props.setProperty("org.omg.CORBA.ORBInitialHost", "ejb_server_ip_or_host_name");

  // optional.  Defaults to 3700.  Only needed if target orb port is not 3700.
  props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

  InitialContext ic = new InitialContext(props);

Step 2. Use the global JNDI name of the target Remote EJB in the lookup.

EJB 3.x, assuming a global JNDI name of "com.acme.FooRemoteBusiness" :

 FooRemoteBusiness foo = (FooRemoteBusiness) ic.lookup("com.acme.FooRemoteBusiness");

EJB 2.x, assuming a global JNDI name of "com.acme.FooHome" :

Object obj = ic.lookup("com.acme.FooHome");

  FooHome fooHome = (FooHome) PortableRemoteObject.narrow(obj, FooHome.class);

Upvotes: 1

Related Questions