A basic JRuby CORBA client

Posted by dstanley on June 13, 2007

JRuby 1.0 was released last Saturday so I had a chance to take it for

a quick testdrive today.

In the example below I used Orbix java 6.3, so I added Orbix’s corba-asp.jar and a jar containing the

helper classes for my client to the java classpath. Then it’s just a matter of calling ‘jruby

corba_client.rb’. It all pretty much worked out of the box.



require 'java'

include_class 'java.lang.System'
include_class 'java.util.Properties'
include_class 'org.omg.CORBA.ORB'
include_class 'simple_persistent.Simple.SimpleObject'
include_class 'simple_persistent.Simple.SimpleObjectHelper'

props = System.getProperties
props.put("org.omg.CORBA.ORBClass", "com.iona.corba.art.artimpl.ORBImpl")
props.put("org.omg.CORBA.ORBSingletonClass", "com.iona.corba.art.artimpl.ORBSingleton")


def import_object(orb, filename)

  ior = ''
  f = File.open(filename, "r")
  f.each_line do |line|
    ior += line
  end

  puts "Have IOR: " + ior

  orb.string_to_object(ior);
end

puts "Initializing ORB"

# Create a non null args array
args = java.lang.String[1].new
args[0]=""

orb = ORB.init(args, props)

objref = import_object(orb, "server.ior");

simple = SimpleObjectHelper.narrow(objref)

puts "Invoking call_me"
simple.call_me
puts "Done!"

It took a bit of digging to figure out how to create a java array in Ruby. The JRuby Cookbook was helpful there.

JRuby opens up a whole new set of possibilities in terms of using Ruby scripting (or Ruby on Rails for that matter) to interface with legacy backend enterprise systems.