Results 1 to 3 of 3

Thread: JRuby with Spring DM

  1. #1
    Join Date
    Feb 2010
    Posts
    2

    Default JRuby with Spring DM

    Hi,

    I'm trying to run a JRuby script with Spring DM and run into problems.

    Java Base class
    Code:
    package org.codingkata.unit.api; 
    
    public abstract class BaseKataSolution { 
        abstract String reply(); 
    }
    JRuby Class
    Code:
    class MyKata 
      include org.codingkata.unit.api.BaseKataSolution 
    
      def reply 
        return "hello world" 
      end 
    end
    Spring Beans context
    Code:
    [...] 
       <osgi:service 
               ref="kataSolution" 
               interface="org.codingkata.unit.api.BaseKataSolution"/> 
       [...]
    So far so clear - the JRuby class inherits the 'BaseKataSolution' class. In Spring I configure this as the interface (cglib is present, in the java and groovy version everything works flawlessly).

    But when I try to run a test which loads the JRuby class, it results in:
    Exported service object does not implement the given interface: class org.codingkata.unit.MyKata is not assignable to interface org.codingkata.unit.api.BaseKataSolution.

    Then I tried to look at the classes in detail by using a decompiler:

    Decompiled Groovy version
    Code:
    public class MyKata extends BaseKataSolution
      implements GroovyObject 
    { 
      public MyKata() 
      { 
        MyKata this; 
        [...] 
      } 
    
      public String reply() 
      { 
        for (CallSite[] arrayOfCallSite = $getCallSiteArray(); ; return ((String)ScriptBytecodeAdapter.castToType("hello world", $get$$class$java$lang$String()))); 
      } 
      [...] 
    }
    Decompiled JRuby version
    Code:
    public class MyKata extends AbstractScript
    { 
      private final Class $class = Class.forName("org.codingkata.unit.MyKata"); 
    
      public MyKata() 
      { 
        [...] 
      } 
    
      @JRubyMethod(name="reply", frame=true, required=0, optional=0, rest=-1) 
      public static IRubyObject method__1$RUBY$reply(MyKata paramMyKata, ThreadContext paramThreadContext, IRubyObject paramIRubyObject, Block paramBlock) { Ruby localRuby = paramThreadContext.getRuntime(); IRubyObject localIRubyObject = localRuby.getNil(); setPosition(paramThreadContext, 5); return paramMyKata.getString1(localRuby); 
      } 
    
      [...] 
    }
    Obviously Groovy directly inherits the base class while JRuby does not. Bummer. I opened a discussion in the JRuby mailing list if this is the desired behavior.

    Still, I'm wondering if there is anything I can do to make it work with Spring DM - because I expect most of the JSR223 languages to act like JRuby.

    Any ideas?

    Cheers,
    stephanos

  2. #2
    Join Date
    Feb 2010
    Posts
    2

    Default

    Somebody in the JRuby board proposed a Proxy - but I can't think of how to combine this with Spring DM on the one side and a dynamic JSR 223 script on the other.

    Do you? Or is that not a good approach?

    Cheers,
    stephanos

  3. #3
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    You could avoid this problem by using a ServiceFactory which allows one to register a factory rather then the object directly.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •