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

@@ -0,0 +1,36 @@
note
description: "Summary description for {WSF_STARTS_WITH_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_STARTS_WITH_HANDLER
inherit
WSF_HANDLER
feature -- Execution
execute (a_start_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE)
deferred
end
feature {WSF_ROUTER} -- Mapping
new_mapping (a_uri: READABLE_STRING_8): WSF_STARTS_WITH_MAPPING
do
create Result.make (a_uri, Current)
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)"
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_PATH."
description: "Summary description for EWF_STARTS_WITH_PATH."
author: ""
date: "$Date$"
revision: "$Revision$"

View File

@@ -22,13 +22,13 @@ feature -- Initialization
feature -- Access
action: FUNCTION [ANY, TUPLE [ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST], WSF_RESPONSE_MESSAGE]
action: FUNCTION [ANY, TUPLE [req: WSF_REQUEST], WSF_RESPONSE_MESSAGE]
feature -- Execution
response (ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST): WSF_RESPONSE_MESSAGE
response (req: WSF_REQUEST): WSF_RESPONSE_MESSAGE
do
Result := action.item ([ctx, req])
Result := action.item ([req])
end
note

View File

@@ -0,0 +1,36 @@
note
description: "Summary description for {EWF_ROUTER_URI_PATH_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_URI_HANDLER
inherit
WSF_HANDLER
feature -- Execution
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
deferred
end
feature {WSF_ROUTER} -- Mapping
new_mapping (a_uri: READABLE_STRING_8): WSF_URI_MAPPING
do
create Result.make (a_uri, Current)
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)"
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_ROUTED_SERVICE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_URI_ROUTED_SERVICE
inherit
WSF_ROUTED_SERVICE
feature -- Mapping helper: uri
map_uri (a_uri: READABLE_STRING_8; h: WSF_URI_HANDLER)
do
map_uri_with_request_methods (a_uri, h, Void)
end
map_uri_with_request_methods (a_uri: READABLE_STRING_8; h: WSF_URI_HANDLER; rqst_methods: detachable WSF_ROUTER_METHODS)
do
router.map_with_request_methods (create {WSF_URI_MAPPING}.make (a_uri, h), rqst_methods)
end
feature -- Mapping helper: uri agent
map_uri_agent (a_uri: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [req: WSF_REQUEST; res: WSF_RESPONSE]])
do
map_uri_agent_with_request_methods (a_uri, proc, Void)
end
map_uri_agent_with_request_methods (a_uri: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [req: WSF_REQUEST; res: WSF_RESPONSE]]; rqst_methods: detachable WSF_ROUTER_METHODS)
do
map_uri_with_request_methods (a_uri, create {WSF_AGENT_URI_HANDLER}.make (proc), rqst_methods)
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)"
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

@@ -12,7 +12,7 @@ inherit
feature -- Response
response (ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST): WSF_RESPONSE_MESSAGE
response (req: WSF_REQUEST): WSF_RESPONSE_MESSAGE
require
is_valid_context: is_valid_context (req)
deferred
@@ -22,10 +22,10 @@ feature -- Response
feature -- Execution
execute (ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE)
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
res.send (response (ctx, req))
res.send (response (req))
end
note

View File

@@ -20,13 +20,13 @@ feature {NONE} -- Initialization
action := a_action
end
action: PROCEDURE [ANY, TUPLE [context: WSF_URI_TEMPLATE_HANDLER_CONTEXT; request: WSF_REQUEST; response: WSF_RESPONSE]]
action: PROCEDURE [ANY, TUPLE [request: WSF_REQUEST; response: WSF_RESPONSE]]
feature -- Execution
execute (ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE)
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
do
action.call ([ctx, req, res])
action.call ([req, res])
end
note

View File

@@ -0,0 +1,36 @@
note
description: "Summary description for EWF_URI_TEMPLATE_HANDLER."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_URI_TEMPLATE_HANDLER
inherit
WSF_HANDLER
feature -- Execution
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
deferred
end
feature {WSF_ROUTER} -- Mapping
new_mapping (a_tpl: READABLE_STRING_8): WSF_URI_TEMPLATE_MAPPING
do
create Result.make (a_tpl, Current)
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)"
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

