CGI Services Architecture
Recent Pages

Environment Variables
Handling Concurrency
Template Processing
RDF Responses
RDF Messaging
URL Rewriting
File Uploads
Sample Authenticated Se ...
HTTP Cookies
Client Authentication

Links

www.strozzi.it on Twitter
CSA Home
Table of Contents

Advertising

Session

User ID
Password



Campaigns

stopsoftwarepatents.eu petition banner

RDF Responses

Here is the source code of a typical CSA response in XHTML, produced by the Hello World example program:

 <?xml version="1.0" standalone="no"?> 
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                                        "DTD/xhtml1-transitional.dtd"> 
 
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
 <head> 
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
 
 <title>Success!</title> 
 
 <script type="text/csa-rdf-container"> 
 
 <![CDATA[ 
  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
          xmlns:csa="http://www.linux.it/~carlos/csa/" 
          xmlns="http://www.linux.it/~carlos/csa/"> 
 
   <rdf:Description rdf:about="#response"> 
    <result> 
     <rdf:Seq rdf:ID="response.1"> 
      <rdf:li 
  rdf:datatype="http://www.w3.org/2000/10/XMLSchema#string">Hello World!</rdf:li> 
 
     </rdf:Seq> 
    </result> 
   </rdf:Description> 
 
  </rdf:RDF> 
 ]]> 
 </script> 
 
 </head> 
 
 <body> 
 <p> 
 Hello World! 
 </p></body></html> 
As you can see, such response contains two sections: an RDF container embedded in the HTML <script> element, and the usual HTML body. The RDF part is meant to be parsed by a programmatic client, while the HTML payload is presumably to be read by humans. Apart from that, the two sections contain the very same pieces of information, just formatted differently. The machine-oriented section contains one single <result> tag, named response.1 as an RDF resource, and that resource contains an ordered list (array) of string-type values (only one in this stripped-down example, but there could be more, and they could be of mixed types, not just strings).

