On 9/27/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Hi, > > I read some of the mails regarding usage of JAXB in > Tuscany. My question is how do I use/exchange custom > data types such as Purchase Order/ Customer (have > multiple fields) using web services binding in SCA. > > Thanks, > SM. > > > > > ____________________________________________________________________________________ > Check out the hottest 2008 models today at Yahoo! Autos. > http://autos.yahoo.com/new_cars.html > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > Hi, typically you would start with a schema that is used in the WSDL to describe the custom data types in each operations input and output messages. Using JAXB tools you would then generate the Jaxb java objects representing these custom types and use them on your java service interfaces. These service interfaces are described to sca in the ".composite" file and SCA will take it from there ensuring that the Jaxb objects are converted to and from XML in order that the messages flow over the web services binding.
I just took a look to see if we use Jaxb in any of our samples and it would seem that we don't (do you fancy creating a sample?). We do have an itest that uses Jaxb (itests/databindings/jaxbgen) although this is a little complicated as the test is actually created automatically from templates. This is basically what happens.... Some XSD describing a custom type (a person in this case rather than a purchase order) <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://apache.org/tuscany/sca/itest/databinding/types"> <xsd:complexType name="PersonType"> <xsd:sequence> <xsd:element name="firstName" type="xsd:string" /> <xsd:element name="lastName" type="xsd:string" /> <xsd:element name="greeting" type="xsd:string" /> </xsd:sequence> </xsd:complexType> </xsd:schema> A WSDL that defines messages that use this custom type ... <wsdl:definitions targetNamespace=" http://apache.org/tuscany/sca/itest/databinding/services" ...> <wsdl:types> <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" <xsd:import namespace=" http://apache.org/tuscany/sca/itest/databinding/types" schemaLocation="../xsd/Person.xsd" /> <element name="greetPersonType"> <complexType> <sequence> <element name="parm" type="p:PersonType" /> </sequence> </complexType> </element> </xsd:schema> </wsdl:types> <wsdl:message name="PersonTypeRequest"> <wsdl:part element="tns:greetPersonType" name="parameters" /> </wsdl:message> <wsdl:message name="PersonTypeResponse"> <wsdl:part element="tns:greetPersonType" name="parameters" /> </wsdl:message> <wsdl:portType name="GreeterPortType"> <wsdl:operation name="greetPersonType"> <wsdl:input message="tns:PersonTypeRequest" name="PersonTypeRequestMsg" /> <wsdl:output message="tns:PersonTypeResponse" name="PersonTypeResponseMsg" /> </wsdl:operation> etc... The maven pom plugin directive that builds the jaxb java objects from the types in this WSDL <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jaxws-maven-plugin</artifactId> <executions> <execution> <phase>process-resources</phase> <goals> <goal>wsimport</goal> </goals> </execution> </executions> <configuration> <packageName> org.apache.tuscany.sca.itest.jaxbdatabinding.generated</packageName> <wsdlDirectory>${project.build.directory }/classes/wsdl</wsdlDirectory> <wsdlFiles> <wsdlFile>Greeter.wsdl</wsdlFile> </wsdlFiles> <sourceDestDir>${project.build.directory }/jaxws-source</sourceDestDir> <verbose>true</verbose> </configuration> </plugin> The resulting Jaxb PersonType @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "PersonType", namespace = " http://apache.org/tuscany/sca/itest/databinding/types", propOrder = { "firstName", "lastName", "greeting" }) public class PersonType { @XmlElement(required = true) protected String firstName; @XmlElement(required = true) protected String lastName; @XmlElement(required = true) protected String greeting; /** * Gets the value of the firstName property. * * @return * possible object is * [EMAIL PROTECTED] String } * */ public String getFirstName() { return firstName; } /** * Sets the value of the firstName property. * * @param value * allowed object is * [EMAIL PROTECTED] String } * */ public void setFirstName(String value) { this.firstName = value; } /** * Gets the value of the lastName property. * * @return * possible object is * [EMAIL PROTECTED] String } * */ public String getLastName() { return lastName; } /** * Sets the value of the lastName property. * * @param value * allowed object is * [EMAIL PROTECTED] String } * */ public void setLastName(String value) { this.lastName = value; } /** * Gets the value of the greeting property. * * @return * possible object is * [EMAIL PROTECTED] String } * */ public String getGreeting() { return greeting; } /** * Sets the value of the greeting property. * * @param value * allowed object is * [EMAIL PROTECTED] String } * */ public void setGreeting(String value) { this.greeting = value; } } Using this object in a service interface... @Remotable public interface GreeterService { /** * Take the provided data object, change it slightly and return it * * @param param the data object to be changed and returned * @return the change data object */ PersonType greetPersonType(PersonType param); Note the @Remotable SCA annotation which tells SCA that this service will be available over remote bindings such as binding.ws The .composite file that describes the component service and how it is assembled with other services... <composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:wsdli="http://www.w3.org/2006/01/wsdl-instance" name="JAXBGreeterService"> <!-- Client --> <component name="WSGreeterServiceClient"> <implementation.java class=" org.apache.tuscany.sca.itest.jaxbdatabinding.GreeterServiceClientImpl" /> </component> <reference name="JAXBGreeterServiceWSReference" promote="WSGreeterServiceClient/greeterService"> <interface.wsdl interface=" http://apache.org/tuscany/sca/itest/databinding/services#wsdl.interface(GreeterPortType) "/> <binding.ws wsdlElement=" http://apache.org/tuscany/sca/itest/databinding/services#wsdl.port(GreeterService/GreeterPort) "/> </reference> <!-- The greeter service --> <service name="JAXBGreeterService" promote="JAXBGreeterServiceComponent"> <interface.wsdl interface=" http://apache.org/tuscany/sca/itest/databinding/services#wsdl.interface(GreeterPortType) "/> <binding.ws wsdlElement=" http://apache.org/tuscany/sca/itest/databinding/services#wsdl.port(GreeterService/GreeterPort) "/> </service> <!-- Components used to implement the services --> <component name="JAXBGreeterServiceComponent"> <implementation.java class=" org.apache.tuscany.sca.itest.jaxbdatabinding.GreeterServiceImpl" /> </component> </composite> Note that in this case we expose the component service (JAXBGreeterService) and we reference it (JAXBGreeterServiceWSReference) in the same .composite file. So in this case Tuscany both expose the JAXBGreeterService web service endpoint and call it using the reference. This all happens when the WSGreeterServiceClient itself is called. All of these files come from the jaxb databindings itest ( http://svn.apache.org/repos/asf/incubator/tuscany/java/sca/itest/databindings/jaxbgen/) but to see them you will have to check out the code and run the test first. As they are not generated until the test is run. Hope this helps Simon
