Applied new ROUTER design to the whole EWF project.

This commit is contained in:
Jocelyn Fiat
2012-09-25 23:18:17 +02:00
parent 0503e63209
commit 28186efbe7
61 changed files with 960 additions and 1129 deletions

View File

@@ -5,16 +5,27 @@ note
revision: "$Revision$"
class
AUTHENTICATION_FILTER [C -> WSF_URI_TEMPLATE_HANDLER_CONTEXT]
AUTHENTICATION_FILTER
inherit
WSF_FILTER_HANDLER [C]
WSF_FILTER_HANDLER [WSF_URI_TEMPLATE_HANDLER]
SHARED_DATABASE_API
WSF_URI_TEMPLATE_HANDLER
WSF_RESOURCE_HANDLER_HELPER
-- redefine
-- do_get
-- end
SHARED_DATABASE_API
SHARED_EJSON
feature -- Basic operations
execute (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute the filter
local
l_auth: HTTP_AUTHORIZATION
@@ -24,15 +35,24 @@ feature -- Basic operations
attached Db_access.users.item (1) as l_user and then
(attached l_auth.login as l_auth_login and then l_auth_login.is_equal (l_user.name)
and attached l_auth.password as l_auth_password and then l_auth_password.is_equal (l_user.password)) then
execute_next (ctx, req, res)
execute_next (req, res)
else
handle_unauthorized ("Unauthorized", ctx, req, res)
handle_unauthorized ("Unauthorized", req, res)
end
end
feature -- Filter
execute_next (req: WSF_REQUEST; res: WSF_RESPONSE)
do
if attached next as n then
n.execute (req, res)
end
end
feature {NONE} -- Implementation
handle_unauthorized (a_description: STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
handle_unauthorized (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE)
-- Handle forbidden.
local
h: HTTP_HEADER

View File

@@ -10,7 +10,7 @@ class
inherit
ANY
WSF_URI_TEMPLATE_FILTERED_SERVICE
WSF_FILTERED_SERVICE
WSF_HANDLER_HELPER
@@ -34,18 +34,21 @@ feature {NONE} -- Initialization
create_filter
-- Create `filter'
local
l_router: WSF_URI_TEMPLATE_ROUTER
l_authentication_filter: AUTHENTICATION_FILTER [WSF_URI_TEMPLATE_HANDLER_CONTEXT]
l_user_filter: USER_HANDLER [WSF_URI_TEMPLATE_HANDLER_CONTEXT]
l_user_handler: WSF_HANDLER [WSF_URI_TEMPLATE_HANDLER_CONTEXT]
l_routing_filter: WSF_ROUTING_FILTER [WSF_HANDLER [WSF_URI_TEMPLATE_HANDLER_CONTEXT], WSF_URI_TEMPLATE_HANDLER_CONTEXT]
l_router: WSF_ROUTER
l_authentication_filter_hdl: AUTHENTICATION_FILTER
l_user_filter: USER_HANDLER
l_user_handler: WSF_URI_TEMPLATE_HANDLER
-- l_routing_hdl: WSF_URI_TEMPLATE_ROUTING_HANDLER --[WSF_HANDLER [WSF_URI_TEMPLATE_HANDLER_CONTEXT], WSF_URI_TEMPLATE_HANDLER_CONTEXT]
l_routing_filter: WSF_ROUTING_FILTER
do
create l_router.make (1)
create l_authentication_filter
create l_authentication_filter_hdl
create l_user_filter
l_authentication_filter.set_next (l_user_filter)
l_user_handler := l_authentication_filter
l_router.map_with_request_methods ("/user/{userid}", l_user_handler, << "GET" >>)
l_authentication_filter_hdl.set_next (l_user_filter)
l_user_handler := l_authentication_filter_hdl
l_router.handle_with_request_methods ("/user/{userid}", l_user_handler, l_router.methods_get)
-- l_router.map_with_request_methods ("/user/{userid}", l_user_handler, << "GET" >>)
-- create l_routing_hdl.make_with_router (l_router)
create l_routing_filter.make (l_router)
l_routing_filter.set_execute_default_action (agent execute_default)
filter := l_routing_filter

View File

@@ -5,12 +5,14 @@ note
revision: "$Revision$"
class
USER_HANDLER [C -> WSF_HANDLER_CONTEXT]
USER_HANDLER
inherit
WSF_FILTER_HANDLER [C]
WSF_FILTER_HANDLER [WSF_URI_TEMPLATE_HANDLER]
WSF_RESOURCE_HANDLER_HELPER [C]
WSF_URI_TEMPLATE_HANDLER
WSF_RESOURCE_HANDLER_HELPER
redefine
do_get
end
@@ -21,13 +23,13 @@ inherit
feature -- Basic operations
execute (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (ctx, req, res)
execute_methods (req, res)
end
do_get (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Using GET to retrieve resource information.
-- If the GET request is SUCCESS, we response with
-- 200 OK, and a representation of the user
@@ -39,16 +41,16 @@ feature -- Basic operations
if attached req.orig_path_info as orig_path then
id := get_user_id_from_path (orig_path)
if attached retrieve_user (id) as l_user then
compute_response_get (ctx, req, res, l_user)
compute_response_get (req, res, l_user)
else
handle_resource_not_found_response ("The following resource " + orig_path + " is not found ", ctx, req, res)
handle_resource_not_found_response ("The following resource " + orig_path + " is not found ", req, res)
end
end
end
feature {NONE} -- Implementation
compute_response_get (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE; l_user : USER)
compute_response_get (req: WSF_REQUEST; res: WSF_RESPONSE; l_user : USER)
local
h: HTTP_HEADER
l_msg : STRING