|
||||
IntroductionNetKernel is agnostic with respect to web-service/XML-service technologies. Internally it uses REST-like URI interfaces for services supplied from different modules. It is relatively simple to export a module's public URI address space to an HTTP transport to create a classic REST service. This trailmap shows how to build a module which exports an XML service interface over HTTP. Service SpecificationWe will create a service which generates a PNG bitmap image of a supplied text string. We will also support an optional fontsize argument. The service will be exported with a URL /trailmap/service/Text2PNG. So an example request on the interface would look like...
If no query parameters are supplied we will return an HTML document giving the service interface description. ExampleThere's an example service at /example/trailmap/service/Text2PNG. Here's an image generated by the service...
You can try it out for yourself here. The service definition is available here. At the bottom of this page is the DPML idoc that processes the service requests. It uses the org.ten60.util.image.text2PNG accessor provided by the util_image module. We will not cover the DPML in depth - the service to be exported as a REST service could do anything you like. The example service shown above is tied into the documentation module so for the remainder of this trailmap we'll discuss how to setup a standalone module configuration which exports this DPML service with the correct URL /trailmap/service/Text2PNG as defined in the specification. Developing the Service
The service is now configured and exported. You should now be able to call it with the parameters specified above. Any DPML process can be exported as a REST service using this method of rewriting an external URI to an active URI DPML request. Text2PNG DPML<idoc>
<seq> <comment> ************** Transform the parameter document into a Text2PNG parameter document using an inline XSLT transform ************** </comment> <instr> <type>xslt</type> <operand>this:param</operand> <operator> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" /> <xsl:template match="/nvp"> <text2PNG> <fontsize> <!--Deal with optional fontsize--> <xsl:choose> <xsl:when test="fontsize"> <xsl:value-of select="fontsize" /> </xsl:when> <xsl:otherwise>12</xsl:otherwise> </xsl:choose> </fontsize> </text2PNG> </xsl:template> </xsl:stylesheet> </operator> <target>var:Text2PNG</target> </instr> <comment> ************** Invoke the Text2PNG accessor with the text referenced by xpointer and the newly created Text2PNG specification doc. ************** </comment> <instr> <type>org.ten60.util.image.text2PNG</type> <operand>this:param#xpointer(/nvp/text)</operand> <operator>var:Text2PNG</operator> <target>this:response</target> </instr> <exception> <comment> ************** An exception will be thrown if we don't receive a parameter so issue an HTML service description. ************** </comment> <instr> <type>copy</type> <operand> <html> <body> <h2>Text2PNG Service Specification</h2> <p> This service generates a PNG bitmap image of a supplied text string. It supports an optional fontsize argument. The service is exported with a URL /trailmap/service/Text2PNG. So an example request on the interface would look like... </p> <p> <code>http://localhost:8080/trailmap/service/Text2PNG?text=Hello%20World&fontsize=20</code> <ul> <li> <b>text</b> is the URL escaped text string to render </li> <li> <b>fontsize</b> is the optional font size to render the text with </li> </ul> The service will support either GET or POST encoded form data requests. </p> <p> If no query parameters are supplied this service interface description is served. </p> </body> </html> </operand> <target>this:response</target> </instr> <instr> <type>cast</type> <operand>this:response</operand> <operator> <cast> <mimetype>text/html</mimetype> </cast> </operator> <target>this:response</target> </instr> </exception> </seq> </idoc>
|
||||
|
© 2003,2004, 1060® Research Limited
1060 registered trademark, NetKernel trademark of 1060 Research Limited
|
||||