2

EJBs can be accessed with RMI or as SOAP-RESTful endpoint. I want to access a remote EJB from another computer/ip address for example in a standalone application. I can reach to EJBs with web services endpoint then i dont know to reach with RMI. How can i implement this idea. I'm using Glassfish 3.1.

Rahman Usta
  • 716
  • 3
  • 14
  • 28

1 Answers1

0

Check out the How do I access a Remote EJB component from a stand-alone java client? document. Code snippets rely on EJB 2 (Home interfaces), you should lookup @Remote interfaces directly. Of course they must be available on the client side.

Example

Based on: Creating EJB3 Sessions Beans using Netbeans 6.1 and Glassfish:

jndi.properties:

java.naming.factory.initial = com.sun.enterprise.naming.SerialInitContextFactory
java.naming.factory.url.pkgs = com.sun.enterprise.naming
java.naming.factory.state = com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl
org.omg.CORBA.ORBInitialHost = localhost
org.omg.CORBA.ORBInitialPort = 3700

Main.java:

package testclient;

import java.io.FileInputStream;
import java.util.Properties;
import javax.naming.InitialContext;
import stateless.TestEJBRemote;

public class Main {

    public static void main(String[] args) {
        try {
            Properties props = new Properties();
            props.load(new FileInputStream("jndi.properties"));
            InitialContext ctx = new InitialContext(props);
            TestEJBRemote testEJB = (TestEJBRemote) ctx.lookup("stateless.TestEJBRemote");
            System.out.println(testEJB.getMessage());
        } catch (NamingException nex) {
            nex.printStackTrace();
        } catch (FileNotFoundException fnfex) {
            fnfex.printStackTrace();
        } catch (IOException ioex) {
            ioex.printStackTrace();
        }

    }

}

See also

Community
  • 1
  • 1
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674