From: Michael Neumann Date: 2001-11-09T20:36:33+09:00 Subject: [ruby-talk:24756] Re: Ruby servlet container? Gary Lawrence Murphy wrote: > Mod_ruby requires all the overhead of an apache install, and that's > the sort of admin overhead I was hoping to avoid; even tomcat would > be overkill for a simple webservice. In the java world, these > things fall to jo! or Jini, and in C/C++ it falls to curl; I > just wondered if there was a simple-but-effective Ruby HTTP > server -- in a perfect world, this would be like curl+wombat > (servlet package for perl) only in Ruby. Have a look at wwwsrv at RAA. It's simple yet powerful. An example how to use it is shown below. ======================================================== # file: srv.rb require "xmlrpc/server" module XMLRPC class WWWServer < WWWsrv::Document def initialize(server) @server = server end def session(sid, srv_opt, prefix, request, response) srv_opt.log.debug "sid #{sid}: debug #{type}" case (request.method) when 'POST' if request.header.content_type != "text/xml" response.status = 400 http_error(response) end length = request.header.content_length.to_i if length <= 0 response.status = 411 http_error(response) end data = request.content.read(length) if data.nil? or data.size != length response.status = 400 http_error(response) end resp = @server.process(data) response.status = 200 response.header.content_type = 'text/xml' yield(response) yield(resp) else response.status = 405 http_error(response) end end end # class WWWServer end # module XMLRPC ======================================================== # The config file __HOST__ HOSTNAME = '0.0.0.0' PORT = 8000 STRICT = false # WWWsrv::Server object initialization parameters are defined in this # section. When parameters are omitted, default parameters are used. __SERVER__ # A new created WWWsrv::Server object is set up in this section. # SERVER constant variable is bound to a new server object. require 'srv' srv = XMLRPC::WWWServer::new( XMLRPC::BasicServer.new. add_handler("michael.add") {|a,b| a + b}. add_handler("michael.sub") {|a,b| a - b}. add_introspection ) SERVER.mount(srv, '/') ======================================================== Regards, Michael -- Michael Neumann merlin.zwo InfoDesign GmbH http://www.merlin-zwo.de