Added WSF_RESPONSE_HANDLER based on WSF_RESPONSE_MESSAGE

The descendant has to implement the function

    response (ctx: C; req: WSF_REQUEST): WSF_RESPONSE_MESSAGE

Added related features and class in WSF_ROUTER to be able to use agent easily.
This commit is contained in:
Jocelyn Fiat
2012-03-19 12:04:46 +01:00
parent ef5ba19c46
commit 487487ad44
5 changed files with 136 additions and 4 deletions

View File

@@ -10,12 +10,12 @@ class
inherit inherit
WSF_URI_ROUTER_I [WSF_HANDLER [WSF_URI_HANDLER_CONTEXT], WSF_URI_HANDLER_CONTEXT] WSF_URI_ROUTER_I [WSF_HANDLER [WSF_URI_HANDLER_CONTEXT], WSF_URI_HANDLER_CONTEXT]
redefine redefine
map_agent_with_request_methods map_agent_with_request_methods, map_agent_response_with_request_methods
end end
create create
make make
feature -- Mapping feature -- Mapping agent
map_agent_with_request_methods (a_id: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: WSF_URI_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE]]; map_agent_with_request_methods (a_id: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: WSF_URI_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE]];
rqst_methods: detachable ARRAY [READABLE_STRING_8]) rqst_methods: detachable ARRAY [READABLE_STRING_8])
@@ -26,6 +26,15 @@ feature -- Mapping
map_with_request_methods (a_id, h, rqst_methods) map_with_request_methods (a_id, h, rqst_methods)
end end
map_agent_response_with_request_methods (a_id: READABLE_STRING_8; a_action: FUNCTION [ANY, TUPLE [ctx: WSF_URI_HANDLER_CONTEXT; req: WSF_REQUEST], WSF_RESPONSE_MESSAGE];
rqst_methods: detachable ARRAY [READABLE_STRING_8])
local
h: WSF_AGENT_RESPONSE_HANDLER [WSF_URI_HANDLER_CONTEXT]
do
create h.make (a_action)
map_with_request_methods (a_id, h, rqst_methods)
end
note note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

View File

@@ -10,14 +10,15 @@ class
inherit inherit
WSF_URI_TEMPLATE_ROUTER_I [WSF_HANDLER [WSF_URI_TEMPLATE_HANDLER_CONTEXT], WSF_URI_TEMPLATE_HANDLER_CONTEXT] WSF_URI_TEMPLATE_ROUTER_I [WSF_HANDLER [WSF_URI_TEMPLATE_HANDLER_CONTEXT], WSF_URI_TEMPLATE_HANDLER_CONTEXT]
redefine redefine
map_agent_with_request_methods map_agent_with_request_methods,
map_agent_response_with_request_methods
end end
create create
make, make,
make_with_base_url make_with_base_url
feature -- Mapping feature -- Mapping agent
map_agent_with_request_methods (a_id: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE]]; map_agent_with_request_methods (a_id: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE]];
rqst_methods: detachable ARRAY [READABLE_STRING_8]) rqst_methods: detachable ARRAY [READABLE_STRING_8])
@@ -28,6 +29,15 @@ feature -- Mapping
map_with_request_methods (a_id, h, rqst_methods) map_with_request_methods (a_id, h, rqst_methods)
end end
map_agent_response_with_request_methods (a_id: READABLE_STRING_8; a_action: FUNCTION [ANY, TUPLE [ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST], WSF_RESPONSE_MESSAGE];
rqst_methods: detachable ARRAY [READABLE_STRING_8])
local
h: WSF_AGENT_RESPONSE_HANDLER [WSF_URI_TEMPLATE_HANDLER_CONTEXT]
do
create h.make (a_action)
map_with_request_methods (a_id, h, rqst_methods)
end
note note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

View File

@@ -0,0 +1,43 @@
note
description: "Summary description for WSF_AGENT_RESPONSE_HANDLER."
date: "$Date$"
revision: "$Revision$"
class
WSF_AGENT_RESPONSE_HANDLER [C -> WSF_HANDLER_CONTEXT]
inherit
WSF_RESPONSE_HANDLER [C]
create
make
feature -- Initialization
make (act: like action)
do
action := act
end
feature -- Access
action: FUNCTION [ANY, TUPLE [ctx: C; req: WSF_REQUEST], WSF_RESPONSE_MESSAGE]
feature -- Execution
response (ctx: C; req: WSF_REQUEST): WSF_RESPONSE_MESSAGE
do
Result := action.item ([ctx, 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,48 @@
note
description: "[
Request handler object which is called by a WSF_ROUTER
A response handler should implement the method
response (ctx: C; req: WSF_REQUEST): WSF_RESPONSE_MESSAGE
The class is generic, this way one can use a custom WSF_HANDLER_CONTEXT if needed
]"
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_RESPONSE_HANDLER [C -> WSF_HANDLER_CONTEXT]
inherit
WSF_HANDLER [C]
feature -- Execution
response (ctx: C; req: WSF_REQUEST): WSF_RESPONSE_MESSAGE
require
is_valid_context: is_valid_context (req)
deferred
ensure
Result_attached: Result /= Void
end
feature -- Implementation
execute (ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
response (ctx, req).send_to (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

@@ -58,6 +58,8 @@ feature -- Mapping
deferred deferred
end end
feature -- Mapping agent
map_agent (a_resource: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE]]) map_agent (a_resource: READABLE_STRING_8; a_action: PROCEDURE [ANY, TUPLE [ctx: C; req: WSF_REQUEST; res: WSF_RESPONSE]])
do do
map_agent_with_request_methods (a_resource, a_action, Void) map_agent_with_request_methods (a_resource, a_action, Void)
@@ -76,6 +78,26 @@ feature -- Mapping
end end
end end
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])
do
map_agent_response_with_request_methods (a_resource, a_action, 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];
rqst_methods: detachable ARRAY [READABLE_STRING_8])
local
rah: WSF_AGENT_RESPONSE_HANDLER [C]
do
create rah.make (a_action)
if attached {H} rah as h then
map_with_request_methods (a_resource, h, rqst_methods)
else
check valid_agent_handler: False end
end
end
feature -- Base url feature -- Base url
base_url: detachable READABLE_STRING_8 base_url: detachable READABLE_STRING_8