@@ -12,16 +12,16 @@ inherit
create
make,
make_from_string
make_from_template
feature {NONE} -- Initialization
make_from_string (s: READABLE_STRING_8; h: like handler)
make (s: READABLE_STRING_8; h: like handler)
do
make (create {URI_TEMPLATE}.make (s), h)
make_from_template (create {URI_TEMPLATE}.make (s), h)
end
make (tpl: URI_TEMPLATE; h: like handler)
make_from_template (tpl: URI_TEMPLATE; h: like handler)
do
template := tpl
handler := h
@@ -46,26 +46,26 @@ feature -- Status
local
tpl: URI_TEMPLATE
p: READABLE_STRING_32
ctx: detachable WSF_URI_TEMPLATE_HANDLER_CONTEXT
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
create ctx.make (req, tpl, tpl_res, path_from_request (req))
a_router.execute_before (Current)
--| Applied the context to the request
--| in practice, this will fill the {WSF_REQUEST}.path_parameters
ctx.apply (req)
handler.execute (ctx, req, res)
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.
ctx.revert (req)
new_src.revert (req)
a_router.execute_after (Current)
end
rescue
if ctx /= Void then
ctx.revert (req)
if new_src /= Void then
new_src.revert (req)
end
end

View File

@@ -0,0 +1,47 @@
note
description: "Summary description for {WSF_URI_TEMPLATE_ROUTED_SERVICE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_URI_TEMPLATE_ROUTED_SERVICE
inherit
WSF_ROUTED_SERVICE
feature -- Mapping helper: uri
map_uri_template (a_tpl: STRING; h: WSF_URI_TEMPLATE_HANDLER)
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_HANDLER; rqst_methods: detachable WSF_ROUTER_METHODS)
do
router.map_with_request_methods (create {WSF_URI_TEMPLATE_MAPPING}.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 [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 [req: WSF_REQUEST; res: WSF_RESPONSE]]; rqst_methods: detachable WSF_ROUTER_METHODS)
do
map_uri_template_with_request_methods (a_tpl, create {WSF_AGENT_URI_TEMPLATE_HANDLER}.make (proc), rqst_methods)
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)"
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,29 @@
note
description: "Summary description for {WSF_URI_TEMPLATE_ROUTING_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_URI_TEMPLATE_ROUTING_HANDLER
inherit
WSF_ROUTING_HANDLER
WSF_URI_TEMPLATE_HANDLER
create
make,
make_with_router
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)"
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_AGENT_URI_TEMPLATE_WITH_CONTEXT_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_AGENT_URI_TEMPLATE_WITH_CONTEXT_HANDLER
inherit
WSF_URI_TEMPLATE_WITH_CONTEXT_HANDLER
create
make
feature {NONE} -- Initialization
make (a_action: like action)
do
action := a_action
end
action: PROCEDURE [ANY, TUPLE [context: WSF_URI_TEMPLATE_HANDLER_CONTEXT; request: WSF_REQUEST; response: WSF_RESPONSE]]
feature -- Execution
execute (ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE)
do
action.call ([ctx, req, res])
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)"
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,36 @@
note
description: "Summary description for EWF_URI_TEMPLATE_WITH_CONTEXT_HANDLER."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_URI_TEMPLATE_WITH_CONTEXT_HANDLER
inherit
WSF_HANDLER
feature -- Execution
execute (ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE)
deferred
end
feature {WSF_ROUTER} -- Mapping
new_mapping (a_tpl: READABLE_STRING_8): WSF_URI_TEMPLATE_WITH_CONTEXT_MAPPING
do
create Result.make (a_tpl, Current)
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)"
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,95 @@
note
description: "Summary description for {EWF_ROUTER_URI_TEMPLATE_WITH_CONTEXT_PATH}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_URI_TEMPLATE_WITH_CONTEXT_MAPPING
inherit
WSF_ROUTER_MAPPING
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
handler: WSF_URI_TEMPLATE_WITH_CONTEXT_HANDLER
template: URI_TEMPLATE
feature -- Element change
set_handler (h: like handler)
do
handler := h
end
feature -- Status
routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER
local
tpl: URI_TEMPLATE
p: READABLE_STRING_32
ctx: detachable WSF_URI_TEMPLATE_HANDLER_CONTEXT
do
p := path_from_request (req)
tpl := based_uri_template (template, a_router)
if attached tpl.match (p) as tpl_res then
Result := handler
create ctx.make (req, tpl, tpl_res, path_from_request (req))
a_router.execute_before (Current)
--| Applied the context to the request
--| in practice, this will fill the {WSF_REQUEST}.path_parameters
ctx.apply (req)
handler.execute (ctx, req, res)
--| Revert {WSF_REQUEST}.path_parameters_source to former value
--| In case the request object passed by other handler that alters its values.
ctx.revert (req)
a_router.execute_after (Current)
end
rescue
if ctx /= Void then
ctx.revert (req)
end
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, 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_WITH_CONTEXT_ROUTED_SERVICE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_URI_TEMPLATE_WITH_CONTEXT_ROUTED_SERVICE
inherit
WSF_ROUTED_SERVICE
feature -- Mapping helper: uri
map_uri_template (a_tpl: STRING; h: WSF_URI_TEMPLATE_WITH_CONTEXT_HANDLER)
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_WITH_CONTEXT_HANDLER; rqst_methods: detachable WSF_ROUTER_METHODS)
do
router.map_with_request_methods (create {WSF_URI_TEMPLATE_WITH_CONTEXT_MAPPING}.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: WSF_URI_TEMPLATE_HANDLER_CONTEXT; 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: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE]]; rqst_methods: detachable WSF_ROUTER_METHODS)
do
map_uri_template_with_request_methods (a_tpl, create {WSF_AGENT_URI_TEMPLATE_WITH_CONTEXT_HANDLER}.make (proc), rqst_methods)
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)"
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,39 @@
note
description: "Summary description for {WSF_URI_TEMPLATE_WITH_CONTEXT_ROUTING_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_URI_TEMPLATE_WITH_CONTEXT_ROUTING_HANDLER
inherit
WSF_ROUTING_HANDLER
WSF_URI_TEMPLATE_WITH_CONTEXT_HANDLER
rename
execute as uri_template_xecute
end
create
make,
make_with_router
feature -- Execution
uri_template_xecute (ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE)
do
execute (req, res)
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)"
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,19 +0,0 @@
note
description: "Summary description for {WSF_STARTS_WITH_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_STARTS_WITH_HANDLER
inherit
WSF_HANDLER
feature -- Execution
execute (a_start_path: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE)
deferred
end
end

