Class org.jcodings.specific.ASCIIEncoding is not Serializable

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 arr = new ArrayList();
for (Iterator iter = ((RubyArray) res).iterator();
iter.hasNext():wink: {
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

On 28 Dec, 2008, at 9:45 AM, Guillermo A. 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.

Bill K. 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

Hello G.s,

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