Explaining how RDF works is ouside the scope of this manual so I won't get into the details here, but the above should give you the general idea. The example shown is a bit artificial, as a real-world response will normally contain more RDF stuff and possibly a larger HTML <body>. Here is what the actual response page from the same Hell oWorld program will look like in the reality:

 <?xml version="1.0" standalone="no"?> 
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                                             "DTD/xhtml1-transitional.dtd"> 
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
 <head> 
 <!-- $Id: rdf-responses+wki,v 1.1 2007/11/15 21:44:11 carlo Exp www-data $ --> 
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
 
 <title>Success!</title> 
 <!-- begin of machine-oriented section --> 
 <!-- 
      Although browsers ignore unknown tags, most of them display the 
      associated content, if any. This results in the following block 
      content to appear at the top of the page, with only minimal 
      formatting. Since I do not want it to appear at all, incapsulating 
      the whole meta-data block into a 'script' element with a bogus 
      'type' attribute does the trick. 
  --> 
 
  <script type="text/csa-rdf-container"> 
  <![CDATA[ 
  <!-- The Dublin Core part is about the page template itself.  --> 
 
  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
          xmlns:dc="http://purl.org/dc/elements/1.1/" 
          xmlns:csa="http://www.linux.it/~carlos/csa/" 
          xmlns:cc="http://web.resource.org/cc/" 
          xmlns="http://www.linux.it/~carlos/csa/"> 
   <!-- 
      This part is about the page template itself. The idea is that this 
      template becomes a subordinate resource of whichever URI led to it. 
   --> 
   <rdf:Description rdf:about="#template"> 
    <dc:relation>csaOk.html</dc:relation> 
    <dc:description>generic CSA positive completion template</dc:description> 
 
    <dc:title>Success</dc:title> 
    <dc:creator> 
     <rdf:Bag> 
      <rdf:li rdf:resource="http://www.linux.it/~carlos/" /> 
     </rdf:Bag> 
 
    </dc:creator> 
    <dc:date>2003-05-28</dc:date> 
    <dc:format>text/html</dc:format> 
    <cc:Work rdf:parseType="Resource" rdf:about=""> 
     <cc:license rdf:resource="http://creativecommons.org/licenses/GPL/2.0/" /> 
 
     <!-- 
      A web page or xml response can be produced only if a either a user 
      or a client program makes a request to a server program, thus I think 
      the InteractiveResource type is appropriate for such objects. Carlo 
     --> 
     <dc:type rdf:resource="http://purl.org/dc/dcmitype/InteractiveResource" /> 
    </cc:Work> 
    <cc:License rdf:parseType="Resource" 
        rdf:about="http://creativecommons.org/licenses/GPL/2.0/"> 
     <cc:permits rdf:resource="http://web.resource.org/cc/Reproduction" /> 
     <cc:permits rdf:resource="http://web.resource.org/cc/Distribution" /> 
 
     <cc:requires rdf:resource="http://web.resource.org/cc/Notice" /> 
     <cc:permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" /> 
     <cc:requires rdf:resource="http://web.resource.org/cc/ShareAlike" /> 
     <cc:requires rdf:resource="http://web.resource.org/cc/SourceCode" /> 
    </cc:License> 
   </rdf:Description> 
 
   <!-- IDL begin --> 
   <rdf:Description rdf:about="#service"> 
  <!-- $Id: rdf-responses+wki,v 1.1 2007/11/15 21:44:11 carlo Exp www-data $ --> 
  <dc:relation> 
    http://www.example.com/cgi-bin/cgiwrap/~goofy/CSA/example.hello-world 
  </dc:relation> 
 
  <dc:description>default data for CSA_RPC_IDL</dc:description> 
  <dc:creator rdf:resource="http://www.linux.it/~carlos/" /> 
  <cc:Work rdf:parseType="Resource" rdf:about=""> 
   <cc:license rdf:resource="http://creativecommons.org/licenses/GPL/2.0/" /> 
   <!-- 
    A web page or xml response can be produced only if a either a user 
    or a client program makes a request to a server program, thus I think 
    the InteractiveResource type is appropriate for such objects. Carlo 
   --> 
 
   <dc:type rdf:resource="http://purl.org/dc/dcmitype/InteractiveResource" /> 
  </cc:Work> 
  <cc:License rdf:parseType="Resource" 
        rdf:about="http://creativecommons.org/licenses/GPL/2.0/"> 
   <cc:permits rdf:resource="http://web.resource.org/cc/Reproduction" /> 
   <cc:permits rdf:resource="http://web.resource.org/cc/Distribution" /> 
   <cc:requires rdf:resource="http://web.resource.org/cc/Notice" /> 
 
   <cc:permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" /> 
   <cc:requires rdf:resource="http://web.resource.org/cc/ShareAlike" /> 
   <cc:requires rdf:resource="http://web.resource.org/cc/SourceCode" /> 
  </cc:License> 
 </rdf:Description> 
 
   <!-- IDL end --> 
 
   <rdf:Description rdf:about="#call"> 
    <dc:date>2004-08-03T14:53:11+0200</dc:date> 
       </rdf:Description> 
 
   <rdf:Description rdf:about="#response"> 
    <result> 
 
     <rdf:Seq rdf:ID="response.1"> 
      <rdf:li 
  rdf:datatype="http://www.w3.org/2000/10/XMLSchema#string">1000</rdf:li> 
      <rdf:li 
  rdf:datatype="http://www.w3.org/2000/10/XMLSchema#string">INFO_OK</rdf:li> 
      <rdf:li 
  rdf:datatype="http://www.w3.org/2000/10/XMLSchema#string">Hello World!</rdf:li> 
 
     </rdf:Seq> 
    </result> 
   </rdf:Description> 
 
  </rdf:RDF> 
  ]]> 
  </script> 
 
 <!-- begin of human-oriented section --> 
 </head> 
 
 <body> 
 <p> 
 Hello World! 
 </p></body></html> 
This more realistic examples shows that a real response contains quite a bit of stuff, to cope with other meta-data that are used in practise, such as Copyright stuff for both the web service and the response template (the latter may contain copyrighted elements, especially in the human-oriented HTML body). Other sections deal with the interface definition (IDL) of the requested service, the echoing of call parameters back to the client for debugging purposes, and so on. Given the triviality of the Hello World example, even the real-world version of the response does not show every possible meta-data that a typical CSA response can convey. Often the called program can take parameters, as it is the case with the following sample "calendar" program than can optionally be passed year/month values:

 # Sample calendar program for CSA tutoring. 
 csaGetArgs 
 csaMkTemp ftmp 
 cal $WWW_month $WWW_year > $ftmp 
 csaExit.pcdata $ftmp 
 # End of program. 
