i have the followinig situation. I would like to create a method as a web service:
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:
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:
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.
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!