Hi Ahmed
Sorry for a late reply - to be honest I just don't know the answer may be
others can comment more.
I didn't know DOSGi can handle requests like
IPersistable ip = requestService.syncRequest();
which return interface instances (it probably works with the help WS-Addressing
under the hood ?)
But even it works, I don't think you can do
IComponent component = (IComponent)ip;
this is really out of DOSGI's control, because it's really controlling the publication/lookups of IRequestService only. IPersistable
instances are CXF proxies as far as I know...If so then it's down to CXF to ensure a given proxy implements IPersistable &
IComponent and it can't do it as far as I know - unless Dan knows how it can be done
cheers, Sergey
----- Original Message -----
From: <[email protected]>
To: <[email protected]>
Sent: Thursday, July 23, 2009 4:35 PM
Subject: [dOSGI] Proxies and Casting
Hi
I have a blocking problem dealing with downcasting proxied types under
dOSGI, and of course any help from this lovely community is very
appreciated.
//given an interface
interface IComponent extends IPersistable
//its implementation
class Component implements IComponent
//service contract
interface IRequestService{
IPersistable syncRequest();
}
// its implementation
class RequestService implements IRequestService{
IPersistable syncRequest(){
//in this arbitrary case return IComponent object
return new Component();
}
An exception such as: "java.lang.ClassCastException: $Proxy39 cannot be
cast to ... "
is thrown when the remote consumer is trying to down cast from
IPersistable to IComponent via proxy:
class SomeConsumer{
IRequestService requestService= ..;//some remote proxy to IRequestService
IComponent c = ( IComponent) requestService.syncRequest();
}
I found you can config your spring beans to be jdk/cglib proxied. I tried
adding some aop elements "like":
<aop:config proxy-target-class="true" /> to my spring/context.xml hoping
for some springful magic :).
Back to earth, the problem is that neither our objects (Component in this
case) were intended to be managed by Spring, nor are we
intercepting/advising in our osgi app, in first place.
Is going for some aop stuff (somehow overkill!) for such issues the right
solution? Please advise!
Kind regards
Ahmed Aadel
remainsoftware.com