Thanks to everyone who replied. The Hello Servlet is running now, but
form parameters are not being picked up.
Here's my test servlet; with trivial mods to the hello servlet. The
do_POST method is a plausible guess, which didn't work:
PS: I'm experienced with java/tomcat/jetty's way of doing things but
entirely new to ruby/webrick.
require 'webrick/httpserver'
require 'webrick'
include WEBrick
class IleServlet < HTTPServlet::AbstractServlet
def do_POST(req, res)
do_GET(req, res)
end
def do_GET(req, res)
res.body = %Q{<HTML>
<head>
<title>Hello world</title>
</head>
<body>
<h1>hello, world</h1>
<p>
<form action="http://192.168.1.3:8989/ile" method="POST">
<input type="text" name="val"
value="xxxxxxxxxxxxxxxxxxxxxxxxx">
<input type="submit" name="op" value="OK">
</form>
</p>
<p>request: #{req.inspect}</p>
<p>response:#{res.inspect}</p>
</body>
</HTML>
}
res['Content-Type'] = "text/html"
end
end
This displays properly via GET. When I click the OK button, here's
the log output
hello, world
OK
request: #"WEBrick/1.1.5 (Ruby/1.6.7/2002-03-01)",
:BindAddress=>"0.0.0.0", :ServerName=>"linux.virtualschool.edu",
:MimeTypes=>{"html"=>"text/html", "pgm"=>"image/x-portable-graymap",
"xml"=>"text/xml", "htm"=>"text/html", "jpg"=>"image/jpeg",
"zip"=>"application/zip", "dvi"=>"application/x-dvi",
"mpe"=>"video/mpeg", "ppm"=>"image/x-portable-pixmap",
"class"=>"application/octet-stream", "doc"=>"application/msword",
"qt"=>"video/quicktime", "sgm"=>"text/sgml", "css"=>"text/css",
"xbm"=>"image/x-xbitmap", "ps"=>"application/postscript",
"mpg"=>"video/mpeg", "pnm"=>"image/x-portable-anymap",
"ras"=>"image/x-cmu-raster", "gif"=>"image/gif",
"rtf"=>"application/rtf", "lzh"=>"application/octet-stream",
"mpeg"=>"video/mpeg", "rb"=>"text/plain", "txt"=>"text/plain",
"xwd"=>"image/x-xwindowdump", "pbm"=>"image/x-portable-bitmap",
"bmp"=>"image/bmp", "lha"=>"application/octet-stream",
"asc"=>"text/plain", "tif"=>"image/tiff", "rd"=>"text/plain",
"pdf"=>"application/pdf", "exe"=>"application/octet-stream",
"bin"=>"application/octet-stream", "sgml"=>"text/sgml",
"jpeg"=>"image/jpeg", "eps"=>"application/postscript",
"ai"=>"application/postscript", "avi"=>"video/x-msvideo",
"mov"=>"video/quicktime", "etx"=>"text/x-setext", "png"=>"image/png",
"jpe"=>"image/jpeg", "ppt"=>"application/vnd.ms-powerpoint",
"xls"=>"application/vnd.ms-excel", "xpm"=>"image/x-xpixmap",
"tiff"=>"image/tiff", "dms"=>"application/octet-stream"},
:TempDir=>"/tmp", :Logger=>#, @time_format="[%Y-%m-%d %H:%M:%S] ",
@level=5>, :ListenImmediately=>true, :ServerType=>nil,
:DirectoryIndex=>["index.html", "index.htm", "index.rhtml",
"index.cgi"], :RequestTimeout=>30, :StartThreads=>5,
:DirectoryListEnable=>true,
:DocumentRoot=>"/home/bcox/perforce/roach/lib/apps", :Port=>8989,
:HTTPVersion=>1.1}, @path="/ile/", @request_uri=#, @peer_addr=nil,
@logger=#, @time_format="[%Y-%m-%d %H:%M:%S] ", @level=5>,
@header={"accept-language"=>["en"], "connection"=>["close"],
"accept"=>["*/*"], "extension"=>["Security/Remote-Passphrase"],
"user-agent"=>["Mozilla/4.0 (compatible; MSIE 5.12; Mac_PowerPC)"],
"cookie"=>["sid=b6f788a52f255bf8894a7a8c9bcb22ce"],
"referer"=>["http://192.168.1.3:8989/"], "ua-cpu"=>["PPC"],
"host"=>["192.168.1.3:8989"], "ua-os"=>["MacOS"],
"pragma"=>["no-cache"]}, @keep_alive=false, @request_method="GET",
@cookies=[#], @http_version="1.0", @path_info="/", @request_line="GET
/ile/ HTTP/1.0\r\n", @body="">
response:#"WEBrick/1.1.5 (Ruby/1.6.7/2002-03-01)",
:BindAddress=>"0.0.0.0", :ServerName=>"linux.virtualschool.edu",
:MimeTypes=>{"html"=>"text/html", "pgm"=>"image/x-portable-graymap",
"xml"=>"text/xml", "htm"=>"text/html", "jpg"=>"image/jpeg",
"zip"=>"application/zip", "dvi"=>"application/x-dvi",
"mpe"=>"video/mpeg", "ppm"=>"image/x-portable-pixmap",
"class"=>"application/octet-stream", "doc"=>"application/msword",
"qt"=>"video/quicktime", "sgm"=>"text/sgml", "css"=>"text/css",
"xbm"=>"image/x-xbitmap", "ps"=>"application/postscript",
"mpg"=>"video/mpeg", "pnm"=>"image/x-portable-anymap",
"ras"=>"image/x-cmu-raster", "gif"=>"image/gif",
"rtf"=>"application/rtf", "lzh"=>"application/octet-stream",
"mpeg"=>"video/mpeg", "rb"=>"text/plain", "txt"=>"text/plain",
"xwd"=>"image/x-xwindowdump", "pbm"=>"image/x-portable-bitmap",
"bmp"=>"image/bmp", "lha"=>"application/octet-stream",
"asc"=>"text/plain", "tif"=>"image/tiff", "rd"=>"text/plain",
"pdf"=>"application/pdf", "exe"=>"application/octet-stream",
"bin"=>"application/octet-stream", "sgml"=>"text/sgml",
"jpeg"=>"image/jpeg", "eps"=>"application/postscript",
"ai"=>"application/postscript", "avi"=>"video/x-msvideo",
"mov"=>"video/quicktime", "etx"=>"text/x-setext", "png"=>"image/png",
"jpe"=>"image/jpeg", "ppt"=>"application/vnd.ms-powerpoint",
"xls"=>"application/vnd.ms-excel", "xpm"=>"image/x-xpixmap",
"tiff"=>"image/tiff", "dms"=>"application/octet-stream"},
:TempDir=>"/tmp", :Logger=>#, @time_format="[%Y-%m-%d %H:%M:%S] ",
@level=5>, :ListenImmediately=>true, :ServerType=>nil,
:DirectoryIndex=>["index.html", "index.htm", "index.rhtml",
"index.cgi"], :RequestTimeout=>30, :StartThreads=>5,
:DirectoryListEnable=>true,
:DocumentRoot=>"/home/bcox/perforce/roach/lib/apps", :Port=>8989,
:HTTPVersion=>1.1}, @header={}, @keep_conn=true, @cookies=[],
@http_version=1.1, @reason_phrase=nil, @body="", @status=200>
Notice that this is received as a GET, not a POST, and the query
string is empty.
At 12:32 AM -0800 4/5/02, mmm wrote:
>On Thu, 4 Apr 2002, Jim Menard wrote:
>
>> Date: Thu, 4 Apr 2002 19:55:53 -0600
>> From: Jim Menard <jimm@io.com>
>> Reply-To: webricken@notwork.org
>> To: webricken@notwork.org
>> Subject: [webricken:86] Re: ai_family not supported (SocketError)
>>
>> Brad Cox writes:
>> > I just joined this list. Sorry if this is a faq.
>> >
>> > On running the HelloWorld example on linux 7.0 + apache latest, I get
>> > this error. Same results with eruby.
>> >
>> > Any suggestions?
>>
>> It is a FAQ. I asked it, too. Here's the answer I received from gotoyuzo:
>>
>> > Sorry. Listening socket is not required for this test.
>> > Please try the following patch.
>> >
>> > --- TestWEBrickHTTPServer.rb~ Tue Feb 5 20:33:11 2002
>> > +++ TestWEBrickHTTPServer.rb Tue Feb 5 06:44:18 2002
>> > @@ -8,14 +8,8 @@
>> > include WEBrick
>> >
>> > def setup
>> > - (2000..3000).each{|port|
>> > - begin
>> > - logger = Log.new(nil, Log::FATAL)
>> > - @svr = HTTPServer.new(:Logger=>logger, :Port=>port)
>> > - break
>> > - rescue Errno::EACCES, Errno::EADDRINUSE
>> > - end
>> > - }
>> > + logger = Log.new(nil, Log::FATAL)
>> > + @svr = HTTPServer.new(:Logger=>logger, :ListenImmediately => false)
>> > end
>> >
>> > Socket::getaddrinfo may cause problem on some Linux box.
>> > See also http://www.ruby-talk.com/28598.
>> >
>> > --
>> > gotoyuzo
>>
>> I also needed to set the :BindAddress address to '0.0.0.0' when starting
>> the server. Here's my httpd.rb:
>>
>> require 'webrick'
>> require 'getopts'
>>
>> DEFAULT_DOCROOT_DIR = File.join(File.dirname($0), 'src')
>>
>> getopts nil, 'r:'
>>
>> s=WEBrick::HTTPServer.new(
>> :BindAddress => '0.0.0.0',
>> :Port => 2000,
>> :Logger => WEBrick::Log::new($stderr, WEBrick::Log::DEBUG),
>> :DocumentRoot => $OPT_R || DEFAULT_DOCROOT_DIR
>> )
>> trap("INT"){ s.shutdown }
>> s.start
>>
>> Jim
>> --
>> Jim Menard, jimm@io.com, http://www.io.com/~jimm/
>> "Any sufficiently complicated C or Fortran program contains an ad hoc
>> informally-specified bug-ridden slow implementation of half of Common Lisp."
>> -- Greenspun's Tenth Rule of Programming
>>
>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>I also had this problem. After some searching, I discovered that
>the getaddrinfo() call in the 'def listen' in file server.rb is trying to
>return IPV6 information (in addition to IPV4) due to the address family
>being AF_UNSPEC. On some systems (my SuSE release 7.3 being one) this
>causes a problem when attempting to retrieve information.
>Changing the Socket::AF_UNSPEC to Socket::AF_INET fixed the problem. The
>family type AF_INET forces only IPV4 information to be returned in the
>socket address structure. Presumably this isn't going to break anything
>regarding dropping the IPV6 information (since IPV6 info. obviously
>couldn't be properly used when it _was_ being returned in the socket
>address structure).
>
>Anyway, that's what I understood from my research, and that's how I fixed
>the problem on my system, and then the httpsd.rb server worked just fine,
>and all the webrick sample programs worked fine after the change, also.
>
>Michael McDaniel
--
Brad Cox, PhD; bcox@virtualschool.edu 703 361 4751
o For industrial age goods there were checks and credit cards.
For everything else there is http://virtualschool.edu/mybank
o Java Interactive Learning Environment http://virtualschool.edu/jile
o Java Web Application Architecture: http://virtualschool.edu/jwaa