A
download WEBrickServlet.rb
Language: Ruby
LOC: 52
Project Info
IOWA
Server: RubyForge
Type: cvs
...Forge\i\iowa\iowa\iowa\src\
   Application.rb
   ApplicationStats.rb
   Association.rb
   BindingsParser.rb
   Client.rb
   Component.rb
   ComponentProxy.rb
   config.rb
   Context.rb
   DbPool.rb
   DynamicElements.rb
   Element.rb
   Form.rb
   HTTPServer.rb
   ISAAC.rb
   KeyValueCoding.rb
   LRUCache.rb
   PageStore.rb
   read_multipart.rb
   Request.rb
   SciTE.properties
   Session.rb
   SessionStats.rb
   SessionStore.rb
   Tag.rb
   TemplateParser.rb
   WEBrickServlet.rb

require 'iowa'
require 'webrick'
require 'log4r'
include Log4r

# This is a _basic_ level of support.  I'm sure that I need to add things to
# deal with multipart/form-data forms for file uploads, and for providing some
# of the other information that is encapsulated in an Iowa::Request.

class Iowa::Request
	alias old_init initialize
	def initialize
		@headers_in = Iowa::R::Table.new
		@headers_out = Iowa::R::Table.new
		@params = {}
	end
end

class Iowa::WEBrickServlet < WEBrick::HTTPServlet::AbstractServlet

	#####
	#// This is the only magic.  It takes the place of the
	#// Iowa::handleConnection() method that is used when running in a
	#// non-webrick mode.
	#####
	def do_GET request, response
		start_time = Time.now
		status = 'OK'
		iowa_log = Logger['iowa_log']
		buffer = ""
		req = Iowa::Request.new
		req.uri = request.path.to_s
		req.request_time = request.request_time
		request.query.each do |k,v| req.params[ k ] = v end
		request.header.each do |k,v| req.headers_in[ k ] = v end
		read_time = Time.now
		
		context = nil
		exception = catch(:session_error) do
			begin
				context = Iowa::Context.new(req, buffer)
				Iowa.app.handleRequest(context)
			rescue Exception => exception
			end
		end

		if exception.to_s != '' and exception.kind_of? Exception
			buffer << "<p>#{exception}<br/>"
			buffer << exception.backtrace.join("<br/>\n").to_s
			buffer << "</p>"
			iowa_log.warn "Execution Error: #{exception} :: " + exception.backtrace.join(".....").to_s
			status = 'EOUT'
		end			

		response[ "Date" ] = "#{Time.now.asctime}"
		response[ "Pragma" ] = "no_cache"
		response[ "Connection" ] = "close"
		response[ "Content-Type" ] = req.content_type || "text/html"
		response[ "Content-Length" ] = buffer.length
		req.headers_out.each do |k,v| response[ k ] = v end

		response.body = context.response
		
		end_time = Time.now
		referer = req.headers_in['Referer'] != '' ? req.headers_in['Referer'] : request.uri
		iowa_log.info "#{start_time} (#{read_time.to_f - start_time.to_f}/#{end_time.to_f - start_time.to_f}) :: #{req.uri} #{status} #{buffer.length}B"
	end
	alias do_POST do_GET
end

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us