If we call http://www.example.com/cgi-bin/cgiwrap/goofy/CSA?0=example.calendar&year=2004&month=8 with a Web browser (after replacing the relevant parts of the URL with your local setup), here's what we will see if we ask our browser to show us the HTML source code of the response page:

 <?xml version="1.0" standalone="no"?> 
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                                           "DTD/xhtml1-transitional.dtd"> 
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
 <head> 
 <!-- $Id: rdf-responses+wki,v 1.1 2007/11/15 21:44:11 carlo Exp www-data $ --> 
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
 
 <title>Result</title> 
 <!-- begin of machine-oriented section --> 
 <!-- 
      Although browsers ignore unknown tags, most of them display the 
      associated content, if any. This results in the following block 
      content to appear at the top of the page, with only minimal 
      formatting. Since I do not want it to appear at all, incapsulating 
      the whole meta-data block into a 'script' element with a bogus 
      'type' attribute does the trick. 
  --> 
 
  <script type="text/csa-rdf-container"> 
  <![CDATA[ 
  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
          xmlns:dc="http://purl.org/dc/elements/1.1/" 
          xmlns:csa="http://www.linux.it/~carlos/csa/" 
          xmlns:cc="http://web.resource.org/cc/" 
          xmlns="http://www.linux.it/~carlos/csa/"> 
 
   <!-- 
      This part is about the page template itself. The idea is that this 
      template becomes a subordinate resource of whichever URI led to it. 
   --> 
   <rdf:Description rdf:about="#template"> 
    <dc:relation>csaPCdata.html</dc:relation> 
    <dc:description>generic CSA PCDATA result template</dc:description> 
    <dc:title>Result</dc:title> 
 
    <dc:creator> 
     <rdf:Bag> 
      <rdf:li rdf:resource="http://www.linux.it/~carlos/" /> 
     </rdf:Bag> 
    </dc:creator> 
    <dc:date>2003-05-28</dc:date> 
 
    <dc:format>text/html</dc:format> 
    <cc:Work rdf:parseType="Resource" rdf:about=""> 
     <cc:license rdf:resource="http://creativecommons.org/licenses/GPL/2.0/" /> 
     <!-- 
      A web page or xml response can be produced only if a either a user 
      or a client program makes a request to a server program, thus I think 
      the InteractiveResource type is appropriate for such objects. Carlo 
     --> 
     <dc:type rdf:resource="http://purl.org/dc/dcmitype/InteractiveResource" /> 
 
    </cc:Work> 
    <cc:License rrdf:parseType="Resource" 
        rdf:about="http://creativecommons.org/licenses/GPL/2.0/"> 
     <cc:permits rdf:resource="http://web.resource.org/cc/Reproduction" /> 
     <cc:permits rdf:resource="http://web.resource.org/cc/Distribution" /> 
     <cc:requires rdf:resource="http://web.resource.org/cc/Notice" /> 
     <cc:permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" /> 
 
     <cc:requires rdf:resource="http://web.resource.org/cc/ShareAlike" /> 
     <cc:requires rdf:resource="http://web.resource.org/cc/SourceCode" /> 
    </cc:License> 
   </rdf:Description> 
 
   <!-- IDL begin --> 
   <rdf:Description rdf:about="#service"> 
 
  <!-- $Id: rdf-responses+wki,v 1.1 2007/11/15 21:44:11 carlo Exp www-data $ --> 
  <dc:relation> 
   http://www.example.com/cgi-bin/cgiwrap/~goofy/CSA/example.calendar 
  </dc:relation> 
  <dc:description>CSA sample calendar program</dc:description> 
  <dc:creator rdf:resource="http://www.linux.it/~carlos/" /> 
 
  <dc:date>2003-01-15</dc:date> 
  <dc:format rdf:resource="http://rc-shell.slackmatic.org/" /> 
  <cc:Work rdf:parseType="Resource" rdf:about=""> 
   <cc:license rdf:resource="http://creativecommons.org/licenses/GPL/2.0/" /> 
   <dc:type rdf:resource="http://purl.org/dc/dcmitype/Software" /> 
 
  </cc:Work> 
  <cc:License rdf:parseType="Resource" 
        rdf:about="http://creativecommons.org/licenses/GPL/2.0/"> 
   <cc:permits rdf:resource="http://web.resource.org/cc/Reproduction" /> 
   <cc:permits rdf:resource="http://web.resource.org/cc/Distribution" /> 
   <cc:requires rdf:resource="http://web.resource.org/cc/Notice" /> 
   <cc:permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" /> 
 
   <cc:requires rdf:resource="http://web.resource.org/cc/ShareAlike" /> 
   <cc:requires rdf:resource="http://web.resource.org/cc/SourceCode" /> 
  </cc:License> 
 </rdf:Description> 
 
 <rdf:Description rdf:about="#interface-1"> 
  <dc:descripttion> 
 
   If no arguments are passed, then the current month calendar is returned. 
  </dc:description> 
  <param /> 
 </rdf:Description> 
 
 <rdf:Description rdf:about="#interface-2"> 
  <param> 
 
   <rdf:Seq rdf:ID="interface-2.year"> 
    <rdf:li rdf:datatype="http://www.w3.org/2000/10/XMLSchema#int" /> 
   </rdf:Seq> 
  </param> 
  <dc:description> 
   If one single argument is passed, then it is considered a year value. 
  </dc:description> 
 
 </rdf:Description> 
 
 <rdf:Description rdf:about="#interface-3"> 
  <param> 
   <rdf:Seq rdf:ID="interface-3.year"> 
    <rdf:li rdf:datatype="http://www.w3.org/2000/10/XMLSchema#int" /> 
   </rdf:Seq> 
 
  </param> 
 
  <param> 
   <rdf:Seq rdf:ID="interface-3.month"> 
    <rdf:li rdf:datatype="http://www.w3.org/2000/10/XMLSchema#int" /> 
   </rdf:Seq> 
  </param> 
 
  <dc:description> 
   If both arguments are passed, they are treated as year/month. 
  </dc:description> 
 </rdf:Description> 
 
   <!-- IDL end --> 
 
   <rdf:Description rdf:about="#call"> 
 
    <dc:date>2004-08-03T16:03:52+0200</dc:date> 
    <param><rdf:Seq rdf:ID="call.year"> 
 <rdf:li rdf:datatype="http://www.w33333.org/20000/10/XMLSchema#int">2004</rdf:li> 
 </rdf:Seq></param> 
 
 <param><rdf:Seq rdf:ID="call.month"> 
 <rdf:li rdf:datatype="http://www.w3.org/2000/10/XMLSchema#int">8</rdf:li> 
 </rdf:Seq></param> 
   </rdf:Description> 
 
   <rdf:Description rdf:about="#response"> 
    <result> 
     <rdf:Seq rdf:ID="response.1"> 
      <rdf:li rdf:datatype="http://www.w3.org/2000/10/XMLSchema#string">August 2004 
 Su Mo Tu We Th Fr Sa 
  1  2  3  4  5  6  7 
  8  9 10 11 12 13 14 
 15 16 17 18 19 20 21 
 22 23 24 25 26 27 28 
 29 30 31 
 
 </rdf:li>    </rdf:Seq> 
    </result> 
 
   </rdf:Description> 
 
  </rdf:RDF> 
  ]]> 
  </script></head> 
 
 
 
 <body> 
 <p> 
 </p><blockquote><pre>    August 2004 
 Su Mo Tu We Th Fr Sa 
  1  2  3  4  5  6  7 
  8  9 10 11 12 13 14 
 15 16 17 18 19 20 21 
 22 23 24 25 26 27 28 
 29 30 31 
 
 </pre></blockquote> 
 
 </body></html> 
Now, all this may seem overkill for carrying simple stuff as the one shown in the examples, and maybe it really is. On the other hand it is XML that is often criticised as being needlessly verbose, so blame it, not me laughing smiley. As the dialog between the client and the server gets more articulated, however, the overhead introduced by XML/RDF becomes proportionally smaller and the overall usefulness of the above mechanism starts to emerge.
Trackbacks (0) | New trackback | Print

This Web Site is Copyright © 2007,2008,2009,2010 Carlo Strozzi, Some Rights Reserved
site map | recent changes | disclaimer