38.2. Accessing a CORBA Service by an EJB Deployed on JOnAS Server

38.2.1. Setting up the CORBA Service

Create the CORBA service:

  1. Create the idl file corresponding to this service (for example, the interface name, which is "Hello").

  2. Generate the Java file corresponding to the idl service:

    idlj -fall Hello.idl
  3. Implement the Java interface (in this example, the service will be bound with the name "Hello" in the server implementation).

  4. Start the orb.

  5. Start the CORBA service.

38.2.2. Setting up the EJB on JOnAS

Set up the EJB on JOnAS as follows:

  1. To call the CORBA service, generate the Java file corresponding to the idl file. To do this, apply the idlj tool on the idl file corresponding to the CORBA service description:

    idlj -fclient Hello.idl
  2. Create an EJB.

  3. To call the CORBA service, initialize the orb by specifying the host and the port.

  4. Get the environment.

  5. Get the Java object corresponding to the CORBA service with the environment.

  6. Call the method on this object.

Example code:

try {
     String[] h=new String[4];
     h[0]="-ORBInitialPort";
     h[1]=port;
     h[2]="-ORBInitialHost";
     h[3]=host;
    
     ORB orb=ORB.init(h,null);
 
     // get a reference on the context handling all services
     org.omg.CORBA.Object 
       objRef=orb.resolve_initial_references("NameService");
     
     NamingContextExt ncRef=NamingContextExtHelper.narrow(objRef);
     Hello hello=HelloHelper.narrow(ncRef.resolve_str("Hello"));
     System.out.println(hello.sayHello());
     return hello.sayHello();
     }
     catch (Exception e) {
         ...
     }