Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > 71d40963b505df4524269198e237b3e3 > files > 828

virtuoso-opensource-doc-6.1.4-2.fc14.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
 <head profile="http://internetalchemy.org/2003/02/profile">
  <link rel="foaf" type="application/rdf+xml" title="FOAF" href="http://www.openlinksw.com/dataspace/uda/about.rdf" />
  <link rel="schema.dc" href="http://purl.org/dc/elements/1.1/" />
  <meta name="dc.title" content="12. Web Application Development" />
  <meta name="dc.subject" content="12. Web Application Development" />
  <meta name="dc.creator" content="OpenLink Software Documentation Team ;&#10;" />
  <meta name="dc.copyright" content="OpenLink Software, 1999 - 2009" />
  <link rel="top" href="index.html" title="OpenLink Virtuoso Universal Server: Documentation" />
  <link rel="search" href="/doc/adv_search.vspx" title="Search OpenLink Virtuoso Universal Server: Documentation" />
  <link rel="parent" href="webappdevelopment.html" title="Chapter Contents" />
  <link rel="prev" href="perlhosting.html" title="Perl Hosting" />
  <link rel="next" href="rubyhosting.html" title="Ruby Hosting" />
  <link rel="shortcut icon" href="../images/misc/favicon.ico" type="image/x-icon" />
  <link rel="stylesheet" type="text/css" href="doc.css" />
  <link rel="stylesheet" type="text/css" href="/doc/translation.css" />
  <title>12. Web Application Development</title>
  <meta http-equiv="Content-Type" content="text/xhtml; charset=UTF-8" />
  <meta name="author" content="OpenLink Software Documentation Team ;&#10;" />
  <meta name="copyright" content="OpenLink Software, 1999 - 2009" />
  <meta name="keywords" content="" />
  <meta name="GENERATOR" content="OpenLink XSLT Team" />
 </head>
 <body>
  <div id="header">
    <a name="pythonhosting" />
    <img src="../images/misc/logo.jpg" alt="" />
    <h1>12. Web Application Development</h1>
  </div>
  <div id="navbartop">
   <div>
      <a class="link" href="webappdevelopment.html">Chapter Contents</a> | <a class="link" href="perlhosting.html" title="Perl Hosting">Prev</a> | <a class="link" href="rubyhosting.html" title="Ruby Hosting">Next</a>
   </div>
  </div>
  <div id="currenttoc">
   <form method="post" action="/doc/adv_search.vspx">
    <div class="search">Keyword Search: <br />
        <input type="text" name="q" /> <input type="submit" name="go" value="Go" />
    </div>
   </form>
   <div>
      <a href="http://www.openlinksw.com/">www.openlinksw.com</a>
   </div>
   <div>
      <a href="http://docs.openlinksw.com/">docs.openlinksw.com</a>
   </div>
    <br />
   <div>
      <a href="index.html">Book Home</a>
   </div>
    <br />
   <div>
      <a href="contents.html">Contents</a>
   </div>
   <div>
      <a href="preface.html">Preface</a>
   </div>
    <br />
   <div class="selected">
      <a href="webappdevelopment.html">Web Application Development</a>
   </div>
    <br />
   <div>
      <a href="webserver.html">The HTTP Server</a>
   </div>
   <div>
      <a href="wsacl.html">Web Services ACL (Access Control List)</a>
   </div>
   <div>
      <a href="vsp1.html">Virtuoso Server Pages (VSP)</a>
   </div>
   <div>
      <a href="vspx.html">Virtuoso Server Pages for XML (VSPX)</a>
   </div>
   <div>
      <a href="rthwritaspxapps.html">Deploying ASP.Net Web Applications</a>
   </div>
   <div>
      <a href="asmxhosting.html">ASMX Web Service Hosting</a>
   </div>
   <div>
      <a href="blogger.html">Blogging &amp; Weblogs</a>
   </div>
   <div>
      <a href="servphpext.html">Deploying PHP Applications</a>
   </div>
   <div>
      <a href="rthjsp.html">Deploying JSP Applications</a>
   </div>
   <div>
      <a href="perlhosting.html">Perl Hosting</a>
   </div>
   <div class="selected">
      <a href="pythonhosting.html">Python Hosting</a>
   </div>
   <div>
      <a href="rubyhosting.html">Ruby Hosting</a>
   </div>
    <br />
  </div>
  <div id="text">
    <a name="pythonhosting" />
    <h2>12.11. Python Hosting</h2>

<p>Virtuoso functionality can be enhanced through external libraries by
loading shared objects or DLLs.  The new functions are written in a language of
choice and compiled to produce a shared library appropriate to the operating
system.  The path to the shared library must be declared in the Virtuoso INI
file and the server restarted before it can be used.</p>

