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); }; };
idlj -fall calculator.idl
| | calculator.idl | \---example numbersHelper.java numbersHolder.java numbers.java calculatorPOA.java _calculatorStub.java calculatorHolder.java calculatorHelper.java calculator.java calculatorOperations.java
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; } }
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(); } }
javac *.java
<deployer extension=".xml" directory="corba" class="org.apache.axis2.corba.deployer.CorbaDeployer"/>
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>
tnameserv -ORBInitialPort 900
java Server
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.
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 |
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>