aspose file tools*
The moose likes Web Services and the fly likes How best to deal with Interface Return Type for Web Service Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "How best to deal with Interface Return Type for Web Service Method" Watch "How best to deal with Interface Return Type for Web Service Method" New topic
Author

How best to deal with Interface Return Type for Web Service Method

Marty Kopka
Greenhorn

Joined: Jun 29, 2010
Posts: 1
Hi All,
i have the followinig situation. I would like to create a method as a web service:

Customer getCustomer(someType){....}

ie: getCustomer method, with a parameter that indicates some backend data source. The method returns a Customer object. However, depending on the datasource this method uses (which is dependent on the type passed in, ie FooDB, BarDB etc) then i return either a:

FooCustomer extends AbstractCustomer implements Customer
BarCustomer extends AbstractCustomer implements Customer

Now this fails because JAXB cant handle interfaces because when sending XML over the wire it needs a concrete representation (as far as i understand).

So how should i deal with this?

Do I need to create a differnet method for each datasource (foo DB, bar DB), ie:
FooCustomer getFooCustomer()
BarCustomer getBarCustomer()

or do i continue calling getCustomer but somehow indicate in the WSDL that I have an AbstractCustomer object and some other bits from FooCusotmer or BarCustomer or ....

kinda stumpeed here? I wouldve thought itd be handy to be able to do this (ie: call one getCustomer() method and get back Customer objects representing nay type of customer ... in some way...but cant see how to achieve this.

Any pointers would be greatly appreciated

cheers
Marty
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
I have done something similar to what you want to do and I used the following way:
- Declare an XML schema specifying the Customer complex type.
- Declare (either in a new XML schema or in the same XML schema) the FooCustomer complex type that extends the Customer complex type.
- Declare (either in a new XML schema or in the same XML schema) the BarCustomer complex type that extends the Customer complex type.
- Use the JAXB schema compiler XJC to create Java classes representing Customer, FooCustomer and BarCustomer.
- Use the generated classes in your code-first web service.

An alternative is to do WDSL-first development, in which case you use the XML schema(s) in the WSDL you write.
Ask if you need more information!
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How best to deal with Interface Return Type for Web Service Method
 
Similar Threads
How to return nicely?
Vector Search
Hibernate AND Axis2 problem
db method return type: object array or Vector?
Accessing the GET parameters of a URL in a RESTful service using Apache CXF REST HTTP binding