Strange error when calling into jruby1.2 from java using javax.scripting?


#1

I am trying to get jruby1.2 working with the new scripting api on JDK1.6
(JSR 223) but I have run into a strange error with the returned jruby
object not properly implementing a specified java interface. Can anyone
on the list help?

The error I get is an undefined method error as shown below about a
undefined method which is on an interface that the jruby object has been
asked to implement??? As can be shown further below, the jruby code
does implement the interface so it is a bit strange.

First the error that I get:

javax.script.ScriptException: org.jruby.exceptions.RaiseException:
undefined method `clear’ for #Java::JavaObject:0x2b1d8f11
   at
com.sun.script.jruby.JRubyScriptEngine.invokeImpl(JRubyScriptEngine.java:518)
   at
com.sun.script.jruby.JRubyScriptEngine.access$100(JRubyScriptEngine.java:88)
   at
com.sun.script.jruby.JRubyScriptEngine$1.invoke(JRubyScriptEngine.java:170)
   at $Proxy14.clear(Unknown Source)
   at
com.rv.testsupport.ServiceTestHarness.clear(ServiceTestHarness.java:198)

My jruby 1.2 script is as follows:
"
require ‘java’
module Example
 import java.util.Properties # type of config arg
 import com.rv.Service # implementing interface
 import com.rv.Store # type of store arg
 import com.rv.TaskCoordinator # type of coordinaterCallback arg
Â
 class RubyService
     include com.rv.Service
      Â
     def restore(store, config, coordinaterCallback)
       puts “Restore called”
     end
    Â
     def clear(config, coordinaterCallback)
       puts “Clear called”
     end
 end
end

return Example::RubyService.new
"

And the java script engine code extract:
"
ScriptEngine engine = scriptManager.getEngineByName(“jruby”)
Invocable invocable = (Invocable)engine;
ScriptContext context = engine.getContext();
BufferedReader scriptReader = …

Object rawResult=engine.eval(scriptReader, context);

com.rv.Service rubyService=invocable.getInterface(rawResult,
com.rv.Service.class);
rubyService.clear(null, null); # This line fails with the exception
shown above!!
"

Finally, here is the java interface with the clear method:
"
package com.rv;
public interface Service
{
   void restore(Store store, Properties config, TaskCoordinator
coordinaterCallback) throws CoreException, InterruptedException,
IOException;

   void clear(Properties config, TaskCoordinator tc) throws
CoreException, InterruptedException, IOException;
}
"

Any idea why this happens?

P.S: The code extracts here are just extracts from a large piece of SW.

  Trænger du til at se det store billede? Kelkoo giver dig gode 

tilbud på LCD TV! Se her http://dk.yahoo.com/r/pat/lcd