Interoperability between JOnAS and CORBA

The aim of this document is to show basic usage of interoperability between JOnAS and CORBA using RMI-IIOP (the examples in this document assume that the Sun rmi/iiop of the JDK 1.4 is used).

This document describes:

  1. Accessing an EJB deployed on JOnAS server by a CORBA client
  2. Accessing a CORBA service by an EJB deployed on JOnAS server

Accessing an EJB deployed on JOnAS server by a CORBA client

JOnAS Configuration

No modification on the EJB code is necessary. However, you should deploy it for the iiop protocol, e.g. when you create the build.xml, add the tag "protocols" and specify "iiop".
For example:

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

If you are using GenIC for deploying, you may use the -protocols option, note also that you may deploy an EJB for several protocols, see the JOnAS Configuration Guide about configuring the communication protocol for more details.

In order for the JOnAS server to use RMI-IIOP, you must modify the JOnAS configuration.
In the file carol.properties, choose the iiop protocol, see also the JOnAS Configuration Guide for details about configuring the communication protocol.
These modifications enable to create an EJB using RMI-IIOP protocol.

RMIC to create IDL files used by the Corba Client

In order to call an EJB deployed on JOnAS accessible through RMI-IIOP, you must to create the idl files. For this, use the rmic tool on the EJB Remote interface and EJB Home interface. Example: rmic -classpath $JONAS_ROOT/lib/common/j2ee/ejb.jar -idl package1.Hello

This action generates many 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 in the directory where you develop your CORBA client.

CORBA Client Development

1. idlj

Once idl files are generated, you must apply the idlj tool to build java files corresponding to idl files (idlj = idl to java). For this, apply idlj tool to Remote interface idl file and Home interface idl file. Example: idlj -fclient -emitAll package1/Hello.idl

The idlj tool also generates bugged classes. Indeed in the class _Exception.java, CreateException.java, RemoveException.java put the _read and _write method in comment.

Also the class OutputStream.java, PrintStream.java, PrintWriter.java, Writer.java, FilterOuputStream.java must extend Serializable and then replace

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

by

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

in the write method.

2. Client

Create your 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);
	}
    }
}
    

3. Compilation

Compile the generated files.


WARNING: compile the file corresponding to client part. This files are Hello.java, HelloHome.java, _Exception.java, ..., and _*Stub.java, *Helper.java, *ValueFactory.java, *Operation.java (* represente a name of interface).

Accessing a CORBA service by an EJB deployed on JOnAS server

CORBA Service

Create your CORBA service.

Create the idl file corresponding to this service (e.g. the interface name of which is "Hello").

Generate the java file corresponding to the idl service by idlj -fall Hello.idl tool.

Implement the java interface (in our example, in the server implementation, the service will be bound with the name "Hello").

Start your orb.

Start your CORBA service.

EJB on JOnAS

In order to call your CORBA service, you must generate java file corresponding to idl file.

For this, apply the idlj tool on the idl file corresponding to CORBA service description.

idlj -fclient Hello.idl

Then create your EJB.

For calling your CORBA service, you must initialize the orb. For this specify the host and the port.

Then get the environment.

With the environment you can get the java object corresponding to CORBA service.

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) {
	      ...
	  }