Example ApplicationThe example application included with JibxSoap runs SOAP queries against an in-memory database on the server to retrieve information about moderate to large earthquakes recorded around the world during a particular time span. The client generates a pseudo-random sequence of queries based on command line arguments, sending each query to the server which then responds with the set of matching quakes. Here's the web.xml file for the quake service, defining the JibxSoap servlet, and service definition path: <web-app> <servlet> <servlet-name>soap_servlet</servlet-name> <servlet-class>org.jibx.soap.server.SOAPServlet</servlet-class> <init-param> <param-name>quake-service</param-name> <param-value>quake-service.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>soap_servlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app> Here's the quake-service.xml service definition file referenced by the web.xml: <service name="quake"> <schema>SeismicSchema.xsd</schema> <wsdl-uri>http://seismic.sosnoski.com/wsdl</wsdl-uri> <handler-class>com.sosnoski.seismic.jibxsoap.QuakeBase</handler-class> <operation method="process"/> </service> These files configure a single web service at the access path http://server:port/webapp/quake-service, where server:port is the name and port number for the servlet engine (such as localhost:8080 for the standard Tomcat configuration) and webapp is the name of the web application (normally the name of the .war file deployed to the server). As long as a schema definition and WSDL URI are supplied by the service definition file, the JibxSoap servlet supports dynamic WSDL generation. Here's the WSDL returned by a browser query to http://localhost:8080/JibxSoapExample/quake-service?WSDL when the example is deployed as JibxSoapExample.war to a local Tomcat installation (slightly reformatted for line length): <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://seismic.sosnoski.com/wsdl" xmlns:wns="http://seismic.sosnoski.com/wsdl" xmlns:tns="http://www.sosnoski.com/quakes"> <wsdl:types> <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.sosnoski.com/quakes" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://www.sosnoski.com/quakes"> <element name="query"> <complexType> <sequence> <element minOccurs="0" name="min-date" type="xsd:dateTime"/> <element minOccurs="0" name="max-date" type="xsd:dateTime"/> <element minOccurs="0" name="min-long" type="xsd:float"/> <element minOccurs="0" name="max-long" type="xsd:float"/> <element minOccurs="0" name="min-lat" type="xsd:float"/> <element minOccurs="0" name="max-lat" type="xsd:float"/> <element minOccurs="0" name="min-mag" type="xsd:float"/> <element minOccurs="0" name="max-mag" type="xsd:float"/> <element minOccurs="0" name="min-depth" type="xsd:float"/> <element minOccurs="0" name="max-depth" type="xsd:float"/> </sequence> </complexType> </element> <complexType name="Region"> <simpleContent> <extension base="xsd:string"> <attribute name="ident" type="xsd:ID"/> <attribute name="index" type="xsd:int"/> </extension> </simpleContent> </complexType> <complexType name="Quake"> <attribute name="time" type="xsd:dateTime"/> <attribute name="millis" type="xsd:int"/> <attribute name="latitude" type="xsd:float"/> <attribute name="longitude" type="xsd:float"/> <attribute name="depth" type="xsd:float"/> <attribute name="magnitude" type="xsd:float"/> <attribute name="method" type="xsd:token"/> <attribute name="region" type="xsd:IDREF"/> </complexType> <complexType name="QuakeSet"> <sequence> <element name="area-name" type="xsd:string"/> <element name="regions"> <complexType> <sequence> <element maxOccurs="unbounded" minOccurs="0" name="region" type="tns:Region"/> </sequence> <attribute name="count" type="xsd:int"/> </complexType> </element> <element name="quakes"> <complexType> <sequence> <element maxOccurs="unbounded" minOccurs="0" name="quake" type="tns:Quake"/> </sequence> <attribute name="count" type="xsd:int"/> </complexType> </element> </sequence> </complexType> <element name="results"> <complexType> <sequence> <element maxOccurs="unbounded" minOccurs="0" name="result-set" type="tns:QuakeSet"/> </sequence> <attribute name="count" type="xsd:int"/> </complexType> </element> </schema> </wsdl:types> <wsdl:message name="Query"> <wsdl:part name="query" element="tns:query"/> </wsdl:message> <wsdl:message name="Response"> <wsdl:part name="results" element="tns:results"/> </wsdl:message> <wsdl:portType name="quakeInterface"> <wsdl:operation name="process"> <wsdl:input message="wns:Query"/> <wsdl:output message="wns:Response"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="quakeBinding" type="wns:quakeInterface"> <wsdl:operation name="process"> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> <soap:operation soapAction=""/> </wsdl:operation> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> </wsdl:binding> <wsdl:service name="quakeService"> <wsdl:port name="quake" binding="wns:quakeBinding"> <soap:address location="http://localhost:8080/JibxSoapExample/quake-service"/> </wsdl:port> </wsdl:service> </wsdl:definitions> The schema definition referenced by the service definition file is just embedded directly into the generated WSDL, with all other WSDL components generated by JibxSoap based on the configuration. This includes the actual service location, so that if the same service is accessed via multiple paths the returned WSDL will properly reflect the actual request path. You can experiment with the example application yourself using the supplied code and data, and Ant build file. See the installation page for details. |