Added first draft for RESTful library
note: the interfaces are likely to change in the future
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
note
|
||||
description: "Summary description for {APP_APPLICATION}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
APP_APPLICATION
|
||||
|
||||
inherit
|
||||
REST_APPLICATION [APP_REQUEST_HANDLER, APP_REQUEST_HANDLER_CONTEXT]
|
||||
redefine
|
||||
router
|
||||
end
|
||||
|
||||
feature {NONE} -- Router
|
||||
|
||||
router: APP_REQUEST_ROUTER
|
||||
|
||||
;note
|
||||
copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
5949 Hollister Ave., Goleta, CA 93117 USA
|
||||
Telephone 805-685-1006, Fax 805-685-6869
|
||||
Website http://www.eiffel.com
|
||||
Customer support http://support.eiffel.com
|
||||
]"
|
||||
end
|
||||
@@ -0,0 +1,32 @@
|
||||
note
|
||||
description: "Summary description for REST_REQUEST_AGENT_HANDLER."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
APP_REQUEST_AGENT_HANDLER
|
||||
|
||||
inherit
|
||||
APP_REQUEST_HANDLER
|
||||
undefine
|
||||
execute, pre_execute, post_execute
|
||||
end
|
||||
|
||||
REST_REQUEST_AGENT_HANDLER [APP_REQUEST_HANDLER_CONTEXT]
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
|
||||
note
|
||||
copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
5949 Hollister Ave., Goleta, CA 93117 USA
|
||||
Telephone 805-685-1006, Fax 805-685-6869
|
||||
Website http://www.eiffel.com
|
||||
Customer support http://support.eiffel.com
|
||||
]"
|
||||
end
|
||||
@@ -0,0 +1,60 @@
|
||||
note
|
||||
description : "Objects that ..."
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
|
||||
deferred class
|
||||
APP_REQUEST_HANDLER
|
||||
|
||||
inherit
|
||||
REST_REQUEST_HANDLER [APP_REQUEST_HANDLER_CONTEXT]
|
||||
|
||||
APP_REQUEST_HELPER
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
string_hash_table_string_string (ht: HASH_TABLE_ITERATION_CURSOR [READABLE_STRING_GENERAL, READABLE_STRING_GENERAL]; using_pre: BOOLEAN): STRING_8
|
||||
do
|
||||
create Result.make (100)
|
||||
if using_pre then
|
||||
Result.append ("<pre>")
|
||||
end
|
||||
from
|
||||
ht.start
|
||||
until
|
||||
ht.after
|
||||
loop
|
||||
Result.append_string (ht.key.as_string_8 + " = " + ht.item.as_string_8 + "%N")
|
||||
ht.forth
|
||||
end
|
||||
if using_pre then
|
||||
Result.append ("</pre>")
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Helpers
|
||||
|
||||
format_id (s: detachable STRING): INTEGER
|
||||
do
|
||||
Result := {HTTP_FORMAT_CONSTANTS}.text
|
||||
if s /= Void then
|
||||
Result := format_constants.format_id (s)
|
||||
end
|
||||
end
|
||||
|
||||
exit_with_code (a_code: INTEGER)
|
||||
do
|
||||
(create {EXCEPTIONS}).die (a_code)
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
5949 Hollister Ave., Goleta, CA 93117 USA
|
||||
Telephone 805-685-1006, Fax 805-685-6869
|
||||
Website http://www.eiffel.com
|
||||
Customer support http://support.eiffel.com
|
||||
]"
|
||||
end
|
||||
@@ -0,0 +1,86 @@
|
||||
note
|
||||
description : "Objects that ..."
|
||||
author : "$Author$"
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
|
||||
class
|
||||
APP_REQUEST_HANDLER_CONTEXT
|
||||
|
||||
inherit
|
||||
REST_REQUEST_URI_TEMPLATE_HANDLER_CONTEXT
|
||||
redefine
|
||||
authenticated,
|
||||
authenticated_identifier
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Auth
|
||||
|
||||
authenticated: BOOLEAN
|
||||
do
|
||||
if attached request.http_authorization as l_http_auth then
|
||||
Result := True
|
||||
end
|
||||
end
|
||||
|
||||
authenticated_identifier: detachable READABLE_STRING_32
|
||||
do
|
||||
if authenticated then
|
||||
Result := "foo"
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Format
|
||||
|
||||
get_format_id (a_format_variable_name: detachable READABLE_STRING_GENERAL; a_content_type_supported: detachable ARRAY [STRING_8])
|
||||
do
|
||||
if internal_format_id = 0 then
|
||||
internal_format_id := request_format_id (a_format_variable_name, a_content_type_supported)
|
||||
end
|
||||
end
|
||||
|
||||
get_format_name (a_format_variable_name: detachable READABLE_STRING_GENERAL; a_content_type_supported: detachable ARRAY [STRING_8])
|
||||
do
|
||||
if internal_format_name = Void then
|
||||
internal_format_name := request_format (a_format_variable_name, a_content_type_supported)
|
||||
end
|
||||
end
|
||||
|
||||
format_id: INTEGER
|
||||
do
|
||||
if internal_format_id = 0 then
|
||||
get_format_id (Void, Void)
|
||||
end
|
||||
Result := internal_format_id
|
||||
end
|
||||
|
||||
format_name: detachable READABLE_STRING_8
|
||||
do
|
||||
Result := internal_format_name
|
||||
if Result = Void then
|
||||
Result := request_format (Void, Void)
|
||||
internal_format_name := Result
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Internal
|
||||
|
||||
internal_format_id: like format_id
|
||||
|
||||
internal_format_name: like format_name
|
||||
|
||||
|
||||
;note
|
||||
copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
5949 Hollister Ave., Goleta, CA 93117 USA
|
||||
Telephone 805-685-1006, Fax 805-685-6869
|
||||
Website http://www.eiffel.com
|
||||
Customer support http://support.eiffel.com
|
||||
]"
|
||||
end
|
||||
@@ -0,0 +1,101 @@
|
||||
note
|
||||
description: "Summary description for {APP_REQUEST_HELPER}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
APP_REQUEST_HELPER
|
||||
|
||||
feature -- Helpers
|
||||
|
||||
send_error (a_path: STRING; a_error_id: INTEGER; a_error_name: STRING; a_error_message: detachable STRING; ctx: APP_REQUEST_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
|
||||
local
|
||||
s: STRING
|
||||
i,nb: INTEGER
|
||||
rep_data: REST_RESPONSE
|
||||
do
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.expectation_failed)
|
||||
create rep_data.make (a_path)
|
||||
rep_data.headers.put_content_type_text_plain
|
||||
|
||||
create s.make_empty
|
||||
inspect ctx.format_id
|
||||
when {HTTP_FORMAT_CONSTANTS}.json then
|
||||
rep_data.headers.put_content_type_text_plain
|
||||
s := "{%"application%": %"" + a_path + "%""
|
||||
s.append_string (", %"error%": {")
|
||||
s.append_string ("%"id%": " + a_error_id.out)
|
||||
s.append_string (",%"name%": %"" + a_error_name + "%"")
|
||||
if a_error_message /= Void then
|
||||
s.append_string (",%"message%": %"")
|
||||
|
||||
if a_error_message.has ('%N') then
|
||||
from
|
||||
i := s.count
|
||||
s.append_string (a_error_message)
|
||||
nb := s.count
|
||||
until
|
||||
i > nb
|
||||
loop
|
||||
inspect s[i]
|
||||
when '%R' then
|
||||
if s.valid_index (i+1) and then s[i+1] = '%N' then
|
||||
s[i] := '\'
|
||||
s[i+1] := 'n'
|
||||
i := i + 1
|
||||
end
|
||||
when '%N' then
|
||||
s.insert_character ('\', i)
|
||||
s[i] := 'n'
|
||||
else
|
||||
end
|
||||
i := i + 1
|
||||
end
|
||||
else
|
||||
s.append_string (a_error_message)
|
||||
end
|
||||
s.append_string ("%"")
|
||||
end
|
||||
|
||||
s.append_string ("}") -- end error
|
||||
s.append_string ("}") -- end global object
|
||||
rep_data.set_message (s)
|
||||
when {HTTP_FORMAT_CONSTANTS}.xml then
|
||||
rep_data.headers.put_content_type_text_xml
|
||||
s := "<application path=%"" + a_path + "%"><error id=%"" + a_error_id.out + "%" name=%""+ a_error_name +"%">"
|
||||
if a_error_message /= Void then
|
||||
s.append_string (a_error_message)
|
||||
end
|
||||
s.append_string ("</error></application>")
|
||||
rep_data.set_message (s)
|
||||
when {HTTP_FORMAT_CONSTANTS}.html then
|
||||
rep_data.headers.put_content_type_text_html
|
||||
s := "<strong>application</strong>: " + a_path + "<br/>%N<strong>Error</strong> (" + a_error_id.out + ") %"" + a_error_name + "%"<br/>%N"
|
||||
if a_error_message /= Void then
|
||||
s.append_string ("<blockquote>" + a_error_message + "</blockquote>")
|
||||
end
|
||||
rep_data.set_message (s)
|
||||
when {HTTP_FORMAT_CONSTANTS}.text then -- Default
|
||||
s := "Application: " + a_path + "<br/>%N"
|
||||
s.append_string ("Error (" + a_error_id.out + ") %"" + a_error_name + "%"%N")
|
||||
if a_error_message /= Void then
|
||||
s.append_string ("%T" + a_error_message + "%N")
|
||||
end
|
||||
rep_data.set_message (s)
|
||||
end
|
||||
rep_data.send (res)
|
||||
rep_data.recycle
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
5949 Hollister Ave., Goleta, CA 93117 USA
|
||||
Telephone 805-685-1006, Fax 805-685-6869
|
||||
Website http://www.eiffel.com
|
||||
Customer support http://support.eiffel.com
|
||||
]"
|
||||
end
|
||||
@@ -0,0 +1,26 @@
|
||||
note
|
||||
description: "Summary description for {REST_REQUEST_URI_TEMPLATE_ROUTER}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
APP_REQUEST_ROUTER
|
||||
|
||||
inherit
|
||||
REST_REQUEST_URI_TEMPLATE_ROUTER [APP_REQUEST_HANDLER, APP_REQUEST_HANDLER_CONTEXT]
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
note
|
||||
copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
5949 Hollister Ave., Goleta, CA 93117 USA
|
||||
Telephone 805-685-1006, Fax 805-685-6869
|
||||
Website http://www.eiffel.com
|
||||
Customer support http://support.eiffel.com
|
||||
]"
|
||||
end
|
||||
@@ -0,0 +1,40 @@
|
||||
note
|
||||
description: "Summary description for {APP_REQUEST_ROUTING_HANDLER}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
APP_REQUEST_ROUTING_HANDLER
|
||||
|
||||
inherit
|
||||
APP_REQUEST_HANDLER
|
||||
undefine
|
||||
execute,
|
||||
pre_execute,
|
||||
post_execute
|
||||
end
|
||||
|
||||
REST_REQUEST_URI_TEMPLATE_ROUTING_HANDLER [APP_REQUEST_HANDLER, APP_REQUEST_HANDLER_CONTEXT]
|
||||
redefine
|
||||
router
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Routing
|
||||
|
||||
router: APP_REQUEST_ROUTER
|
||||
|
||||
;note
|
||||
copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
5949 Hollister Ave., Goleta, CA 93117 USA
|
||||
Telephone 805-685-1006, Fax 805-685-6869
|
||||
Website http://www.eiffel.com
|
||||
Customer support http://support.eiffel.com
|
||||
]"
|
||||
end
|
||||
Reference in New Issue
Block a user