PageRenderTime 20ms CodeModel.GetById 17ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/library/server/httpd/interface/httpd_application.e

http://github.com/jocelyn/EiffelWebReloaded
Specman e | 142 lines | 105 code | 19 blank | 18 comment | 5 complexity | 8f38d0ed84e17c3da38661921d6e20c1 MD5 | raw file
  1note
  2	description: "Summary description for {HTTPD_APPLICATION}."
  3	legal: "See notice at end of class."
  4	status: "See notice at end of class."
  5	date: "$Date$"
  6	revision: "$Revision$"
  7
  8deferred class
  9	HTTPD_APPLICATION
 10
 11feature -- Basic operation
 12
 13	launch
 14		deferred
 15		end
 16
 17feature -- Execution
 18
 19	call_execute (a_variables: HASH_TABLE [STRING, STRING]; a_input: HTTPD_SERVER_INPUT; a_output: HTTPD_SERVER_OUTPUT)
 20			-- Call execute
 21			--| Note: you can redefine this feature, if you want to optimize
 22			--| as much as possible a very simple query
 23			--| without fetching GET, POST, ... data
 24		local
 25			rescued: BOOLEAN
 26			ctx: detachable like new_request_context
 27		do
 28			if not rescued then
 29				pre_execute
 30				ctx := new_request_context (a_variables, a_input, a_output)
 31				execute (ctx)
 32				post_execute (ctx)
 33			else
 34				rescue_execute (ctx, (create {EXCEPTION_MANAGER}).last_exception)
 35			end
 36		rescue
 37			rescued := True
 38			retry
 39		end
 40
 41	pre_execute
 42			-- Operation processed before `execute'
 43		do
 44		end
 45
 46	post_execute (ctx: detachable like new_request_context)
 47			-- Operation processed after `execute', or after `rescue_execute'
 48		do
 49			if ctx /= Void then
 50				ctx.recycle
 51			end
 52		end
 53
 54	rescue_execute (ctx: detachable like new_request_context; e: detachable EXCEPTION)
 55			-- Operation processed after `execute', or on rescue
 56		do
 57			post_execute (ctx)
 58		end
 59
 60	execute (ctx: like new_request_context)
 61			-- Execute the request
 62		deferred
 63		end
 64
 65feature {NONE} -- Context
 66
 67	request_count: INTEGER
 68			-- Current request count
 69		deferred
 70		end
 71
 72	new_request_context (a_vars: HASH_TABLE [STRING, STRING]; a_input: HTTPD_SERVER_INPUT; a_output: HTTPD_SERVER_OUTPUT): HTTPD_REQUEST_CONTEXT
 73			-- New httpd environment based on `a_vars' and `input'
 74			--| note: you can redefine this function to create your own
 75			--| descendant of HTTPD_REQUEST_CONTEXT , or even to reuse/recycle existing
 76			--| instance of HTTPD_REQUEST_CONTEXT
 77		do
 78			create Result.make (a_vars, a_input, a_output)
 79		end
 80
 81feature -- Output: helpers
 82
 83	http_put_exception_trace (ctx: like new_request_context)
 84			-- Print exception trace is any
 85		do
 86			if attached (create {EXCEPTIONS}).exception_trace as l_trace then
 87				http_put_string ("Exception occurred%N", ctx)
 88				http_put_string ("<pre>" + l_trace + "</pre>", ctx)
 89				http_flush (ctx)
 90			end
 91		end
 92
 93	http_put_file_content (fn: STRING; ctx: like new_request_context)
 94			-- Send the content of file `fn'
 95		local
 96			f: RAW_FILE
 97			o: like {HTTPD_REQUEST_CONTEXT}.output
 98		do
 99			create f.make (fn)
100			if f.exists and then f.is_readable then
101				o := ctx.output
102				f.open_read
103				from
104				until
105					f.exhausted
106				loop
107					f.read_stream (1024)
108					o.put_string (f.last_string)
109				end
110				f.close
111			end
112		end
113
114	http_put_header_line (s: STRING; ctx: like new_request_context)
115			-- Send `s' to http client as header line
116		do
117			ctx.output.put_header_line (s)
118		end
119
120	http_put_string (s: STRING; ctx: like new_request_context)
121			-- Send `s' to http client
122		do
123			ctx.output.put_string (s)
124		end
125
126	http_flush (ctx: like new_request_context)
127			-- Flush the output to http client	
128		do
129			ctx.output.flush
130		end
131
132note
133	copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
134	license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
135	source: "[
136			Eiffel Software
137			5949 Hollister Ave., Goleta, CA 93117 USA
138			Telephone 805-685-1006, Fax 805-685-6869
139			Website http://www.eiffel.com
140			Customer support http://support.eiffel.com
141		]"
142end