<!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 ; " /> <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="pythonhosting.html" title="Python Hosting" /> <link rel="next" href="contents.html" title="Contents" /> <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 ; " /> <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="rubyhosting" /> <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="pythonhosting.html" title="Python Hosting">Prev</a> | <a class="link" href="webandxml.html" title="XML Support">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 & 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> <a href="pythonhosting.html">Python Hosting</a> </div> <div class="selected"> <a href="rubyhosting.html">Ruby Hosting</a> </div> <br /> </div> <div id="text"> <a name="rubyhosting" /> <h2>12.12. Ruby 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 Ruby language is hosted within Virtuoso in this way. <span class="computeroutput">hosting_ruby.so</span> (or <span class="computeroutput">hosting_ruby.dll</span>) is the library used.</p> <p>The Ruby hosting module requires the Ruby library, version 1.8.3 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 for building the <span class="computeroutput">hosting_ruby.so</span> module are included in the Unix distribution in the <span class="computeroutput">custom/hosting/ruby</span> directory. The Unix installer will offer to build it near the end of the installation process.</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_ruby.so .. </pre> </div> <p>The "Hosting" 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 Ruby hosting plugin supports the 'rb' extension. Hence, upon initialization of the hosting plugin, Virtuoso defines the <span class="computeroutput">__http_handler_rb(..)</span> function according to the API for file type handlers in the Virtuoso HTTP server. With this handler in place, each hit on a .rb 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 ruby interpreter has a global lock unrelated to the Virtuoso hosting module, thus no more than one thread can run ruby 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 "1" 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 Ruby Plugin</div> <p>Executing Ruby code directly:</p> <div> <pre class="programlisting"> select __hosting_http_handler ('rb', 'print "hello world"; ', '', vector (), 'helloworld.rb'); </pre> </div> <div> <pre class="programlisting"> returns : hello world </pre> </div> <p>Executing a ruby script file (ruby/test_print.rb in the Virtuoso working directory):</p> <div> <pre class="programlisting"> ruby/test_print.rb ------------------- #!/usr/bin/ruby print "hello world file"; </pre> </div> <div> <pre class="programlisting"> select __hosting_http_handler ('rb', 'ruby/test_print.rb'); </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="pythonhosting.html" title="Python Hosting">Previous</a> <br />Python Hosting</td> <td align="center" width="34%"> <a href="webappdevelopment.html">Chapter Contents</a> </td> <td align="right" width="33%"> <a href="webandxml.html" title="XML Support">Next</a> <br />Contents of XML Support</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>