Tips and tricks for using JiBX
start > axis2-jibx > example > library-service

library-service

Created by dsosnoski. Last edited by dsosnoski, one year and 307 days ago. Viewed 2,666 times. #3
The library service example defines the following operations:
  • get book information based on ISBN
  • get book information by type of book
  • get information about types of books
  • add a book
The service code starts with a built-in set of books and maintains the library information in memory, so that all changes are lost each time you restart the server. The supplied test client tests each of these operations, including the asynchronous version of one operation. It deliberately triggers a Fault by adding a duplicate book (but note that if you run the test client repeatedly without restarting the server you'll get the Fault on every attempt to add a book, since after the first time the books will still be present in the service code's in-memory tables).

Here's the actual API generated by WSDL2Java when using JiBX data binding for this service (leaving out the asynchronous methods, and formatted for readability):

public interface JibxLibrary
{

/** * Auto generated method signature * * @param type feature to be added to the Book attribute * @param isbn feature to be added to the Book attribute * @param author feature to be added to the Book attribute * @param title feature to be added to the Book attribute * @exception java.rmi.RemoteException xxx * @exception org.apache.axis2.jibx.library.AddDuplicateFaultException xxx */ public void addBook( java.lang.String type, java.lang.String isbn, java.lang.String[] author, java.lang.String title) throws java.rmi.RemoteException

, org.apache.axis2.jibx.library.AddDuplicateFaultException; /** * Auto generated method signature * * @param isbn xxx * @return book value * @exception java.rmi.RemoteException xxx */ public com.sosnoski.ws.library.jibx.Book getBook( java.lang.String isbn) throws java.rmi.RemoteException ;

/** * Auto generated method signature * * @param type xxx * @return booksByType value * @exception java.rmi.RemoteException xxx */ public com.sosnoski.ws.library.jibx.Book[] getBooksByType( java.lang.String type) throws java.rmi.RemoteException ;

/** * Auto generated method signature * * @return types value * @exception java.rmi.RemoteException xxx */ public com.sosnoski.ws.library.jibx.Type[] getTypes( ) throws java.rmi.RemoteException ; }

The generated JavaDocs are not exactly quality documentation, but the actual API is very clean and direct. Try generating code for the same WSDL using ADB or XMLBeans binding and see how it compares! Here's the WSDL:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://ws.sosnoski.com/library/wsdl"
    xmlns:wns="http://ws.sosnoski.com/library/wsdl"
    xmlns:tns="http://ws.sosnoski.com/library/types"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/">
  <wsdl:types>

<schema elementFormDefault="qualified" targetNamespace="http://ws.sosnoski.com/library/wsdl" xmlns="http://www.w3.org/2001/XMLSchema">

<import namespace="http://ws.sosnoski.com/library/types"/>

<element name="getBook"> <complexType> <sequence> <element name="isbn" type="string"/> </sequence> </complexType> </element>

<element name="getBookResponse"> <complexType> <sequence> <element name="getBookReturn" minOccurs="0" type="tns:BookInformation"/> </sequence> </complexType> </element>

<element name="getBooksByType"> <complexType> <sequence> <element name="type" type="string"/> </sequence> </complexType> </element>

<element name="getBooksByTypeResponse"> <complexType> <sequence> <element name="getBooksByTypeReturn" minOccurs="0" maxOccurs="unbounded" type="tns:BookInformation"/> </sequence> </complexType> </element>

<element name="getTypes"> <complexType> <sequence/> </complexType> </element>

<element name="getTypesResponse"> <complexType> <sequence> <element name="getTypesReturn" maxOccurs="unbounded" type="tns:TypeInformation"/> </sequence> </complexType> </element>

<element name="addBook"> <complexType> <sequence> <element name="type" type="string"/> <element name="isbn" type="string"/> <element name="author" minOccurs="0" maxOccurs="unbounded" type="string"/> <element name="title" type="string"/> </sequence> </complexType> </element>

<element name="addBookResponse"> <complexType> <sequence/> </complexType> </element>

<element name="addDuplicate"> <complexType> <sequence> <element name="book" type="tns:BookInformation"/> </sequence> </complexType> </element>

</schema>

<schema elementFormDefault="qualified" targetNamespace="http://ws.sosnoski.com/library/types" xmlns="http://www.w3.org/2001/XMLSchema">

<complexType name="BookInformation"> <sequence> <element name="author" minOccurs="0" maxOccurs="unbounded" type="string"/> <element name="title" type="string"/> </sequence> <attribute name="type" use="required" type="string"/> <attribute name="isbn" use="required" type="string"/> </complexType>

