9 class JSONServlet < HTTPServlet::AbstractServlet
14 "TIME" => Time.now.strftime("%FT%T"),
19 'COUNT' => @@count += 1,
21 'd' => [ 1, "b", 3.14 ],
22 'e' => { 'foo' => 'bar' },
26 'j' => "\xf0\xa0\x80\x81",
28 res.body = JSON.generate obj
29 res['Content-Type'] = "application/json"
33 def create_server(err, dir, port)
34 dir = File.expand_path(dir)
35 err.puts "Surf to:", "http://#{Socket.gethostname}:#{port}"
40 :Logger => WEBrick::Log.new(err),
42 [ err, WEBrick::AccessLog::COMMON_LOG_FORMAT ],
43 [ err, WEBrick::AccessLog::REFERER_LOG_FORMAT ],
44 [ err, WEBrick::AccessLog::AGENT_LOG_FORMAT ]
47 s.mount("/json", JSONServlet)
51 default_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'data'))
52 dir = ARGV.shift || default_dir
53 port = (ARGV.shift || 6666).to_i
54 s = create_server(STDERR, dir, 6666)
55 t = Thread.new { s.start }