PageRenderTime 92ms CodeModel.GetById 89ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/library/server/rest/interface/rest_application.e

http://github.com/jocelyn/EiffelWebReloaded
Specman e | 85 lines | 69 code | 13 blank | 3 comment | 3 complexity | f149a903c4f4863959921251e6806f67 MD5 | raw file
 1note
 2	description : "Objects that ..."
 3	author      : "$Author$"
 4	date        : "$Date$"
 5	revision    : "$Revision$"
 6
 7deferred class
 8	REST_APPLICATION
 9
10inherit
11	HTTPD_APPLICATION
12		redefine
13			new_request_context
14		end
15
16feature {NONE} -- Handlers
17
18	handler_manager: REST_REQUEST_HANDLER_MANAGER
19		deferred
20		end
21
22feature {NONE} -- Environment
23
24	new_request_context (a_vars: HASH_TABLE [STRING, STRING]; a_input: HTTPD_SERVER_INPUT; a_output: HTTPD_SERVER_OUTPUT): REST_REQUEST_CONTEXT
25		do
26			create Result.make (a_vars, a_input, a_output)
27			Result.environment_variables.add_variable (request_count.out, "REQUEST_COUNT")
28		end
29
30feature -- Execution
31
32	execute (ctx: like new_request_context)
33		local
34			rescued: INTEGER
35			rq: detachable REST_REQUEST_HANDLER
36		do
37			if rescued = 0 then
38				rq := handler_manager.handler (ctx)
39				if rq = Void then
40					rq := handler_manager.smart_handler (ctx)
41				end
42				if rq /= Void then
43					rq.execute (ctx)
44				else
45					execute_default (ctx)
46				end
47			elseif rescued = 1 then
48				execute_rescue (ctx)
49			else
50				-- Bye Bye
51				exit_with_code (-1)
52			end
53		rescue
54			rescued := rescued + 1
55			retry
56		end
57
58	execute_default (ctx: like new_request_context)
59			-- Execute the default behavior
60		deferred
61		end
62
63	execute_rescue (ctx: like new_request_context)
64			-- Execute the default rescue behavior
65		deferred
66		end
67
68feature -- Execution
69
70	exit_with_code (a_code: INTEGER)
71		do
72			(create {EXCEPTIONS}).die (a_code)
73		end
74
75note
76	copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
77	license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
78	source: "[
79			Eiffel Software
80			5949 Hollister Ave., Goleta, CA 93117 USA
81			Telephone 805-685-1006, Fax 805-685-6869
82			Website http://www.eiffel.com
83			Customer support http://support.eiffel.com
84		]"
85end