View File

@@ -1,19 +0,0 @@
note
description: "Summary description for {EWF_ROUTER_URI_PATH_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_URI_HANDLER
inherit
WSF_HANDLER
feature -- Execution
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
deferred
end
end

View File

@@ -1,19 +0,0 @@
note
description: "Summary description for EWF_URI_TEMPLATE_HANDLER."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_URI_TEMPLATE_HANDLER
inherit
WSF_HANDLER
feature -- Execution
execute (ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE)
deferred
end
end

View File

@@ -20,7 +20,7 @@ feature {NONE} -- Initialization
make (d: like document_root)
require
valid_d: (d /= Void and then not d.is_empty) implies d.ends_with ("/")
valid_d: (d /= Void and then not d.is_empty) implies not d.ends_with (operating_environment.directory_separator.out)
local
e: EXECUTION_ENVIRONMENT
do
@@ -30,6 +30,8 @@ feature {NONE} -- Initialization
else
document_root := d
end
ensure
not document_root.is_empty and then not document_root.ends_with (operating_environment.directory_separator.out)
end
feature -- Access
@@ -337,7 +339,7 @@ feature {NONE} -- Implementation
resource_filename (uri: READABLE_STRING_8): READABLE_STRING_8
do
Result := real_filename (document_root + real_filename (uri))
Result := real_filename (document_root + operating_environment.directory_separator.out + real_filename (uri))
end
dirname (uri: READABLE_STRING_8): READABLE_STRING_8
@@ -450,4 +452,14 @@ feature {NONE} -- implementation: date time
Result := date_time_utility.unix_time_stamp_to_date_time (n)
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)"
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

