You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@aries.apache.org by Harald Wellmann <ha...@gmx.de> on 2011/07/03 14:17:32 UTC

Proxy Serialization

Aries Blueprint proxies are not serializable. The problem is, you'd 
expect them to be when the proxied class or interface is serializable.

After all, the proxy should be transparent to the client, and if the 
proxied class declares itself to be serializable, then a 
non-serializable proxy breaks the API contract of its target.

I ran into this problem when using Wicket with Aries - Wicket pages and 
components get serialized all the time...

Regards,
Harald



Re: Proxy Serialization

Posted by Harald Wellmann <ha...@gmx.de>.
Am 04.07.2011 10:59, schrieb Timothy Ward:
> Yes,
>
> This is a slightly unpleasant issue which affects all our proxy
> instances going back to 0.1 and before. The problem we have is that we
> can't unwrap the proxy on its way into the ObjectOutputStream (there's
> nothing we can hook into).


Hmm, what about writeReplace() and readResolve()?

Wicket has a generic solution for this in the wicket-ioc component, see

http://svn.apache.org/viewvc/wicket/releases/wicket-1.5-RC5.1/wicket-ioc/src/main/java/org/apache/wicket/proxy/LazyInitProxyFactory.java?view=markup

Integration components like wicket-spring, wicket-cdi or wicket-osgi
which have to deal with different flavours of injections
just need to provide a serializable IProxyTargetLocator which knows how 
to look up the real (possibly not serializable) target object.

I've just implemented this for wicket-osgi in

https://github.com/wicketstuff/core/blob/master/jdk-1.5-parent/wicket-osgi-parent/wicket-osgi/src/main/java/org/wicketstuff/osgi/inject/impl/OsgiServiceProxyTargetLocator.java

This means, the Blueprint proxy is wrapped in another Wicket proxy, 
which wouldn't be necessary if the Blueprint proxy already used a 
similar mechanism to make itself serializable.

The current solution is just a first shot, I'm planning to add support 
for service properties to handle the case of multiple service candidates 
for the same interface.

Would this approach also work for Blueprint proxies?

Regards,
Harald

RE: Proxy Serialization

Posted by Timothy Ward <ti...@apache.org>.
Yes,

This is a slightly unpleasant issue which affects all our proxy instances going back to 0.1 and before. The problem we have is that we can't unwrap the proxy on its way into the ObjectOutputStream (there's nothing we can hook into). As a result you end up with something that either breaks immediately, or is just plain wrong when it gets deserialized.

The only thought I've managed so far is to put in a defaultWriteObject that throws an exception for all our proxys. That doesn't really solve the issue though.

If anyone has any bright ideas I would love to hear them!

Tim

> Date: Sun, 3 Jul 2011 14:17:32 +0200
> From: harald.wellmann@gmx.de
> To: user@aries.apache.org
> Subject: Proxy Serialization
> 
> Aries Blueprint proxies are not serializable. The problem is, you'd 
> expect them to be when the proxied class or interface is serializable.
> 
> After all, the proxy should be transparent to the client, and if the 
> proxied class declares itself to be serializable, then a 
> non-serializable proxy breaks the API contract of its target.
> 
> I ran into this problem when using Wicket with Aries - Wicket pages and 
> components get serialized all the time...
> 
> Regards,
> Harald
> 
>