Added missing "context" classes for uri and starts_with mapping+handler (and helper classes).

So that it is address more needs.
Factorized code between "context" and non context classes.
This commit is contained in:
Jocelyn Fiat
2012-12-13 10:58:08 +01:00
parent 025457747b
commit cb034fc94e
27 changed files with 778 additions and 215 deletions

View File

@@ -0,0 +1,31 @@
note
description: "Summary description for {WSF_URI_TEMPLATE_AGENT_CONTEXT_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_URI_TEMPLATE_AGENT_CONTEXT_HANDLER [C -> WSF_HANDLER_CONTEXT create make end]
inherit
WSF_URI_TEMPLATE_CONTEXT_HANDLER [C]
WSF_AGENT_CONTEXT_HANDLER [C]
rename
set_action as make
end
create
make
note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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

View File

@@ -0,0 +1,47 @@
note
description: "Summary description for {WSF_URI_TEMPLATE_CONTEXT_ROUTED_SERVICE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_URI_TEMPLATE_CONTEXT_ROUTED_SERVICE [C -> WSF_HANDLER_CONTEXT create make end]
inherit
WSF_ROUTED_SERVICE
feature -- Mapping helper: uri
map_uri_template (a_tpl: READABLE_STRING_8; h: WSF_URI_TEMPLATE_CONTEXT_HANDLER [C])
do
map_uri_template_with_request_methods (a_tpl, h, Void)
end
map_uri_template_with_request_methods (a_tpl: READABLE_STRING_8; h: WSF_URI_TEMPLATE_CONTEXT_HANDLER [C]; rqst_methods: detachable WSF_ROUTER_METHODS)
do
router.map_with_request_methods (create {WSF_URI_TEMPLATE_CONTEXT_MAPPING [C]}.make (a_tpl, h), rqst_methods)
end
feature -- Mapping helper: uri agent
map_uri_template_agent (a_tpl: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE]])
do
map_uri_template_agent_with_request_methods (a_tpl, proc, Void)
end
map_uri_template_agent_with_request_methods (a_tpl: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE]]; rqst_methods: detachable WSF_ROUTER_METHODS)
do
map_uri_template_with_request_methods (a_tpl, create {WSF_URI_TEMPLATE_AGENT_CONTEXT_HANDLER [C] }.make (proc), rqst_methods)
end
note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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

View File