@@ -14,8 +14,15 @@ feature -- Status report
do
Result := True
end
feature {WSF_ROUTER} -- Mapping change
feature {WSF_ROUTER} -- Mapping
new_mapping (a_resource: READABLE_STRING_8): WSF_ROUTER_MAPPING
-- New mapping built with Current as handler
deferred
ensure
Result /= Void and then Result.handler = Current
end
on_mapped (a_mapping: WSF_ROUTER_MAPPING; a_rqst_methods: detachable WSF_ROUTER_METHODS)
-- Callback called when a router map a route to Current handler

View File

@@ -57,6 +57,21 @@ feature -- Mapping
a_mapping.handler.on_mapped (a_mapping, rqst_methods)
end
feature -- Mapping handler
handle (a_resource: READABLE_STRING_8; h: WSF_HANDLER)
-- Map the mapping associated to handler `h' for resource `a_resource'
do
handle_with_request_methods (a_resource, h, Void)
end
handle_with_request_methods (a_resource: READABLE_STRING_8; h: WSF_HANDLER; rqst_methods: detachable WSF_ROUTER_METHODS)
-- Map the mapping associated to handler `h' for resource `a_resource'
-- and only for request methods `rqst_methods'
do
map_with_request_methods (h.new_mapping (a_resource), rqst_methods)
end
feature -- Access
is_dispatched: BOOLEAN

View File

@@ -7,6 +7,12 @@ note
deferred class
WSF_ROUTER_MAPPING
feature {NONE} -- Initialization
make (a_resource: READABLE_STRING_8; h: like handler)
deferred
end
feature -- Access
handler: WSF_HANDLER

View File

@@ -62,11 +62,7 @@ feature {NONE} -- Initialization
make_from_iterable (v: ITERABLE [READABLE_STRING_8])
do
make (1)
across
v as vc
loop
add_method_using_constant (vc.item)
end
add_methods (v)
end
make_from_string (v: READABLE_STRING_8)
@@ -115,6 +111,19 @@ feature -- Status change
is_locked := True
end
feature -- Basic operations
add alias "+" (a_other: WSF_ROUTER_METHODS): WSF_ROUTER_METHODS
-- Merge Current and a_other into Result
require
a_other_not_void: a_other /= Void
do
create Result.make_from_iterable (Current)
Result.add_methods (a_other)
ensure
end
feature -- Element change
enable_get
@@ -328,7 +337,21 @@ feature -- Access
Result := methods.to_array
end
feature {NONE} -- Implementation
feature {WSF_ROUTER_METHODS} -- Implementation
add_methods (lst: ITERABLE [READABLE_STRING_8])
-- Enable methods from `lst'
do
if not is_locked then
across
lst as c
loop
add_method_using_constant (c.item)
end
end
end
feature {NONE} -- Implementation
add_method_using_constant (v: READABLE_STRING_8)
-- Add method `v' using method_* constant
@@ -358,15 +381,6 @@ feature {NONE} -- Implementation
method_set: has (v.as_upper)
end
add_method (v: READABLE_STRING_8)
require
is_upper_case: v.same_string (v.as_upper)
do
if not is_locked then
methods.extend (v)
end
end
prune_method (v: READABLE_STRING_8)
require
is_upper_case: v.same_string (v.as_upper)

View File

@@ -0,0 +1,75 @@
note
description: "Summary description for {WSF_ROUTING_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_ROUTING_HANDLER
inherit
WSF_HANDLER
feature {NONE} -- Initialization
make_with_router (a_router: like router)
do
router := a_router
end
make (n: INTEGER)
do
make_with_router (create {WSF_ROUTER}.make (n))
end
feature -- Access
router: WSF_ROUTER
feature -- Access
count: INTEGER
-- Count of maps handled by current
do
Result := router.count
end
base_url: detachable READABLE_STRING_8
do
Result := router.base_url
end
feature -- Element change
set_base_url (a_base_url: like base_url)
-- Set `base_url' to `a_base_url'
-- make sure no map is already added (i.e: count = 0)
require
no_handler_set: count = 0
do
router.set_base_url (a_base_url)
end
feature -- Execution
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
if attached router.dispatch_and_return_handler (req, res) as h then
check is_dispatched: router.is_dispatched end
else
res.put_header ({HTTP_STATUS_CODE}.not_found, <<[{HTTP_HEADER_NAMES}.header_content_length, "0"]>>)
end
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)"
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

