Added first draft for RESTful library
note: the interfaces are likely to change in the future
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
note
|
||||
description: "Summary description for {APP_ACCOUNT_VERIFY_CREDENTIAL}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
APP_ACCOUNT_VERIFY_CREDENTIAL
|
||||
|
||||
inherit
|
||||
APP_REQUEST_HANDLER
|
||||
redefine
|
||||
initialize,
|
||||
execute_unauthorized
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
do
|
||||
description := "Verify credentials"
|
||||
initialize
|
||||
end
|
||||
|
||||
initialize
|
||||
do
|
||||
Precursor
|
||||
enable_request_method_get
|
||||
enable_format_json
|
||||
enable_format_xml
|
||||
enable_format_text
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
authentication_required: BOOLEAN = True
|
||||
|
||||
feature -- Execution
|
||||
|
||||
execute_unauthorized (a_hdl_context: APP_REQUEST_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
|
||||
local
|
||||
s: STRING
|
||||
lst: LIST [STRING]
|
||||
do
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.unauthorized)
|
||||
res.write_header ({HTTP_STATUS_CODE}.unauthorized, <<["WWW-Authenticate", "Basic realm=%"My Silly demo auth, password must be the same as login such as foo:foo%""]>>)
|
||||
res.write_string ("Unauthorized")
|
||||
end
|
||||
|
||||
execute_application (ctx: APP_REQUEST_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
|
||||
local
|
||||
l_full: BOOLEAN
|
||||
h: EWF_HEADER
|
||||
l_login: STRING_8
|
||||
s: STRING
|
||||
content_type_supported: ARRAY [STRING]
|
||||
l_format_id: INTEGER
|
||||
do
|
||||
content_type_supported := <<{HTTP_CONSTANTS}.json_app, {HTTP_CONSTANTS}.xml_text, {HTTP_CONSTANTS}.plain_text>>
|
||||
l_format_id := ctx.request_format_id ("format", content_type_supported)
|
||||
if ctx.authenticated then
|
||||
l_full := attached ctx.query_parameter ("details") as v and then v.is_case_insensitive_equal ("true")
|
||||
if attached ctx.authenticated_identifier as log then
|
||||
l_login := log.as_string_8
|
||||
|
||||
create h.make
|
||||
|
||||
create s.make_empty
|
||||
inspect l_format_id
|
||||
when {HTTP_FORMAT_CONSTANTS}.json then
|
||||
h.put_content_type_text_plain
|
||||
s.append_string ("{ %"login%": %"" + l_login + "%" }%N")
|
||||
when {HTTP_FORMAT_CONSTANTS}.xml then
|
||||
h.put_content_type_text_xml
|
||||
s.append_string ("<login>" + l_login + "</login>%N")
|
||||
when {HTTP_FORMAT_CONSTANTS}.text then -- Default
|
||||
h.put_content_type_text_plain
|
||||
s.append_string ("login: " + l_login + "%N")
|
||||
else
|
||||
execute_content_type_not_allowed (req, res, content_type_supported,
|
||||
<<{HTTP_FORMAT_CONSTANTS}.json_name, {HTTP_FORMAT_CONSTANTS}.html_name, {HTTP_FORMAT_CONSTANTS}.xml_name, {HTTP_FORMAT_CONSTANTS}.text_name>>
|
||||
)
|
||||
end
|
||||
if not s.is_empty then
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
||||
res.write_headers_string (h.string)
|
||||
res.write_string (s)
|
||||
end
|
||||
else
|
||||
send_error (ctx.path, 0, "User/password unknown", Void, ctx, req, res)
|
||||
end
|
||||
else
|
||||
send_error (ctx.path, 0, "Authentication rejected", Void, ctx, req, res)
|
||||
end
|
||||
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
|
||||
95
library/server/request/rest/tests/src/app/app_test.e
Normal file
95
library/server/request/rest/tests/src/app/app_test.e
Normal file
@@ -0,0 +1,95 @@
|
||||
note
|
||||
description: "Summary description for {APP_TEST}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
APP_TEST
|
||||
|
||||
inherit
|
||||
APP_REQUEST_HANDLER
|
||||
redefine
|
||||
initialize
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
do
|
||||
description := "Return a simple test output "
|
||||
initialize
|
||||
end
|
||||
|
||||
initialize
|
||||
do
|
||||
Precursor
|
||||
enable_request_method_get
|
||||
enable_format_text
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
authentication_required: BOOLEAN = False
|
||||
|
||||
feature -- Execution
|
||||
|
||||
execute_application (ctx: APP_REQUEST_HANDLER_CONTEXT; req: WGI_REQUEST; res: WGI_RESPONSE_BUFFER)
|
||||
-- Execute request handler
|
||||
local
|
||||
s: STRING
|
||||
h: EWF_HEADER
|
||||
do
|
||||
create h.make
|
||||
h.put_content_type_text_plain
|
||||
|
||||
create s.make_empty
|
||||
s.append_string ("test")
|
||||
if attached req.meta_variable ("REQUEST_COUNT") as l_request_count then
|
||||
s.append_string ("(request_count="+ l_request_count +")%N")
|
||||
end
|
||||
|
||||
-- ctx.request_format_id ("format", Void)
|
||||
|
||||
if attached ctx.request_format ("format", Void) as l_format then
|
||||
s.append_string (" format=" + l_format + "%N")
|
||||
end
|
||||
|
||||
if attached ctx.parameter ("op") as l_op then
|
||||
s.append_string (" op=" + l_op)
|
||||
if l_op.same_string ("crash") then
|
||||
(create {DEVELOPER_EXCEPTION}).raise
|
||||
elseif l_op.starts_with ("env") then
|
||||
s.append_string ("%N%NAll variables:")
|
||||
s.append (string_hash_table_string_string (req.parameters.new_cursor, False))
|
||||
s.append_string ("<br/>script_url(%"" + req.path_info + "%")=" + ctx.script_url (req.path_info) + "%N")
|
||||
-- if attached ctx.http_authorization_login_password as t then
|
||||
-- s.append_string ("Check login=" + t.login + "<br/>%N")
|
||||
-- end
|
||||
if ctx.authenticated and then attached ctx.authenticated_identifier as l_login then
|
||||
s.append_string ("Authenticated: login=" + l_login.as_string_8 + "<br/>%N")
|
||||
end
|
||||
end
|
||||
else
|
||||
s.append ("%N Try " + ctx.script_absolute_url (req.path_info + "?op=env") + " to display all variables%N")
|
||||
s.append ("%N Try " + ctx.script_absolute_url (req.path_info + "?op=crash") + " to demonstrate exception trace%N")
|
||||
end
|
||||
|
||||
res.set_status_code (200)
|
||||
res.write_headers_string (h.string)
|
||||
res.write_string (s)
|
||||
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
|
||||
Reference in New Issue
Block a user