I am using JRuby to act as EJB client.
The attached test case describes the problem I have:
http://pastie.org/563934
In essence, after opening the context, I have a problem getting the proper
type cast on the object I receive by RMI. For that, to my understanding, I
would need to call PortableRemoteObject.narrow(). The connection uses the
RMI network layer with its limitations.
For reference, same test case inline:
require 'test/unit'
### load Java
require 'java'
import java.util.Hashtable
import javax.naming.InitialContext
import javax.rmi.PortableRemoteObject
# load Java libraries
$CLASSPATH << File.join('lib') # custom.ServicesHome
$CLASSPATH << File.join('lib','jboss-javaee.jar')
$CLASSPATH << File.join('lib','oc4jclient.jar')
$CLASSPATH << File.join('lib','ojdl.jar')
class PortableRemoteObjectTest < Test::Unit::TestCase
def setup
env = {
'java.naming.factory.initial' =>
'com.evermind.server.rmi.RMIInitialContextFactory',
'java.naming.security.principal' => 'xxx',
'java.naming.security.credentials' => 'yyy',
'java.naming.provider.url' => 'rmi://localhost:8888/Services'
}
# you need to have a proper RMI server set up to test
ctx = InitialContext.new(Hashtable.new(env))
assert_not_nil ctx
connection = ctx.lookup("Services")
assert_not_nil connection
# type cast the correct object.
# this is where the problem is.
home = PortableRemoteObject.narrow(
# java.lang.Object,
Java.ruby_to_java(connection.java_object),
# java.lang.Class
Java.ruby_to_java(Java::custom.ServicesHome.class)
)
assert_not_nil home
# Idea here is to do equivalent to this:
#ServicesHome home = (ServicesHome)
PortableRemoteObject.narrow(ctx.lookup("Services"), ServicesHome.class);
end
end
--
-- mikael