Forum: JRuby Class org.jcodings.specific.ASCIIEncoding is not Serializable

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3a10ab24a98ffb9884eebb4965dbc955?d=identicon&s=25 Guillermo Acilu (Guest)
on 2008-12-28 15:45
(Received via mailing list)
Hello guys,

I am still fighting trying to call an EJB server. But now I started
with my own code, not just copying the JRuby on Rails Book examples.

I have JRuby code that calls the EJB. The EJB is not pure java, it
runs a JRuby class. The call is done perfectly until it reaches the
"return" line in the EJB. I have the following error:

BAD_PARAM) Class org.jcodings.specific.ASCIIEncoding is not
Serializable" org.omg.CORBA.BAD_PARAM: vmcid: OMG minor code: 6
completed: Maybe at
com
.sun
.corba
.ee
.impl
.logging.OMGSystemException.notSerializable(OMGSystemException.java:
990) at
com
.sun
.corba
.ee
.impl
.logging.OMGSystemException.notSerializable(OMGSystemException.java:1005
...
...
etc


The JRuby code returns an array to the EJB, but when I try to return
from the EJB to the caller JRuby script, I get the error. If I return
just an string, it works fine.

The code for the return is the following (the return in bold):

public Object invoke(String methodName, String argument1, String
argument2) {
    try {
      IRubyObject m, a1, a2;
      if (methodName != null) {
        m = engine.newString(methodName);
      } else {
        m = engine.getNil();
      }
      if (argument1 != null) {
        a1 = engine.newString(argument1);
      } else {
        a1 = engine.getNil();
      }
      if (argument2 != null) {
        a2 = engine.newString(argument2);
      } else {
        a2 = engine.getNil();
      }
      IRubyObject inst =
engineClass.callMethod(engine.getCurrentContext(), "new", new
IRubyObject[] { a2, m });
      IRubyObject res =
inst.callMethod(engine.getCurrentContext(),"invoke", a1);
      if (res instanceof RubyString) {
        return res.toString();
      } else if (res.isNil()) {
        return null;
      } else if (res instanceof RubyArray) {
        List<RubyArray> arr = new ArrayList<RubyArray>();
        for (Iterator<RubyArray> iter = ((RubyArray) res).iterator();
iter.hasNext();) {
          arr.add(iter.next());
        }
        return arr; "This line triggers the exception"
      }
      return res.toString();
    } catch (RaiseException re) {
      RubyException rr = re.getException();
      re.printStackTrace();
      if (rr != null) {
        System.err.println("RubyException: " + rr.inspect());
        re.printStackTrace();
      } else {
        out.println("RaiseException: " + re.toString());
      }
      return null;
    }

Any ideas?

Thanks,

GA
Ff168162d53e22788d576582b3527e97?d=identicon&s=25 Bill Kocik (Guest)
on 2008-12-28 16:42
(Received via mailing list)
On  28 Dec, 2008, at 9:45 AM, Guillermo Acilu wrote:

> com
> .sun
> .corba
> .ee
> .impl
> .logging.OMGSystemException.notSerializable(OMGSystemException.java:
> 1005

>         }
>         return arr; "This line triggers the exception"

Forgive me if I'm only pointing out the obvious here. "Not
serializable" errors are a common one when dealing with EJBs. Anything
passed to, or returned from an EJB must implement Serializable, else
it cannot be marshaled for wire travel. JRuby is using the
ASCIIEncoding class as part of RubyString, and this class is not
serializable - hence the error you're seeing when you try to return a
List full of them.

I don't know what to tell you to do about it, I can only tell you why
it's happening. Maybe that'll be helpful somehow anyways.
Ede2aa10c6462f1d825143879be59e38?d=identicon&s=25 Charles Oliver Nutter (Guest)
on 2008-12-28 22:54
(Received via mailing list)
Bill Kocik wrote:
> Forgive me if I'm only pointing out the obvious here. "Not serializable"
> errors are a common one when dealing with EJBs. Anything passed to, or
> returned from an EJB must implement Serializable, else it cannot be
> marshaled for wire travel. JRuby is using the ASCIIEncoding class as
> part of RubyString, and this class is not serializable - hence the error
> you're seeing when you try to return a List full of them.

I'm pretty sure none of the core Ruby types are serializable at all in
JRuby right now. The problem is that in order to support multiple Rails
instances in the same process we've traditionally had to associate all
Ruby objects with a JRuby instance they came from, so they have access
to other classes, constants, globals, etc. So when deserializing we
would need a way to locate a JRuby instance to associate it with.

If you really need to serialize this data across, your best bet may be
to pull it apart into a Java structure that is serializable and send
that across instead.

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
3a10ab24a98ffb9884eebb4965dbc955?d=identicon&s=25 Guillermo Acilu (Guest)
on 2008-12-29 14:05
(Received via mailing list)
Hello Guys,

thanks for your answers. I have resolved the problem changing the
RubyArray type into a Java Array. Then I am returning the Java Array
to the JRuby caller and just works fine.

Thanks,

GA


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
This topic is locked and can not be replied to.