Reviewed the semantic of the handler context.

Adapted existing code to fit the new router design.
This commit is contained in:
Jocelyn Fiat
2012-09-27 15:09:41 +02:00
parent cdb88059bc
commit e01c5bec57
36 changed files with 458 additions and 431 deletions

View File

@@ -0,0 +1,42 @@
note
description: "Summary description for {WSF_URI_AGENT_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_URI_AGENT_HANDLER
inherit
WSF_URI_HANDLER
create
make
feature {NONE} -- Initialization
make (a_action: like action)
do
action := a_action
end
action: PROCEDURE [ANY, TUPLE [request: WSF_REQUEST; response: WSF_RESPONSE]]
feature -- Execution
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
do
action.call ([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,41 @@
note
description: "Summary description for {WSF_URI_RESPONSE_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_URI_RESPONSE_HANDLER
inherit
WSF_URI_HANDLER
feature -- Response
response (req: WSF_REQUEST): WSF_RESPONSE_MESSAGE
require
is_valid_context: is_valid_context (req)
deferred
ensure
Result_attached: Result /= Void
end
feature -- Execution
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
res.send (response (req))
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_URI_AGENT_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,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,80 @@
note
description: "Summary description for EWF_URI_PATH."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_URI_MAPPING
inherit
WSF_ROUTER_MAPPING
create
make,
make_trailing_slash_ignored
feature {NONE} -- Initialization
make (a_uri: READABLE_STRING_8; h: like handler)
do
handler := h
uri := a_uri
end
make_trailing_slash_ignored (a_uri: READABLE_STRING_8; h: like handler)
do
make (a_uri, h)
trailing_slash_ignored := True
end
feature -- Access
handler: WSF_URI_HANDLER
uri: READABLE_STRING_8
trailing_slash_ignored: BOOLEAN
feature -- Status
routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER
local
p: READABLE_STRING_8
l_uri: like uri
do
p := path_from_request (req)
l_uri := based_uri (uri, a_router)
if l_uri.ends_with ("/") then
if not p.ends_with ("/") then
p := p + "/"
end
else
if p.ends_with ("/") then
p := p.substring (1, p.count - 1)
end
end
if p.same_string (l_uri) then
Result := handler
a_router.execute_before (Current)
handler.execute (req, res)
a_router.execute_after (Current)
end
end
feature {NONE} -- Implementation
based_uri (a_uri: like uri; a_router: WSF_ROUTER): like uri
local
s: STRING_8
do
if attached a_router.base_url as l_base_url then
create s.make_from_string (l_base_url)
s.append_string (a_uri)
Result := s
else
Result := a_uri
end
end
end