@@ -8,19 +8,19 @@ note
revision: "$Revision$"
deferred class
WSF_FILTER_HANDLER [C -> WSF_HANDLER_CONTEXT]
WSF_FILTER_HANDLER [H -> WSF_HANDLER]
inherit
WSF_HANDLER [C]
WSF_HANDLER
feature -- Access
next: detachable WSF_FILTER_HANDLER [C]
-- Next filter
next: detachable H
-- Next handler
feature -- Element change
set_next (a_next: WSF_FILTER_HANDLER [C])
set_next (a_next: like next)
-- Set `next' to `a_next'
do
next := a_next
@@ -28,16 +28,6 @@ feature -- Element change
next_set: next = a_next
end
feature {NONE} -- Implementation
execute_next (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute the `next' filter.
do
if attached next as n then
n.execute (ctx, req, res)
end
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)"

View File

@@ -0,0 +1,34 @@
note
description : "Objects that ..."
author : "$Author$"
date : "$Date$"
revision : "$Revision$"
deferred class
WSF_FILTER_URI_HANDLER
inherit
WSF_FILTER_HANDLER [WSF_URI_HANDLER]
WSF_URI_HANDLER
feature -- Execution
execute_next (req: WSF_REQUEST; res: WSF_RESPONSE)
do
if attached next as n then
n.execute (req, res)
end
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)"
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,34 @@
note
description : "Objects that ..."
author : "$Author$"
date : "$Date$"
revision : "$Revision$"
deferred class
WSF_FILTER_URI_TEMPLATE_HANDLER
inherit
WSF_FILTER_HANDLER [WSF_URI_TEMPLATE_HANDLER]
WSF_URI_TEMPLATE_HANDLER
feature -- Execution
execute_next (req: WSF_REQUEST; res: WSF_RESPONSE)
do
if attached next as n then
n.execute (req, res)
end
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)"
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,11 +1,11 @@
note
description: "Summary description for {WSF_URI_TEMPLATE_FILTERED_SERVICE}."
description: "Summary description for {WSF_FILTERED_SERVICE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_URI_TEMPLATE_FILTERED_SERVICE
WSF_FILTERED_SERVICE
feature {NONE} -- Initialization

View File

@@ -1,75 +0,0 @@
note
description: "Routing filter."
author: "Olivier Ligot"
date: "$Date$"
revision: "$Revision$"
class
WSF_ROUTING_FILTER [H -> WSF_HANDLER [C], C -> WSF_HANDLER_CONTEXT]
inherit
WSF_FILTER
create
make
feature {NONE} -- Initialization
make (a_router: WSF_ROUTER [H, C])
do
router := a_router
ensure
router_set: router = a_router
end
feature -- Access
router: WSF_ROUTER [H, C]
-- Router
execute_default_action: detachable PROCEDURE [ANY, TUPLE [req: WSF_REQUEST; res: WSF_RESPONSE]]
-- `execute_default' action
feature -- Element change
set_execute_default_action (an_action: like execute_default_action)
-- Set `execute_default_action' to `an_action'
do
execute_default_action := an_action
ensure
execute_default_action_set: execute_default_action = an_action
end
feature -- Basic operations
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute the filter
do
if attached router.route (req) as r then
router.execute_route (r, req, res)
else
execute_default (req, res)
end
execute_next (req, res)
end
execute_default (req: WSF_REQUEST; res: WSF_RESPONSE)
do
if attached execute_default_action as action then
action.call ([req, res])
else
do_nothing
end
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)"
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,59 @@
note
description: "Summary description for {WSF_REQUEST_PATH_PARAMETERS_PROVIDER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_REQUEST_PATH_PARAMETERS_PROVIDER
inherit
WSF_REQUEST_PATH_PARAMETERS_SOURCE
create
make
feature {NONE} -- Initialization
make (nb: INTEGER; a_urlencoded_path_parameters: like urlencoded_path_parameters)
do
path_parameters_count := nb
urlencoded_path_parameters := a_urlencoded_path_parameters
end
feature -- Access
path_parameters_count: INTEGER
urlencoded_path_parameters: TABLE_ITERABLE [READABLE_STRING_8, READABLE_STRING_8]
-- Raw urlencoded path parameters.
feature -- Operation
previous_path_parameters_source: detachable WSF_REQUEST_PATH_PARAMETERS_SOURCE
apply (req: WSF_REQUEST)
-- <Precursor>
do
previous_path_parameters_source := req.path_parameters_source
req.set_path_parameters_source (Current)
end
revert (req: WSF_REQUEST)
-- <Precursor>
do
req.set_path_parameters_source (previous_path_parameters_source)
previous_path_parameters_source := Void
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)"
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