@@ -0,0 +1,42 @@
note
description: "Summary description for {WSF_URI_TEMPLATE_FILTER_CONTEXT_HANDLER}."
author : "$Author$"
date : "$Date$"
revision : "$Revision$"
deferred class
WSF_URI_TEMPLATE_FILTER_CONTEXT_HANDLER [C -> WSF_HANDLER_CONTEXT create make end]
inherit
WSF_FILTER_HANDLER
redefine
next
end
WSF_URI_TEMPLATE_CONTEXT_HANDLER [C]
feature -- Access
next: detachable WSF_URI_TEMPLATE_CONTEXT_HANDLER [C]
-- Next handler
feature -- Execution
execute_next (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
do
if attached next as n then
n.execute (ctx, req, res)
end
end
note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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

View File

@@ -0,0 +1,43 @@
note
description: "Summary description for {WSF_URI_TEMPLATE_ROUTING_CONTEXT_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_URI_TEMPLATE_ROUTING_CONTEXT_HANDLER [C -> WSF_HANDLER_CONTEXT create make end]
inherit
WSF_ROUTING_CONTEXT_HANDLER [C]
WSF_URI_TEMPLATE_CONTEXT_HANDLER [C]
rename
execute as uri_template_execute
select
uri_template_execute
end
create
make,
make_with_router
feature -- Execution
uri_template_execute (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
--| For such routing handler, the previous context is lost
do
execute_with_context (ctx, req, res)
end
note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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

View File

@@ -0,0 +1,32 @@
note
description: "Summary description for WSF_URI_TEMPLATE_CONTEXT_HANDLER."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_URI_TEMPLATE_CONTEXT_HANDLER [C -> WSF_HANDLER_CONTEXT create make end]
inherit
WSF_CONTEXT_HANDLER [C]
WSF_ROUTER_MAPPING_FACTORY
feature {WSF_ROUTER} -- Mapping
new_mapping (a_tpl: READABLE_STRING_8): WSF_ROUTER_MAPPING
do
create {WSF_URI_TEMPLATE_CONTEXT_MAPPING [C]} Result.make (a_tpl, Current)
end
note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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

View File

@@ -0,0 +1,53 @@
note
description: "Summary description for {WSF_URI_TEMPLATE_CONTEXT_MAPPING}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_URI_TEMPLATE_CONTEXT_MAPPING [C -> WSF_HANDLER_CONTEXT create make end]
inherit
WSF_URI_TEMPLATE_MAPPING_I
undefine
debug_output
end
WSF_ROUTER_CONTEXT_MAPPING [C]
create
make,
make_from_template
feature -- Access
handler: WSF_URI_TEMPLATE_CONTEXT_HANDLER [C]
feature -- Change
set_handler (h: like handler)
do
handler := h
end
feature {NONE} -- Execution
execute_handler (h: like handler; req: WSF_REQUEST; res: WSF_RESPONSE)
local
ctx: detachable C
do
create ctx.make (req, Current)
h.execute (ctx, req, res)
end
note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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

View File

@@ -1,5 +1,5 @@
note
description: "Summary description for EWF_URI_TEMPLATE_HANDLER."
description: "Summary description for WSF_URI_TEMPLATE_HANDLER."
author: ""
date: "$Date$"
revision: "$Revision$"

View File

@@ -1,5 +1,5 @@
note
description: "Summary description for {EWF_ROUTER_URI_TEMPLATE_PATH}."
description: "Summary description for {WSF_URI_TEMPLATE_MAPPING}."
author: ""
date: "$Date$"
revision: "$Revision$"
@@ -8,92 +8,30 @@ class
WSF_URI_TEMPLATE_MAPPING
inherit
WSF_ROUTER_MAPPING
WSF_SELF_DOCUMENTED_ROUTER_MAPPING
WSF_URI_TEMPLATE_MAPPING_I
create
make,
make_from_template
feature {NONE} -- Initialization
make (s: READABLE_STRING_8; h: like handler)
do
make_from_template (create {URI_TEMPLATE}.make (s), h)
end
make_from_template (tpl: URI_TEMPLATE; h: like handler)
do
template := tpl
handler := h
end
feature -- Access
associated_resource: READABLE_STRING_8
-- Associated resource
do
Result := template.template
end
handler: WSF_URI_TEMPLATE_HANDLER
template: URI_TEMPLATE
feature -- Documentation
description: STRING_32 = "Match-URI-Template"
feature -- Element change
feature -- Change
set_handler (h: like handler)
do
handler := h
end
feature -- Status
feature {NONE} -- Execution
routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER
local
tpl: URI_TEMPLATE
p: READABLE_STRING_32
new_src: detachable WSF_REQUEST_PATH_PARAMETERS_PROVIDER
execute_handler (h: like handler; req: WSF_REQUEST; res: WSF_RESPONSE)
do
p := path_from_request (req)
tpl := based_uri_template (template, a_router)
if attached tpl.match (p) as tpl_res then
Result := handler
a_router.execute_before (Current)
--| Applied the context to the request
--| in practice, this will fill the {WSF_REQUEST}.path_parameters
create new_src.make (tpl_res.path_variables.count, tpl_res.path_variables)
new_src.apply (req)
handler.execute (req, res)
--| Revert {WSF_REQUEST}.path_parameters_source to former value
--| In case the request object passed by other handler that alters its values.
new_src.revert (req)
a_router.execute_after (Current)
end
rescue
if new_src /= Void then
new_src.revert (req)
end
h.execute (req, res)
end
feature {NONE} -- Implementation
based_uri_template (a_tpl: like template; a_router: WSF_ROUTER): like template
do
if attached a_router.base_url as l_base_url then
Result := a_tpl.duplicate
Result.set_template (l_base_url + a_tpl.template)
else
Result := a_tpl
end
end
note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

View File

@@ -0,0 +1,117 @@
note
description: "Summary description for {WSF_URI_TEMPLATE_MAPPING_I}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_URI_TEMPLATE_MAPPING_I
inherit
WSF_ROUTER_MAPPING
WSF_SELF_DOCUMENTED_ROUTER_MAPPING
feature {NONE} -- Initialization
make (s: READABLE_STRING_8; h: like handler)
do
make_from_template (create {URI_TEMPLATE}.make (s), h)
end
make_from_template (tpl: URI_TEMPLATE; h: like handler)
do
template := tpl
set_handler (h)
end
feature -- Access
associated_resource: READABLE_STRING_8
-- Associated resource
do
Result := template.template
end
template: URI_TEMPLATE
feature -- Change
set_handler (h: like handler)
deferred
end
feature -- Documentation
description: STRING_32 = "Match-URI-Template"
feature -- Status
is_mapping (req: WSF_REQUEST; a_router: WSF_ROUTER): BOOLEAN
-- <Precursor>
local
tpl: URI_TEMPLATE
p: READABLE_STRING_32
do
p := path_from_request (req)
tpl := based_uri_template (template, a_router)
Result := tpl.match (p) /= Void
end
routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER
local
tpl: URI_TEMPLATE
p: READABLE_STRING_32
new_src: detachable WSF_REQUEST_PATH_PARAMETERS_PROVIDER
do
p := path_from_request (req)
tpl := based_uri_template (template, a_router)
if attached tpl.match (p) as tpl_res then
Result := handler
a_router.execute_before (Current)
--| Applied the context to the request
--| in practice, this will fill the {WSF_REQUEST}.path_parameters
create new_src.make (tpl_res.path_variables.count, tpl_res.path_variables)
new_src.apply (req)
execute_handler (handler, req, res)
--| Revert {WSF_REQUEST}.path_parameters_source to former value
--| In case the request object passed by other handler that alters its values.
new_src.revert (req)
a_router.execute_after (Current)
end
rescue
if new_src /= Void then
new_src.revert (req)
end
end
feature {NONE} -- Execution
execute_handler (h: like handler; req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute handler `h' with `req' and `res' for Current mapping
deferred
end
feature {NONE} -- Implementation
based_uri_template (a_tpl: like template; a_router: WSF_ROUTER): like template
do
if attached a_router.base_url as l_base_url then
Result := a_tpl.duplicate
Result.set_template (l_base_url + a_tpl.template)
else
Result := a_tpl
end
end
note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, 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