This guide describes the basic 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).
The content of this guide is the following:
No modification to the EJB code is necessary. However, the EJB should be
deployed for the iiop protocol (e.g. 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 JOnAS Configuration Guide for
details about configuring the communication protocol.
These modifications will make it possible to create an EJB using the RMI-IIOP
protocol.
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. 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.
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. Example: idlj -fclient -emitAll package1/Hello.idl
The idlj tool also generates bugged classes. Be sure to put the _read and _write method in comment in the class _Exception.java, CreateException.java, RemoveException.java.
Additionally, 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());
with
((org.omg.CORBA_2_3.portable.OutputStream) ostream).write_value((Serializable) value,id());
in the write method.
2. 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); } } }
3. Compilation
Compile the generated files.
WARNING: 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).
Create the CORBA service.
Create the idl file corresponding to this service (e.g. the interface name, which is "Hello").
Generate the java file corresponding to the idl service with the idlj -fall Hello.idl tool.
Implement the java interface (in this example, the service will be bound with the name "Hello" in the server implementation).
Start the orb.
Start the CORBA service.
To call the CORBA service, generate the java file corresponding to the idl file.
For this, apply the idlj tool on the idl file corresponding to the CORBA service description:.
idlj -fclient Hello.idl
Then, create an EJB.
For calling the CORBA service, initialize the orb by specifying the host and the port.
Then, get the environment.
Get the java object corresponding to the CORBA service with the environment.
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) { ... }