<p>The Python language is hosted within Virtuoso in this way.
<span class="computeroutput">hosting_python.so</span> (or
<span class="computeroutput">hosting_python.dll</span>) is the library used.</p>

<p>The Python hosting module requires the Python library, version 2.2.2 or above,
to build and use the module, which then must be installed in the Plugins-Load-path
defined in the Virtuoso ini file.  The source code and build script
(<span class="computeroutput">build.py</span>) for building the
<span class="computeroutput">hosting_python.so</span> module are included in the Unix
distribution in the  <span class="computeroutput">custom/hosting/python</span>
directory.  The Unix installer will offer to build it near the end of the
installation process.  The build.py is a kind of Makefile.  On unix it requires
<span class="computeroutput">libtool</span> and <span class="computeroutput">cc</span>
in the path.  On windows it requires <span class="computeroutput">cl.exe</span>
in the path.</p>

<p>The Virtuoso INI file uses a [Plugins] configuration section for listing
shared libraries for the server to load upon startup.  An example of this is:</p>

<div>
      <pre class="programlisting">
[Plugins]
LoadPath = /home/virtuoso/hosting
Load1 = Hosting, hosting_python.so
..
</pre>
    </div>

<p>The &quot;Hosting&quot; type defines the entry points for initialization of the runtime
hosting environment, destruction of the user environment and execution of a
file or string containing commands in the hosted language.  It also returns a
list of file extensions that it is capable of processing.  Virtuoso
dynamically defines memory-resident (no disk image) HTTP server handlers for
each specified type. </p>

<p>The Python hosting plugin supports the &#39;py&#39; extension.  Hence, upon
initialization of the hosting plugin, Virtuoso defines the
<span class="computeroutput">__http_handler_py(..)</span>  function according to the API for
file type handlers in the Virtuoso HTTP server.  With this handler in place,
each hit on a .py file (file system or WebDAV) with appropriate execute
permissions will cause the HTTP server to execute the code within it and return
the result instead of simple the file contents.</p>

<p>The python interpreter has a global lock unrelated to the Virtuoso hosting
module, thus no more than one thread can run python code at a time.</p>

<p>The handler will call the __hosting_http_handler VSE with a special set
of parameters to represent the HTTP environment correctly.  Virtuoso will, by
default call the plugin to memory as required, and expel it when finished.
This behavior can be controlled by the INI file parameter:</p>

<div>
      <pre class="programlisting">
[HTTPServer]
PersistentHostingModules = 1/0 default 0
</pre>
    </div>

<p>Setting <span class="computeroutput">PersistentHostingModules</span> to &quot;1&quot;
prevents Virtuoso from removing the interpreters from the HTTP threads after
each request.</p>

<div class="tip">
      <div class="tiptitle">See Also:</div>
  <p>
        <a href="vseplugins.html">VSEI Plugins</a>
      </p>
    </div>

<a name="ex_hostingsharedobjectspy" />
    <div class="example">
      <div class="exampletitle">Using the Python Plugin</div>

<p>Executing Python code directly:</p>

<div>
        <pre class="programlisting">
select __hosting_http_handler (&#39;py&#39;, &#39;print &quot;hello world&quot;; &#39;, &#39;&#39;, vector (), &#39;helloworld.py&#39;);
</pre>
      </div>

<div>
        <pre class="programlisting">
returns : hello world
</pre>
      </div>

<p>Executing a python script file (python/test_print.py in the Virtuoso
working directory):</p>

<div>
        <pre class="programlisting">
python/test_print.py
-------------------
#!/usr/bin/python
print &quot;hello world file&quot;;
</pre>
      </div>

<div>
        <pre class="programlisting">
select __hosting_http_handler (&#39;py&#39;, &#39;python/test_print.py&#39;);
</pre>
      </div>

<div>
        <pre class="programlisting">
returns : hello world file
</pre>
      </div>
</div>

<table border="0" width="90%" id="navbarbottom">
    <tr>
        <td align="left" width="33%">
          <a href="perlhosting.html" title="Perl Hosting">Previous</a>
          <br />Perl Hosting</td>
     <td align="center" width="34%">
          <a href="webappdevelopment.html">Chapter Contents</a>
     </td>
        <td align="right" width="33%">
          <a href="rubyhosting.html" title="Ruby Hosting">Next</a>
          <br />Ruby Hosting</td>
    </tr>
    </table>
  </div>
  <div id="footer">
    <div>Copyright© 1999 - 2009 OpenLink Software All rights reserved.</div>
   <div id="validation">
    <a href="http://validator.w3.org/check/referer">
        <img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" />
    </a>
    <a href="http://jigsaw.w3.org/css-validator/">
        <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" height="31" width="88" />
    </a>
   </div>
  </div>
 </body>
</html>