Web Services
1. Overview
Your OPS applications can consume and expose Web services.
2. Consuming Web Services
Applications built on OPS call Web services using the delegation processor. For example, this is how you
would call the famous highway traffic Web service to get the conditions on the 101
highway in California from an XPL:
<p:processor name="oxf:delegation" xmlns:p="http://www.orbeon.com/oxf/pipeline"> <p:input name="interface"> <config> <service id="ca-traffic" type="webservice" endpoint="http://services.xmethods.net/soap/servlet/rpcrouter"> <operation nsuri="urn:xmethods-CATraffic" name="getTraffic"/> </service> </config> </p:input> <p:input name="call"> <delegation:execute service="ca-traffic" operation="getTraffic" xmlns:delegation="http://orbeon.org/oxf/xml/delegation"> <hwynums>101</hwynums> </delegation:execute> </p:input> <p:output name="data" id="traffic"/> </p:processor>
The output of that call would be:
<return xsi:type="xsd:string">reported as of Wednesday, July 2, 2003 at 16:18 . Slow for the Cone Zone US 101 [LOS ANGELES & VENTURA CO.'S] NO TRAFFIC RESTRICTIONS
ARE REPORTED FOR THIS AREA ... </return>
3. Exposing Web Services
To expose a Web service, follow these steps:
-
Declare the Web service in the page-flow.xml , just like a
regular page with no view. The Web services will be implemented in an XPL file.
The OPS example portal features a Web service that sends
instant messages to Yahoo! users. It is declared in the
page-flow.xml as follows:
<page path-info="/examples/im" model="oxf:/im/yim-webservice.xpl"/>
-
To get the SOAP envelope sent to the Web service, use the Request generator and
include the path /request/body , specifying the
xs:anyURI type for the result. The resuting URI can then be parsed
with the URL generator:
<!-- Extract request body as a URI --> <p:processor name="oxf:request" xmlns:p="http://www.orbeon.com/oxf/pipeline"> <p:input name="config"> <config stream-type="xs:anyURI"> <include>/request/body</include> </config> </p:input> <p:output name="data" id="request"/> </p:processor> <!-- Dereference URI --> <p:processor name="oxf:url-generator" xmlns:p="http://www.orbeon.com/oxf/pipeline"> <p:input name="config" href="aggregate('config', aggregate('url', #request#xpointer(string(/reqest/body)))"/> <p:output name="data" id="file"/> </p:processor>
You will find the SOAP envelope sent by the client of your Web service as the
resulting file. For example:
<soapenv:Envelope soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body>...</soapenv:Body> </soapenv:Envelope>
-
Generate a SOAP envelope that responds to the client's
request and send it to the client with the XML
serializer, as follows:
<p:processor name="oxf:xml-serializer" xmlns:p="http://www.orbeon.com/oxf/pipeline"> <p:input name="config"> <config/> </p:input> <p:input name="data" href="#response"/> </p:processor>
|