@@ -5,160 +5,160 @@ note
revision: "$Revision$"
class
WSF_RESOURCE_HANDLER_HELPER [C -> WSF_HANDLER_CONTEXT]
WSF_RESOURCE_HANDLER_HELPER
feature -- Execute template
execute_methods (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
execute_methods (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request and dispatch according to the request method
local
m: READABLE_STRING_8
do
m := req.request_method.as_upper
if m.same_string ({HTTP_REQUEST_METHODS}.method_get) then
execute_get (ctx, req, res)
execute_get (req, res)
elseif m.same_string ({HTTP_REQUEST_METHODS}.method_put) then
execute_put (ctx, req, res)
execute_put (req, res)
elseif m.same_string ({HTTP_REQUEST_METHODS}.method_delete) then
execute_delete (ctx, req, res)
execute_delete (req, res)
elseif m.same_string ({HTTP_REQUEST_METHODS}.method_post) then
execute_post (ctx, req, res)
execute_post (req, res)
elseif m.same_string ({HTTP_REQUEST_METHODS}.method_trace) then
execute_trace (ctx, req, res)
execute_trace (req, res)
elseif m.same_string ({HTTP_REQUEST_METHODS}.method_options) then
execute_options (ctx, req, res)
execute_options (req, res)
elseif m.same_string ({HTTP_REQUEST_METHODS}.method_head) then
execute_head (ctx, req, res)
execute_head (req, res)
elseif m.same_string ({HTTP_REQUEST_METHODS}.method_connect) then
execute_connect (ctx, req, res)
execute_connect (req, res)
else
--| Eventually handle other methods...
execute_extension_method (ctx, req, res)
execute_extension_method (req, res)
end
end
feature -- Method Post
execute_post (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
execute_post (req: WSF_REQUEST; res: WSF_RESPONSE)
do
if req.is_chunked_input then
do_post (ctx, req, res)
do_post (req, res)
else
if req.content_length_value > 0 then
do_post (ctx, req, res)
do_post (req, res)
else
handle_bad_request_response ("Bad request, content_length empty", ctx, req, res)
handle_bad_request_response ("Bad request, content_length empty", req, res)
end
end
end
do_post (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
do_post (req: WSF_REQUEST; res: WSF_RESPONSE)
do
handle_not_implemented ("Method POST not implemented", ctx, req, res)
handle_not_implemented ("Method POST not implemented", req, res)
end
feature-- Method Put
execute_put (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
execute_put (req: WSF_REQUEST; res: WSF_RESPONSE)
do
if req.is_chunked_input then
do_put (ctx, req, res)
do_put (req, res)
else
if req.content_length_value > 0 then
do_put (ctx, req, res)
do_put (req, res)
else
handle_bad_request_response ("Bad request, content_length empty", ctx, req, res)
handle_bad_request_response ("Bad request, content_length empty", req, res)
end
end
end
do_put (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
do_put (req: WSF_REQUEST; res: WSF_RESPONSE)
do
handle_not_implemented ("Method PUT not implemented", ctx, req, res)
handle_not_implemented ("Method PUT not implemented", req, res)
end
feature -- Method Get
execute_get (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
execute_get (req: WSF_REQUEST; res: WSF_RESPONSE)
do
do_get (ctx, req, res)
do_get (req, res)
end
do_get (ctx: C;req: WSF_REQUEST; res: WSF_RESPONSE)
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
do
handle_not_implemented ("Method GET not implemented", ctx, req, res)
handle_not_implemented ("Method GET not implemented", req, res)
end
feature -- Method DELETE
execute_delete (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
execute_delete (req: WSF_REQUEST; res: WSF_RESPONSE)
do
do_delete (ctx, req, res)
do_delete (req, res)
end
do_delete (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
do_delete (req: WSF_REQUEST; res: WSF_RESPONSE)
do
handle_not_implemented ("Method DELETE not implemented", ctx, req, res)
handle_not_implemented ("Method DELETE not implemented", req, res)
end
feature -- Method CONNECT
execute_connect (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
execute_connect (req: WSF_REQUEST; res: WSF_RESPONSE)
do
do_connect (ctx, req, res)
do_connect (req, res)
end
do_connect (ctx: C;req: WSF_REQUEST; res: WSF_RESPONSE)
do_connect (req: WSF_REQUEST; res: WSF_RESPONSE)
do
handle_not_implemented ("Method CONNECT not implemented", ctx, req, res)
handle_not_implemented ("Method CONNECT not implemented", req, res)
end
feature -- Method HEAD
execute_head (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
execute_head (req: WSF_REQUEST; res: WSF_RESPONSE)
do
do_head (ctx, req, res)
do_head (req, res)
end
do_head (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
do_head (req: WSF_REQUEST; res: WSF_RESPONSE)
do
handle_not_implemented ("Method HEAD not implemented", ctx, req, res)
handle_not_implemented ("Method HEAD not implemented", req, res)
end
feature -- Method OPTIONS
execute_options (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
execute_options (req: WSF_REQUEST; res: WSF_RESPONSE)
do
do_options (ctx, req, res)
do_options (req, res)
end
do_options (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
do_options (req: WSF_REQUEST; res: WSF_RESPONSE)
do
handle_not_implemented ("Method OPTIONS not implemented", ctx, req, res)
handle_not_implemented ("Method OPTIONS not implemented", req, res)
end
feature -- Method TRACE
execute_trace (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
execute_trace (req: WSF_REQUEST; res: WSF_RESPONSE)
do
do_trace (ctx, req, res)
do_trace (req, res)
end
do_trace (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
do_trace (req: WSF_REQUEST; res: WSF_RESPONSE)
do
handle_not_implemented ("Method TRACE not implemented", ctx, req, res)
handle_not_implemented ("Method TRACE not implemented", req, res)
end
feature -- Method Extension Method
execute_extension_method (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
execute_extension_method (req: WSF_REQUEST; res: WSF_RESPONSE)
do
do_extension_method (ctx, req, res)
do_extension_method (req, res)
end
do_extension_method (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
do_extension_method (req: WSF_REQUEST; res: WSF_RESPONSE)
do
handle_not_implemented ("Method extension-method not implemented", ctx, req, res)
handle_not_implemented ("Method extension-method not implemented", req, res)
end
feature -- Retrieve content from WGI_INPUT_STREAM
@@ -208,7 +208,7 @@ feature -- Handle responses
Result := Void
end
handle_bad_request_response (a_description: STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE )
handle_bad_request_response (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE )
local
h : HTTP_HEADER
do
@@ -221,7 +221,7 @@ feature -- Handle responses
res.put_string (a_description)
end
handle_precondition_fail_response (a_description: STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE )
handle_precondition_fail_response (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE )
local
h : HTTP_HEADER
do
@@ -234,7 +234,7 @@ feature -- Handle responses
res.put_string (a_description)
end
handle_internal_server_error (a_description: STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE )
handle_internal_server_error (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE )
local
h : HTTP_HEADER
do
@@ -247,7 +247,7 @@ feature -- Handle responses
res.put_string (a_description)
end
handle_not_implemented (a_description: STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE )
handle_not_implemented (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE )
local
h : HTTP_HEADER
do
@@ -260,7 +260,7 @@ feature -- Handle responses
res.put_string (a_description)
end
handle_method_not_allowed_response (a_description: STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
handle_method_not_allowed_response (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE)
local
h : HTTP_HEADER
do
@@ -273,7 +273,7 @@ feature -- Handle responses
res.put_string (a_description)
end
handle_resource_not_found_response (a_description: STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
handle_resource_not_found_response (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE)
local
h : HTTP_HEADER
do
@@ -287,7 +287,7 @@ feature -- Handle responses
end
handle_resource_not_modified_response (a_description: STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
handle_resource_not_modified_response (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE)
local
h : HTTP_HEADER
do
@@ -302,7 +302,7 @@ feature -- Handle responses
end
handle_resource_conflict_response (a_description: STRING; ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
handle_resource_conflict_response (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE)
local
h : HTTP_HEADER
do