You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by prud3nt <pr...@hotmail.com> on 2008/03/18 03:14:28 UTC

[jira] CXF service returning interface implemented by multiple objects

Hi,

I have been trying to get this working for a couple of days to no avail. I
have a service that returns an interface Widget, this interface has multiple
implementations WidgetType1 and WidgetType2. I have seen some of the
examples which deal with interfaces that use the XmlJavaTypeAdapter, but am
not sure if I am using it properly since i do not just have one
implementation of the interface (UserImpl w/ User). I get null back right
now. Any examples would be greatly appreciated. Thanks.

Attached below is all the code I am using:

http://www.nabble.com/file/p16112384/WidgetService.java WidgetService.java 
http://www.nabble.com/file/p16112384/Widget.java Widget.java 
http://www.nabble.com/file/p16112384/WidgetType1.java WidgetType1.java 
http://www.nabble.com/file/p16112384/WidgetType2.java WidgetType2.java 
http://www.nabble.com/file/p16112384/AnyTypeAdapter.java AnyTypeAdapter.java 
http://www.nabble.com/file/p16112384/Server.java Server.java 
http://www.nabble.com/file/p16112384/WidgetServiceImpl.java
WidgetServiceImpl.java 
http://www.nabble.com/file/p16112384/Client.java Client.java 
-- 
View this message in context: http://www.nabble.com/CXF-service-returning-interface-implemented-by-multiple-objects-tp16112384p16112384.html
Sent from the cxf-issues mailing list archive at Nabble.com.


Re: CXF service returning interface implemented by multiple objects

Posted by Daniel Kulp <dk...@apache.org>.
Pulling this off the cxf-issues list which is normally our JIRA 
notification list.....  Almost missed it.

The thing to remember is that the interface (Widget) has absolutely no 
bearing on the hierachy represented in the schema/wsdl.   You need to 
define the heirachy only with concrete types.   Thus, Widget1 and 
Widget2 will need to share a common parent. 

Alternatively, you would need to create a new bean to represent 
a "choice" of Widget1 or Widget2.  You'd need to check the jaxb spec to 
see how choices are modeled.  I don't really remember.


Next    
@ResponseWrapper(className="hw.common.Widget",   
targetNamespace="http://server.hw.demo/")
    WidgetWrapper getWidget(int id);:

I would get rid of the ResponseWrapper annotation, get rid of 
WidgetWrapper, and just return the widget:  (although this will ONLY 
work with the latest 2.1 snapshots)

@XmlJavaTypeAdapter(AnyTypeAdapter.class)
Widget getWidget(int id);


The AnyTypeAdapter would then either map the Widget interface to the 
concrete Widget1/2 base type or to the new "choice" object that you 
would need to create.


Dan



On Monday 17 March 2008, prud3nt wrote:
> Hi,
>
> I have been trying to get this working for a couple of days to no
> avail. I have a service that returns an interface Widget, this
> interface has multiple implementations WidgetType1 and WidgetType2. I
> have seen some of the examples which deal with interfaces that use the
> XmlJavaTypeAdapter, but am not sure if I am using it properly since i
> do not just have one implementation of the interface (UserImpl w/
> User). I get null back right now. Any examples would be greatly
> appreciated. Thanks.
>
> Attached below is all the code I am using:
>
> http://www.nabble.com/file/p16112384/WidgetService.java
> WidgetService.java http://www.nabble.com/file/p16112384/Widget.java
> Widget.java
> http://www.nabble.com/file/p16112384/WidgetType1.java WidgetType1.java
> http://www.nabble.com/file/p16112384/WidgetType2.java WidgetType2.java
> http://www.nabble.com/file/p16112384/AnyTypeAdapter.java
> AnyTypeAdapter.java http://www.nabble.com/file/p16112384/Server.java
> Server.java
> http://www.nabble.com/file/p16112384/WidgetServiceImpl.java
> WidgetServiceImpl.java
> http://www.nabble.com/file/p16112384/Client.java Client.java



-- 
J. Daniel Kulp
Principal Engineer, IONA
dkulp@apache.org
http://www.dankulp.com/blog

Re: [jira] CXF service returning interface implemented by multiple objects

Posted by prud3nt <pr...@hotmail.com>.
Forgot this file:

http://www.nabble.com/file/p16112413/WidgetWrapper.java WidgetWrapper.java 
-- 
View this message in context: http://www.nabble.com/CXF-service-returning-interface-implemented-by-multiple-objects-tp16112384p16112413.html
Sent from the cxf-issues mailing list archive at Nabble.com.