View Full Version : Hessian+CDI proxy

06-17-2010, 11:16 AM
Hi there,

I am trying to serialize and deserialize a CDI managed bean using Hessian:

@Inject MyBean sb;


ByteArrayOutputStream bos = new ByteArrayOutputStream();
Hessian2Output os = new Hessian2Output(bos);

ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
Hessian2Input is = new Hessian2Input(bis);
MyBean ser = (MyBean) is.readObject(null);

Upon deserialization , I get the following error:

WARNING: Hessian/Burlap: 'wargames.WarGames__ResinWebBean' is an unknown class in EnvironmentClassLoader[resin-context]:
java.lang.ClassNotFoundException: wargames.WarGames__ResinWebBean in EnvironmentClassLoader[resin-context]

What seems to be happening is that Resin created a proxy for my injected bean (because I have a CDI interceptor registered on it). But the Hessian deserialization code does not seem to be aware of this proxy, throwing the ClassCastException. I get the same exception if I use normal Java Serialization.

06-17-2010, 05:59 PM
Hmm. I've filed this as a bug. There's a small complication, though.

I'd assume the right behavior is to serialize the bean as the raw, underlying bean (which will take a bug fix to implement.)

The trick is that the deserialized bean will not be "live". It will be the underlying bean without and aspect behavior.

06-17-2010, 06:05 PM
For reference, here's the bug report:



06-18-2010, 04:01 AM
Thanks Scott, Emil

I think since the spec excludes the propagation of CDI contexts across VM's, having the underlying bean serialized instead of the proxy should be fine. I can always re-inject the interceptor on the other side at the expense of a bit of boiler plate code.

Just to help with that, is there a way that I can wrap an existing object instance into a proxy to get aspect behaviour? The CDI SPI's InjectionTarget interface does not provide a way to wrap an non-proxied bean into a proxy - it only allows you to create a new proxied bean *OR* inject into the underlying bean without wrapping it.

For interest, I think the way Weld does it is that it serializes the (javassist) proxy, so that upon deserialization you still get the aspect behaviour. I haven't tested it in a remote environment though - I'm pretty sure Weld's serialization support is to provide passivation capable beans rather than facilitate serialization in a client/server situation.