Exposing CORBA Services as Web Services

Overview

What is CORBA?

CORBA stands for Common Object Request Broker Architecture. It allows clients to invoke methods of remote objects running on remote machines through a binary protocol such as IIOP.

What Axis2 CORBA module does?

The Axis2 CORBA module acts as a bridge between SOAP and IIOP protocols by converting SOAP messages originated from a web services client to IIOP messages and vise versa. In other words, Axis2 CORBA module allows web service client to invoke methods on a remote CORBA server.

Features

  • Supports all the primitive and composite IDL data types including Value types (objects by value), Structures, Union, Sequences and Arrays (including multidimensional arrays), Enumerations and Exceptions.
  • Dynamic conversion of complex data types
  • IDL driven WSDL generation
  • Supports CORBA pre-processor directives

Why it is Useful?

  • Convert legacy CORBA services into web services
  • Facilitate interoperability between heterogeneous systems
  • Integrate CORBA services with Enterprise Service Buses (ESBs)

Tutorial

This tutorial explains how to write a simple CORBA service and how to make it available as a web service using the Axis2 CORBA module. Let's start the tutorial by creating an IDL file.

Prerequisites

  • Sun JDK version 5.0 or higher
  • Latest version of Axis2 with Axis2 CORBA module

Creating the IDL file

The Interface Definition Language (IDL) is used to describe the interface to a CORBA object. An IDL file can then be used to generate the source code for the CORBA server. Copy the following listing and save as a text file named calculator.idl.
// Address book system module
module example
{
    // A data structure which contains two integer values
    struct numbers
    {
        long first;
        long second;
    };
 
    // Specify interface to our address book
    interface calculator
    {
        // returns n.first + n.second
        long add(in numbers n);

        // returns n.first + n.second
        long subtract(in numbers n);
    };
};

Creating the CORBA server

Open a console window and type the following command. (Make sure JAVA_HOME/bin is included to the PATH environment variable)
idlj -fall calculator.idl
idlj generates several classes needed for CORBA servers and client. Typically, idlj command will generate the following file structure.
|
|   calculator.idl
|
\---example
        numbersHelper.java
        numbersHolder.java
        numbers.java
        calculatorPOA.java
        _calculatorStub.java
        calculatorHolder.java
        calculatorHelper.java
        calculator.java
        calculatorOperations.java
Goto the example subdirectory and create calculatorImpl.java file as follows.
package example;

import example.calculatorPackage.numbers;

public class calculatorImpl extends calculatorPOA {

	public int add(numbers n) {
		return n.first + n.second;
	}

	public int subtract(numbers n) {
		return n.first - n.second;
	}
}
Go back to the root directory (the directory where calculator.idl is located) and create Server.java as follows.
import java.io.*;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;
import example.calculatorImpl;

public class Server {
    public static void main(String[] args) {
        org.omg.CORBA_2_3.ORB orb = 
        	(org.omg.CORBA_2_3.ORB) org.omg.CORBA.ORB.init(args, null);
        try {
            org.omg.PortableServer.POA poa = 
            	org.omg.PortableServer.POAHelper.narrow(
            			orb.resolve_initial_references("RootPOA"));
            poa.the_POAManager().activate();
            org.omg.CORBA.Object o = 
            	poa.servant_to_reference(new calculatorImpl());
            if(args.length == 1) {
                PrintWriter ps = new PrintWriter(new FileOutputStream(args[0]));
                ps.println(orb.object_to_string(o));
                ps.close();
            } else {
                NamingContextExt nc = 
                	NamingContextExtHelper.narrow(
                			orb.resolve_initial_references("NameService"));
                nc.bind(nc.to_name("calculator"), o);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        orb.run();
    }
}
Compile all the Java classes by using the following command.
javac *.java

Creating the CORBA web service

Now we are ready to create a CORBA web service using the Axis2 CORBA module. First of all we have to prepare Axis2 to work with CORBA module.

1. Make sure axis2-corba-{version}.jar is available in AXIS2_HOME/lib directory.

2. Download latest Apache Yoko binary distribution form http://cwiki.apache.org/YOKO/download.html. Extract the downloaded archive to a temporary directory and copy yoko-core-{version}.jar and yoko-spec-corba{version}.jar to AXIS2_HOME/lib directory. (Axis2 CORBA module can also work with other CORBA implementations. Refer 'Additional Configuration Details' section for more information.)

3. Add the following line to the <axisconfig> section of the axis2.xml file which is located in AXIS2_HOME/conf directory.
<deployer extension=".xml" directory="corba" class="org.apache.axis2.corba.deployer.CorbaDeployer"/>

4.Create a new directory named corba inside AXIS2_HOME/repository directory.

Now, your Axis2 server is ready to deploy CORBA web services. Copy calculator.idl file to the newly created corba directory and create a new file named calculator.xml as follows inside the same directory.
<service name="Calculator">
    <description>Calculator Service</description>
    <parameter name="idlFile">calculator.idl</parameter>
    <parameter name="interfaceName">example::calculator</parameter>
    <parameter name="namingServiceUrl">corbaloc::localhost:900/NameService</parameter>
    <parameter name="objectName">calculator</parameter>
</service>
Running the Example Start a console window and execute the following command to start the CORBA name service.
tnameserv -ORBInitialPort 900
Start an other console window and goto the directory where Server.java is located. Execute the following command to start the CORBA server.
java Server
Start the Axis2 server. The EPR of the new Calculator web service will be http://localhost:8080/axis2/services/Calculator. The WSDL is located at http://localhost:8080/axis2/services/Calculator?wsdl. Now you can create a web service client and use it to invoke methods on the CORBA server.

Additional Configuration details

The service definition file (eg. calculator.xml) supports the following parameters.
Parameter Name Description Required
idlFil Relative path to the IDL file Yes
orbClass Overrides the default orb class name. No
orbSingletonClass Overrides the default orb singleton class name. (Default: org.apache.yoko.orb.CORBA.ORB) No
namingServiceUrl URL of the CORBA naming service (Default: org.apache.yoko.orb.CORBA.ORBSingleton) No
iorFilePath Path to IOR file No
iorString IOR as a string No
objectName Name of the CORBA service which used in the naming service Required if namingServiceUrl is present interfaceName Full name of the IDL interface used for the web service. (use :: as the separator between module and interface names) Yes

Notes:

1. Axis2 CORBA module uses Apache Yoko as the default CORBA implementation. If you want to use a CORBA implementation other than Apache Yoko, override orbClass and orbSingletonClass properties.

2. To run the above tutorial without a naming service:
Use java Server /path/to/a/new/file to start the server. Remove namingServiceUrl and objectName properties from the calculator.xml file and add the following line to the same file.
<parameter name="iorFilePath">/path/to/a/new/file</parameter>