Removed default handler for WSF_ROUTER
Added WSF_ROUTE to replace a TUPLE [H, C] WSF_ROUTER.route (req): detachable WSF_ROUTE WSF_ROUTER.execute_route (a_route, req, res) To help usage of Routers Remove WSF_HANDLER_CONTEXT obsolete features. Added comments
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
note
|
||||
description: "Summary description for {WSF_ROUTER}."
|
||||
author: ""
|
||||
description: "[
|
||||
URL dispatcher/router based on deferred mapping (to be defined in descendant)
|
||||
The associated context {WSF_HANDLER_CONTEXT} does contains information related to the matching at runtime.
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
@@ -27,14 +29,6 @@ feature -- Status report
|
||||
|
||||
feature -- Mapping
|
||||
|
||||
map_default (h: like default_handler)
|
||||
-- Map default handler
|
||||
-- If no route/handler is found,
|
||||
-- then use `default_handler' as default if not Void
|
||||
do
|
||||
set_default_handler (h)
|
||||
end
|
||||
|
||||
map (a_resource: READABLE_STRING_8; h: H)
|
||||
-- Map handler `h' with `a_resource'
|
||||
require
|
||||
@@ -61,12 +55,14 @@ feature -- Mapping
|
||||
feature -- Mapping agent
|
||||
|
||||
map_agent (a_resource: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE]])
|
||||
-- Map `a_action' as an handler with `a_resource'
|
||||
do
|
||||
map_agent_with_request_methods (a_resource, a_action, Void)
|
||||
end
|
||||
|
||||
map_agent_with_request_methods (a_resource: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE]];
|
||||
rqst_methods: detachable ARRAY [READABLE_STRING_8])
|
||||
-- Map `a_action' as an handler with `a_resource' and `rqst_methods'
|
||||
local
|
||||
rah: WSF_AGENT_HANDLER [C]
|
||||
do
|
||||
@@ -80,17 +76,19 @@ feature -- Mapping agent
|
||||
|
||||
feature -- Mapping response agent
|
||||
|
||||
map_agent_response (a_resource: READABLE_STRING_8; a_action: FUNCTION [ANY, TUPLE [ctx: C; req: WSF_REQUEST], WSF_RESPONSE_MESSAGE])
|
||||
map_agent_response (a_resource: READABLE_STRING_8; a_function: FUNCTION [ANY, TUPLE [ctx: C; req: WSF_REQUEST], WSF_RESPONSE_MESSAGE])
|
||||
-- Map response as Result `a_function' as an handler with `a_resource'
|
||||
do
|
||||
map_agent_response_with_request_methods (a_resource, a_action, Void)
|
||||
map_agent_response_with_request_methods (a_resource, a_function, Void)
|
||||
end
|
||||
|
||||
map_agent_response_with_request_methods (a_resource: READABLE_STRING_8; a_action: FUNCTION [ANY, TUPLE [ctx: C; req: WSF_REQUEST], WSF_RESPONSE_MESSAGE];
|
||||
map_agent_response_with_request_methods (a_resource: READABLE_STRING_8; a_function: FUNCTION [ANY, TUPLE [ctx: C; req: WSF_REQUEST], WSF_RESPONSE_MESSAGE];
|
||||
rqst_methods: detachable ARRAY [READABLE_STRING_8])
|
||||
-- Map response as Result `a_function' as an handler with `a_resource' and `rqst_methods'
|
||||
local
|
||||
rah: WSF_AGENT_RESPONSE_HANDLER [C]
|
||||
do
|
||||
create rah.make (a_action)
|
||||
create rah.make (a_function)
|
||||
if attached {H} rah as h then
|
||||
map_with_request_methods (a_resource, h, rqst_methods)
|
||||
else
|
||||
@@ -120,36 +118,47 @@ feature -- Element change
|
||||
|
||||
feature -- Execution
|
||||
|
||||
route (req: WSF_REQUEST): detachable WSF_ROUTE [H, C]
|
||||
-- Route matching `req'.
|
||||
do
|
||||
Result := matching_route (req)
|
||||
end
|
||||
|
||||
execute_route (a_route: WSF_ROUTE [H,C]; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Process route `a_route'
|
||||
require
|
||||
a_route_attached: a_route /= Void
|
||||
do
|
||||
a_route.handler.execute (a_route.context, req, res)
|
||||
end
|
||||
|
||||
dispatch (req: WSF_REQUEST; res: WSF_RESPONSE): BOOLEAN
|
||||
-- Dispatch `req, res' to the associated handler
|
||||
-- And return True is handled, otherwise False
|
||||
do
|
||||
Result := dispatch_and_return_handler (req, res) /= Void
|
||||
if attached route (req) as r then
|
||||
Result := True
|
||||
execute_route (r, req, res)
|
||||
end
|
||||
end
|
||||
|
||||
dispatch_and_return_handler (req: WSF_REQUEST; res: WSF_RESPONSE): detachable H
|
||||
-- Dispatch `req, res' to the associated handler
|
||||
-- And return this handler
|
||||
-- If Result is Void, this means no handler was found.
|
||||
local
|
||||
d: like handler
|
||||
ctx: detachable like default_handler_context
|
||||
do
|
||||
d := handler (req)
|
||||
if d /= Void then
|
||||
Result := d.handler
|
||||
ctx := d.context
|
||||
else
|
||||
Result := default_handler
|
||||
if Result /= Void then
|
||||
ctx := default_handler_context (req)
|
||||
end
|
||||
if attached route (req) as r then
|
||||
Result := r.handler
|
||||
execute_route (r, req, res)
|
||||
end
|
||||
if Result /= Void and ctx /= Void then
|
||||
Result.execute (ctx, req, res)
|
||||
end
|
||||
ensure
|
||||
result_void_implie_no_default: Result = Void implies default_handler = Void
|
||||
end
|
||||
|
||||
feature {WSF_ROUTED_SERVICE_I} -- Implementation
|
||||
|
||||
default_handler_context (req: WSF_REQUEST): C
|
||||
-- Default handler context associated with `req'.
|
||||
--| It can be used to build a context if needed.
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- status report
|
||||
@@ -183,8 +192,8 @@ feature {WSF_ROUTED_SERVICE_I} -- Handler
|
||||
Result := req.path_info
|
||||
end
|
||||
|
||||
handler (req: WSF_REQUEST): detachable TUPLE [handler: H; context: like default_handler_context]
|
||||
-- Handler whose map matched with `req'
|
||||
matching_route (req: WSF_REQUEST): detachable WSF_ROUTE [H, C]
|
||||
-- Handler whose map matched with `req' with associated Context
|
||||
require
|
||||
req_valid: source_uri (req) /= Void
|
||||
deferred
|
||||
@@ -194,21 +203,21 @@ feature {WSF_ROUTED_SERVICE_I} -- Handler
|
||||
|
||||
feature {NONE} -- Access: Implementation
|
||||
|
||||
is_matching_request_methods (a_request_method: READABLE_STRING_GENERAL; rqst_methods: like formatted_request_methods): BOOLEAN
|
||||
-- `a_request_method' is matching `rqst_methods' contents
|
||||
is_matching_request_methods (a_request_method: READABLE_STRING_GENERAL; a_rqst_methods: like formatted_request_methods): BOOLEAN
|
||||
-- `a_request_method' is matching `a_rqst_methods' contents
|
||||
local
|
||||
i,n: INTEGER
|
||||
m: READABLE_STRING_GENERAL
|
||||
do
|
||||
if rqst_methods /= Void and then not rqst_methods.is_empty then
|
||||
if a_rqst_methods /= Void and then not a_rqst_methods.is_empty then
|
||||
m := a_request_method
|
||||
from
|
||||
i := rqst_methods.lower
|
||||
n := rqst_methods.upper
|
||||
i := a_rqst_methods.lower
|
||||
n := a_rqst_methods.upper
|
||||
until
|
||||
i > n or Result
|
||||
loop
|
||||
Result := m.same_string (rqst_methods[i])
|
||||
Result := m.same_string (a_rqst_methods [i])
|
||||
i := i + 1
|
||||
end
|
||||
else
|
||||
@@ -236,27 +245,6 @@ feature {NONE} -- Access: Implementation
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
set_default_handler (h: like default_handler)
|
||||
-- Set `default_handler' to `h'
|
||||
deferred
|
||||
ensure
|
||||
default_handler_set: h = default_handler
|
||||
end
|
||||
|
||||
default_handler: detachable H
|
||||
-- Default handler
|
||||
deferred
|
||||
end
|
||||
|
||||
default_handler_context (req: WSF_REQUEST): C
|
||||
-- Default handler context associated with `default_handler'
|
||||
require
|
||||
has_default_handler: default_handler /= Void
|
||||
deferred
|
||||
end
|
||||
|
||||
;note
|
||||
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
|
||||
Reference in New Issue
Block a user