<complexType name="TypeInformation"> <simpleContent> <extension base="string"> <attribute name="count" use="required" type="int"/> <attribute name="name" use="required" type="string"/> </extension> </simpleContent> </complexType>

</schema>

</wsdl:types>

<wsdl:message name="getBookRequest"> <wsdl:part element="wns:getBook" name="parameters"/> </wsdl:message>

<wsdl:message name="getBookResponse"> <wsdl:part element="wns:getBookResponse" name="parameters"/> </wsdl:message>

<wsdl:message name="getBooksByTypeRequest"> <wsdl:part element="wns:getBooksByType" name="parameters"/> </wsdl:message>

<wsdl:message name="getBooksByTypeResponse"> <wsdl:part element="wns:getBooksByTypeResponse" name="parameters"/> </wsdl:message>

<wsdl:message name="getTypesRequest"> <wsdl:part element="wns:getTypes" name="parameters"/> </wsdl:message>

<wsdl:message name="getTypesResponse"> <wsdl:part element="wns:getTypesResponse" name="parameters"/> </wsdl:message>

<wsdl:message name="addBookRequest"> <wsdl:part element="wns:addBook" name="parameters"/> </wsdl:message>

<wsdl:message name="addBookResponse"> <wsdl:part element="wns:addBookResponse" name="parameters"/> </wsdl:message>

<wsdl:message name="addDuplicateFault"> <wsdl:part element="wns:addDuplicate" name="fault"/> </wsdl:message>

<wsdl:portType name="Library">

<wsdl:operation name="getBook"> <wsdl:input message="wns:getBookRequest" name="getBookRequest"/> <wsdl:output message="wns:getBookResponse" name="getBookResponse"/> </wsdl:operation>

<wsdl:operation name="getBooksByType"> <wsdl:input message="wns:getBooksByTypeRequest" name="getBooksByTypeRequest"/> <wsdl:output message="wns:getBooksByTypeResponse" name="getBooksByTypeResponse"/> </wsdl:operation>

<wsdl:operation name="getTypes"> <wsdl:input message="wns:getTypesRequest" name="getTypesRequest"/> <wsdl:output message="wns:getTypesResponse" name="getTypesResponse"/> </wsdl:operation>

<wsdl:operation name="addBook"> <wsdl:input message="wns:addBookRequest" name="addBookRequest"/> <wsdl:output message="wns:addBookResponse" name="addBookResponse"/> <wsdl:fault message="wns:addDuplicateFault" name="addDuplicateFault"/> </wsdl:operation>

</wsdl:portType>

<wsdl:binding name="LibrarySoapBinding" type="wns:Library">

<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

<wsdl:operation name="getBook">

<wsdlsoap:operation soapAction=""/>

<wsdl:input name="getBookRequest"> <wsdlsoap:body use="literal"/> </wsdl:input>

<wsdl:output name="getBookResponse"> <wsdlsoap:body use="literal"/> </wsdl:output>

</wsdl:operation>

<wsdl:operation name="getBooksByType">

<wsdlsoap:operation soapAction=""/>

<wsdl:input name="getBooksByTypeRequest"> <wsdlsoap:body use="literal"/> </wsdl:input>

<wsdl:output name="getBooksByTypeResponse"> <wsdlsoap:body use="literal"/> </wsdl:output>

</wsdl:operation>

<wsdl:operation name="getTypes">

<wsdlsoap:operation soapAction=""/>

<wsdl:input name="getTypesRequest"> <wsdlsoap:body use="literal"/> </wsdl:input>

<wsdl:output name="getTypesResponse"> <wsdlsoap:body use="literal"/> </wsdl:output>

</wsdl:operation>

<wsdl:operation name="addBook">

<wsdlsoap:operation soapAction=""/>

<wsdl:input name="addBookRequest"> <wsdlsoap:body use="literal"/> </wsdl:input>

<wsdl:output name="addBookResponse"> <wsdlsoap:body use="literal"/> </wsdl:output>

<wsdl:fault name="addDuplicateFault"> <wsdlsoap:fault name="addDuplicateFault" use="literal"/> </wsdl:fault>

</wsdl:operation>

</wsdl:binding>

<wsdl:service name="jibx-library">

<wsdl:port binding="wns:LibrarySoapBinding" name="library"> <wsdlsoap:address location="http://localhost:8080/axis2/services/jibx-library"/> </wsdl:port>

</wsdl:service>

</wsdl:definitions>

no comments
snipsnap.org | Copyright 2000-2002 Matthias L. Jugel and Stephan J. Schmidt