Chapter 38. Interoperability between JOnAS and CORBA

This chapter describes the basic interoperability between JOnAS and CORBA using RMI-IIOP.

38.1. Accessing an EJB Deployed on a JOnAS Server by a CORBA Client

38.1.1. JOnAS Configuration

No modification to the EJB code is necessary. However, the EJB should be deployed for the iiop protocol (for example, when the build.xml is created, add the tag "protocols" and specify "iiop"). For example:

<jonas destdir="${dist.ejbjars.dir}" classpath="${classpath}" 
  jonasroot="${jonas.root}" protocols="iiop"/>

If GenIC is used for deployment, the -protocols option can be used. Note also that an EJB can be deployed for several protocols. Refer to the JOnAS Configuration Guide for more details about configuring the communication protocol.

The JOnAS configuration must be modified for the JOnAS server to use RMI-IIOP. Choose the iiop protocol in the file carol.properties. Refer also to the Section 3.3 Configuring the Communication Protocol and JNDI for details about configuring the communication protocol. These modifications will make it possible to create an EJB using the RMI-IIOP protocol.

38.1.2. Using RMIC to Create IDL Files Used by the CORBA Client

To call an EJB deployed on JOnAS that is accessible through RMI-IIOP, use the rmic tool on the EJB Remote interface and EJB Home interface to create the idl files. For example:

rmic -classpath $JONAS_ROOT/lib/common/j2ee/ejb.jar -idl package1.Hello

This action generates several idl files:

package1/Hello.idl
package1/HelloHome.idl

java/io/FilterOutputStream.idl
java/io/IOException.idl
java/io/IOEx.idl
java/io/OutputStream.idl
java/io/PrintStream.idl
java/io/Writer.idl
java/io/PrintWriter.idl

java/lang/Exception.idl
java/lang/Ex.idl
java/lang/Object.idl
java/lang/StackTraceElement.idl
java/lang/ThrowableEx.idl
java/lang/Throwable.idl

javax/ejb/EJBHome.idl
javax/ejb/EJBMetaData.idl
javax/ejb/EJBObject.idl
javax/ejb/Handle.idl
javax/ejb/HomeHandle.idl
javax/ejb/RemoveException.idl
javax/ejb/RemoveEx.idl

org/omg/boxedRMI/seq1_octet.idl
org/omg/boxedRMI/seq1_wchar.idl

org/javax/rmi/CORBA/ClassDesc.idl
org/omg/boxedRMI/java/lang/seq1_StackTraceElement.idl

Copy these files to the directory in which CORBA client development is being done.

38.1.3. CORBA Client Development

38.1.3.1. idlj

Once idl files are generated, apply the idlj tool to build Java files corresponding to the idl files (idlj = idl to java). To do this, apply the idlj tool to the Remote interface idl file and the Home interface idl file. For example:

idlj -fclient -emitAll package1/Hello.idl

The idlj tool also generates bugged classes. Be sure to put the _read and _write method in comments in the classes _Exception.java, CreateException.java, RemoveException.java.

Additionally, the classes OutputStream.java, PrintStream.java, PrintWriter.java, Writer.java, and FilterOuputStream.java must extend Serializable and then replace

((org.omg.CORBA_2_3.portable.OutputStream) 
  ostream).write_value(value,id());

with

((org.omg.CORBA_2_3.portable.OutputStream) 
  ostream).write_value((Serializable) value,id());

in the write method.

38.1.3.2. The CORBA Client

Create the CORBA client:

import org.omg.CosNaming.*;
import org.omg.CORBA.*;

public class Client {
  public static void main(String args[]) {
    try {
        //Create and initialize the ORB
        ORB orb=ORB.init(args,null);
        //Get the root naming context
        org.omg.CORBA.Object 
          objRef=orb.resolve_initial_references("NameService");
        NamingContext ncRef= NamingContextHelper.narrow(objRef);

        //Resolve the object reference in naming
        //make sure there are no spaces between ""
        NameComponent nc= new NameComponent("HelloHome","");
        NameComponent path[] = {nc};
        HelloHome tradeRef=HelloHomeHelper.narrow(ncRef.resolve(path));

        //Call the Trader EJB and print results
        Hello hello=tradeRef.create();
        String tr=hello.say();
        System.out.println("Result = "+tr);
    }
    catch (Exception e) {
        System.out.println("ERROR / "+e);
        e.printStackTrace(System.out);
    }
  }
}

38.1.3.3. Compilation

Compile the generated files.

WarningWarning
 

Compile the file corresponding to the client parts, the files Hello.java, HelloHome.java, _Exception.java, ..., and _*Stub.java, *Helper.java, *ValueFactory.java, *Operation.java (* represents the name of the interface).