moved wsf_extension inside wsf/extension as wsf/wsf_extension.ecf
added wsf/session as wsf/wsf_session.ecf In descendants of WSF_HANDLER , we can keep the result of new_mapping as WSF_ROUTER_MAPPING
This commit is contained in:
96
library/server/wsf/extension/wsf_handler_helper.e
Normal file
96
library/server/wsf/extension/wsf_handler_helper.e
Normal file
@@ -0,0 +1,96 @@
|
||||
note
|
||||
description: "[
|
||||
Provides a few helpful feature to respond predefined message to the client
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_HANDLER_HELPER
|
||||
|
||||
inherit
|
||||
ANY
|
||||
|
||||
feature -- Helper
|
||||
|
||||
execute_content_type_not_allowed (req: WSF_REQUEST; res: WSF_RESPONSE; a_content_types: detachable ARRAY [STRING]; a_uri_formats: detachable ARRAY [STRING])
|
||||
local
|
||||
accept_s, uri_s: detachable STRING
|
||||
i, n: INTEGER
|
||||
do
|
||||
if a_content_types /= Void then
|
||||
create accept_s.make (10)
|
||||
from
|
||||
i := a_content_types.lower
|
||||
n := a_content_types.upper
|
||||
until
|
||||
i > n
|
||||
loop
|
||||
accept_s.append_string (a_content_types[i])
|
||||
if i < n then
|
||||
accept_s.append_character (',')
|
||||
accept_s.append_character (' ')
|
||||
end
|
||||
i := i + 1
|
||||
end
|
||||
else
|
||||
accept_s := "*/*"
|
||||
end
|
||||
|
||||
if a_uri_formats /= Void then
|
||||
create uri_s.make (10)
|
||||
from
|
||||
i := a_uri_formats.lower
|
||||
n := a_uri_formats.upper
|
||||
until
|
||||
i > n
|
||||
loop
|
||||
uri_s.append_string (a_uri_formats[i])
|
||||
if i < n then
|
||||
uri_s.append_character (',')
|
||||
uri_s.append_character (' ')
|
||||
end
|
||||
i := i + 1
|
||||
end
|
||||
end
|
||||
res.put_header ({HTTP_STATUS_CODE}.unsupported_media_type, << ["Content-Type", "text/plain"], ["Accept", accept_s]>>)
|
||||
if accept_s /= Void then
|
||||
res.put_string ("Unsupported request content-type, Accept: " + accept_s + "%N")
|
||||
end
|
||||
if uri_s /= Void then
|
||||
res.put_string ("Unsupported request format from the URI: " + uri_s + "%N")
|
||||
end
|
||||
end
|
||||
|
||||
execute_request_method_not_allowed (req: WSF_REQUEST; res: WSF_RESPONSE; a_methods: ITERABLE [STRING])
|
||||
local
|
||||
s: STRING
|
||||
do
|
||||
create s.make (25)
|
||||
across
|
||||
a_methods as c
|
||||
loop
|
||||
if not s.is_empty then
|
||||
s.append_character (',')
|
||||
s.append_character (' ')
|
||||
end
|
||||
s.append_string (c.item)
|
||||
end
|
||||
res.put_header ({HTTP_STATUS_CODE}.method_not_allowed, <<
|
||||
["Content-Type", {HTTP_MIME_TYPES}.text_plain],
|
||||
["Allow", s]
|
||||
>>)
|
||||
res.put_string ("Unsupported request method, Allow: " + s + "%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
|
||||
44
library/server/wsf/extension/wsf_handler_routes_recorder.e
Normal file
44
library/server/wsf/extension/wsf_handler_routes_recorder.e
Normal file
@@ -0,0 +1,44 @@
|
||||
note
|
||||
description: "[
|
||||
Summary description for WSF_HANDLER_ROUTES_RECORDER.
|
||||
|
||||
You can inherit from this class from any WSF_HANDLER and redefine `on_handler_mapped'
|
||||
to record the available routes if your handler needs it.
|
||||
]"
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
WSF_HANDLER_ROUTES_RECORDER
|
||||
|
||||
feature {WSF_HANDLER} -- Routes access
|
||||
|
||||
available_routes: detachable LIST [TUPLE [resource: READABLE_STRING_8; rqst_methods: detachable ARRAY [READABLE_STRING_8]]]
|
||||
-- Available routes
|
||||
|
||||
feature {WSF_ROUTER} -- Routes change
|
||||
|
||||
on_handler_mapped (a_resource: READABLE_STRING_8; a_rqst_methods: detachable ARRAY [READABLE_STRING_8])
|
||||
local
|
||||
l_routes: like available_routes
|
||||
do
|
||||
l_routes := available_routes
|
||||
if l_routes = Void then
|
||||
create {ARRAYED_LIST [like available_routes.item]} l_routes.make (3)
|
||||
available_routes := l_routes
|
||||
end
|
||||
l_routes.force ([a_resource, a_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
|
||||
112
library/server/wsf/extension/wsf_request_utility.e
Normal file
112
library/server/wsf/extension/wsf_request_utility.e
Normal file
@@ -0,0 +1,112 @@
|
||||
note
|
||||
description: "Summary description for {WSF_REQUEST_UTILITY}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_REQUEST_UTILITY
|
||||
|
||||
inherit
|
||||
ANY
|
||||
|
||||
WSF_FORMAT_UTILITY
|
||||
export
|
||||
{NONE} all
|
||||
end
|
||||
|
||||
WSF_VALUE_UTILITY
|
||||
|
||||
feature -- Url Query
|
||||
|
||||
script_absolute_url (req: WSF_REQUEST; a_path: STRING): STRING
|
||||
-- Absolute Url for the script if any, extended by `a_path'
|
||||
do
|
||||
Result := req.absolute_script_url (a_path)
|
||||
end
|
||||
|
||||
script_url (req: WSF_REQUEST; a_path: STRING): STRING
|
||||
-- Url relative to script name if any, extended by `a_path'
|
||||
require
|
||||
a_path_attached: a_path /= Void
|
||||
do
|
||||
Result := req.script_url (a_path)
|
||||
end
|
||||
|
||||
url (req: WSF_REQUEST; a_path: STRING; args: detachable STRING; abs: BOOLEAN): STRING
|
||||
-- Associated url based on `path' and `args'
|
||||
-- if `abs' then return absolute url
|
||||
local
|
||||
s,t: detachable STRING
|
||||
do
|
||||
s := args
|
||||
if s /= Void and then s.count > 0 then
|
||||
create t.make_from_string (a_path)
|
||||
if s[1] /= '/' and t[t.count] /= '/' then
|
||||
t.append_character ('/')
|
||||
t.append (s)
|
||||
else
|
||||
t.append (s)
|
||||
end
|
||||
s := t
|
||||
else
|
||||
s := a_path
|
||||
end
|
||||
if abs then
|
||||
Result := script_absolute_url (req, s)
|
||||
else
|
||||
Result := script_url (req, s)
|
||||
end
|
||||
ensure
|
||||
result_attached: Result /= Void
|
||||
end
|
||||
|
||||
feature -- Query
|
||||
|
||||
request_accepted_content_type (req: WSF_REQUEST; a_supported_content_types: detachable ARRAY [READABLE_STRING_8]): detachable READABLE_STRING_8
|
||||
-- Accepted content-type for the request, among the supported content types `a_supported_content_types'
|
||||
local
|
||||
s: detachable READABLE_STRING_8
|
||||
i,n: INTEGER
|
||||
do
|
||||
if
|
||||
attached accepted_content_types (req) as l_accept_lst and then
|
||||
not l_accept_lst.is_empty
|
||||
then
|
||||
from
|
||||
l_accept_lst.start
|
||||
until
|
||||
l_accept_lst.after or Result /= Void
|
||||
loop
|
||||
s := l_accept_lst.item
|
||||
if a_supported_content_types /= Void then
|
||||
from
|
||||
i := a_supported_content_types.lower
|
||||
n := a_supported_content_types.upper
|
||||
until
|
||||
i > n or Result /= Void
|
||||
loop
|
||||
if a_supported_content_types [i].same_string (s) then
|
||||
Result := s
|
||||
end
|
||||
i := i + 1
|
||||
end
|
||||
else
|
||||
Result := s
|
||||
end
|
||||
l_accept_lst.forth
|
||||
end
|
||||
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
|
||||
328
library/server/wsf/extension/wsf_resource_handler_helper.e
Normal file
328
library/server/wsf/extension/wsf_resource_handler_helper.e
Normal file
@@ -0,0 +1,328 @@
|
||||
note
|
||||
description: "Work in progress Common abstraction to handle RESTfull methods"
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_RESOURCE_HANDLER_HELPER
|
||||
|
||||
feature -- Execute template
|
||||
|
||||
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 (req, res)
|
||||
elseif m.same_string ({HTTP_REQUEST_METHODS}.method_put) then
|
||||
execute_put (req, res)
|
||||
elseif m.same_string ({HTTP_REQUEST_METHODS}.method_delete) then
|
||||
execute_delete (req, res)
|
||||
elseif m.same_string ({HTTP_REQUEST_METHODS}.method_post) then
|
||||
execute_post (req, res)
|
||||
elseif m.same_string ({HTTP_REQUEST_METHODS}.method_trace) then
|
||||
execute_trace (req, res)
|
||||
elseif m.same_string ({HTTP_REQUEST_METHODS}.method_options) then
|
||||
execute_options (req, res)
|
||||
elseif m.same_string ({HTTP_REQUEST_METHODS}.method_head) then
|
||||
execute_head (req, res)
|
||||
elseif m.same_string ({HTTP_REQUEST_METHODS}.method_connect) then
|
||||
execute_connect (req, res)
|
||||
else
|
||||
--| Eventually handle other methods...
|
||||
execute_extension_method (req, res)
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Method Post
|
||||
|
||||
execute_post (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
if req.is_chunked_input then
|
||||
do_post (req, res)
|
||||
else
|
||||
if req.content_length_value > 0 then
|
||||
do_post (req, res)
|
||||
else
|
||||
handle_bad_request_response ("Bad request, content_length empty", req, res)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
do_post (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
handle_not_implemented ("Method POST not implemented", req, res)
|
||||
end
|
||||
|
||||
feature-- Method Put
|
||||
|
||||
execute_put (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
if req.is_chunked_input then
|
||||
do_put (req, res)
|
||||
else
|
||||
if req.content_length_value > 0 then
|
||||
do_put (req, res)
|
||||
else
|
||||
handle_bad_request_response ("Bad request, content_length empty", req, res)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
do_put (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
handle_not_implemented ("Method PUT not implemented", req, res)
|
||||
end
|
||||
|
||||
feature -- Method Get
|
||||
|
||||
execute_get (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
do_get (req, res)
|
||||
end
|
||||
|
||||
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
handle_not_implemented ("Method GET not implemented", req, res)
|
||||
end
|
||||
|
||||
feature -- Method DELETE
|
||||
|
||||
execute_delete (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
do_delete (req, res)
|
||||
end
|
||||
|
||||
do_delete (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
handle_not_implemented ("Method DELETE not implemented", req, res)
|
||||
end
|
||||
|
||||
feature -- Method CONNECT
|
||||
|
||||
execute_connect (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
do_connect (req, res)
|
||||
end
|
||||
|
||||
do_connect (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
handle_not_implemented ("Method CONNECT not implemented", req, res)
|
||||
end
|
||||
|
||||
feature -- Method HEAD
|
||||
|
||||
execute_head (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
do_head (req, res)
|
||||
end
|
||||
|
||||
do_head (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
handle_not_implemented ("Method HEAD not implemented", req, res)
|
||||
end
|
||||
|
||||
feature -- Method OPTIONS
|
||||
|
||||
execute_options (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
do_options (req, res)
|
||||
end
|
||||
|
||||
do_options (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
handle_not_implemented ("Method OPTIONS not implemented", req, res)
|
||||
end
|
||||
|
||||
feature -- Method TRACE
|
||||
|
||||
execute_trace (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
do_trace (req, res)
|
||||
end
|
||||
|
||||
do_trace (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
handle_not_implemented ("Method TRACE not implemented", req, res)
|
||||
end
|
||||
|
||||
feature -- Method Extension Method
|
||||
|
||||
execute_extension_method (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
do_extension_method (req, res)
|
||||
end
|
||||
|
||||
do_extension_method (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
handle_not_implemented ("Method extension-method not implemented", req, res)
|
||||
end
|
||||
|
||||
feature -- Retrieve content from WGI_INPUT_STREAM
|
||||
|
||||
retrieve_data ( req : WSF_REQUEST) : STRING
|
||||
-- retrieve the content from the input stream
|
||||
-- handle differents transfers
|
||||
local
|
||||
l_input: WGI_INPUT_STREAM
|
||||
n: INTEGER
|
||||
s: STRING
|
||||
do
|
||||
if req.is_chunked_input then
|
||||
l_input := req.input
|
||||
from
|
||||
n := 1_024
|
||||
create Result.make (n)
|
||||
until
|
||||
n = 0
|
||||
loop
|
||||
l_input.read_string (n)
|
||||
s := l_input.last_string
|
||||
if s.count = 0 then
|
||||
n := 0
|
||||
else
|
||||
if s.count < n then
|
||||
n := 0
|
||||
end
|
||||
Result.append (s)
|
||||
end
|
||||
end
|
||||
else
|
||||
req.input.read_string (req.content_length_value.as_integer_32)
|
||||
Result := req.input.last_string
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Handle responses
|
||||
-- TODO Handle Content negotiation.
|
||||
-- The option : Server-driven negotiation: uses request headers to select a variant
|
||||
-- More info : http://www.w3.org/Protocols/rfc2616/rfc2616-sec12.html#sec12
|
||||
|
||||
supported_content_types: detachable ARRAY [READABLE_STRING_8]
|
||||
-- Supported content types
|
||||
-- Can be redefined
|
||||
do
|
||||
Result := Void
|
||||
end
|
||||
|
||||
handle_bad_request_response (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE )
|
||||
local
|
||||
h : HTTP_HEADER
|
||||
do
|
||||
create h.make
|
||||
h.put_content_type_application_json
|
||||
h.put_content_length (a_description.count)
|
||||
h.put_current_date
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.bad_request)
|
||||
res.put_header_text (h.string)
|
||||
res.put_string (a_description)
|
||||
end
|
||||
|
||||
handle_precondition_fail_response (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE )
|
||||
local
|
||||
h : HTTP_HEADER
|
||||
do
|
||||
create h.make
|
||||
h.put_content_type_application_json
|
||||
h.put_content_length (a_description.count)
|
||||
h.put_current_date
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.precondition_failed)
|
||||
res.put_header_text (h.string)
|
||||
res.put_string (a_description)
|
||||
end
|
||||
|
||||
handle_internal_server_error (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE )
|
||||
local
|
||||
h : HTTP_HEADER
|
||||
do
|
||||
create h.make
|
||||
h.put_content_type_application_json
|
||||
h.put_content_length (a_description.count)
|
||||
h.put_current_date
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.internal_server_error)
|
||||
res.put_header_text (h.string)
|
||||
res.put_string (a_description)
|
||||
end
|
||||
|
||||
handle_not_implemented (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE )
|
||||
local
|
||||
h : HTTP_HEADER
|
||||
do
|
||||
create h.make
|
||||
h.put_content_type_application_json
|
||||
h.put_content_length (a_description.count)
|
||||
h.put_current_date
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.not_implemented)
|
||||
res.put_header_text (h.string)
|
||||
res.put_string (a_description)
|
||||
end
|
||||
|
||||
handle_method_not_allowed_response (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
local
|
||||
h : HTTP_HEADER
|
||||
do
|
||||
create h.make
|
||||
h.put_content_type_application_json
|
||||
h.put_content_length (a_description.count)
|
||||
h.put_current_date
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.method_not_allowed)
|
||||
res.put_header_text (h.string)
|
||||
res.put_string (a_description)
|
||||
end
|
||||
|
||||
handle_resource_not_found_response (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
local
|
||||
h : HTTP_HEADER
|
||||
do
|
||||
create h.make
|
||||
h.put_content_type_application_json
|
||||
h.put_content_length (a_description.count)
|
||||
h.put_current_date
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.not_found)
|
||||
res.put_header_text (h.string)
|
||||
res.put_string (a_description)
|
||||
end
|
||||
|
||||
|
||||
handle_resource_not_modified_response (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
local
|
||||
h : HTTP_HEADER
|
||||
do
|
||||
res.flush
|
||||
create h.make
|
||||
h.put_content_type_application_json
|
||||
h.put_content_length (a_description.count)
|
||||
h.put_current_date
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.not_modified)
|
||||
res.put_header_text (h.string)
|
||||
res.put_string (a_description)
|
||||
end
|
||||
|
||||
|
||||
handle_resource_conflict_response (a_description: STRING; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
local
|
||||
h : HTTP_HEADER
|
||||
do
|
||||
create h.make
|
||||
h.put_content_type_application_json
|
||||
h.put_content_length (a_description.count)
|
||||
h.put_current_date
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.conflict)
|
||||
res.put_header_text (h.string)
|
||||
res.put_string (a_description)
|
||||
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
|
||||
156
library/server/wsf/extension/wsf_value_utility.e
Normal file
156
library/server/wsf/extension/wsf_value_utility.e
Normal file
@@ -0,0 +1,156 @@
|
||||
note
|
||||
description: "Summary description for {WSF_VALUE_UTILITY}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_VALUE_UTILITY
|
||||
|
||||
feature -- Parameter
|
||||
|
||||
item (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): detachable WSF_VALUE
|
||||
-- Variable value for parameter or variable `a_name'
|
||||
-- See `{WSF_REQUEST}.item(s)'
|
||||
do
|
||||
Result := req.item (a_name)
|
||||
end
|
||||
|
||||
string_item (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): detachable READABLE_STRING_32
|
||||
-- String value for any variable of parameter `a_name' if relevant.
|
||||
do
|
||||
Result := string_from (item (req, a_name))
|
||||
end
|
||||
|
||||
string_array_item (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): detachable ARRAY [READABLE_STRING_32]
|
||||
-- Array of string values for query parameter `a_name' if relevant.
|
||||
do
|
||||
Result := string_array_for (req, a_name, agent string_item)
|
||||
end
|
||||
|
||||
feature -- Query parameter
|
||||
|
||||
query_parameter (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): detachable WSF_VALUE
|
||||
-- Parameter value for query variable `a_name'
|
||||
--| i.e after the ? character
|
||||
do
|
||||
Result := req.query_parameter (a_name)
|
||||
end
|
||||
|
||||
string_query_parameter (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): detachable READABLE_STRING_32
|
||||
-- String value for query parameter `a_name' if relevant.
|
||||
do
|
||||
Result := string_from (query_parameter (req, a_name))
|
||||
end
|
||||
|
||||
string_array_query_parameter (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): detachable ARRAY [READABLE_STRING_32]
|
||||
-- Array of string values for query parameter `a_name' if relevant.
|
||||
do
|
||||
Result := string_array_for (req, a_name, agent string_query_parameter)
|
||||
end
|
||||
|
||||
is_integer_query_parameter (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): BOOLEAN
|
||||
-- Is query parameter related to `a_name' an integer value?
|
||||
do
|
||||
Result := attached string_query_parameter (req, a_name) as s and then s.is_integer
|
||||
end
|
||||
|
||||
integer_query_parameter (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): INTEGER
|
||||
-- Integer value for query parameter `a_name' if relevant.
|
||||
require
|
||||
is_integer_query_parameter: is_integer_query_parameter (req, a_name)
|
||||
do
|
||||
Result := integer_from (query_parameter (req, a_name))
|
||||
end
|
||||
|
||||
feature -- Path parameter
|
||||
|
||||
path_parameter (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): detachable WSF_VALUE
|
||||
do
|
||||
Result := req.path_parameter (a_name)
|
||||
end
|
||||
|
||||
|
||||
string_path_parameter (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): detachable READABLE_STRING_32
|
||||
-- String value for path parameter `a_name' if relevant.
|
||||
do
|
||||
Result := string_from (path_parameter (req, a_name))
|
||||
end
|
||||
|
||||
string_array_path_parameter (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): detachable ARRAY [READABLE_STRING_32]
|
||||
-- Array of string values for path parameter `a_name' if relevant.
|
||||
do
|
||||
Result := string_array_for (req, a_name, agent string_path_parameter)
|
||||
end
|
||||
|
||||
is_integer_path_parameter (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): BOOLEAN
|
||||
-- Is path parameter related to `a_name' an integer value?
|
||||
do
|
||||
Result := attached string_path_parameter (req, a_name) as s and then s.is_integer
|
||||
end
|
||||
|
||||
integer_path_parameter (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL): INTEGER
|
||||
-- Integer value for path parameter `a_name' if relevant.
|
||||
require
|
||||
is_integer_path_parameter: is_integer_path_parameter (req, a_name)
|
||||
do
|
||||
Result := integer_from (path_parameter (req, a_name))
|
||||
end
|
||||
|
||||
feature -- Convertion
|
||||
|
||||
string_from (a_value: detachable WSF_VALUE): detachable READABLE_STRING_32
|
||||
-- String value from `a_value' if relevant.
|
||||
do
|
||||
if attached {WSF_STRING} a_value as val then
|
||||
Result := val.value
|
||||
end
|
||||
end
|
||||
|
||||
integer_from (a_value: detachable WSF_VALUE): INTEGER
|
||||
-- String value from `a_value' if relevant.
|
||||
do
|
||||
if attached string_from (a_value) as val then
|
||||
if val.is_integer then
|
||||
Result := val.to_integer
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
string_array_for (req: WSF_REQUEST; a_name: READABLE_STRING_GENERAL; a_item_fct: FUNCTION [ANY, TUPLE [WSF_REQUEST, READABLE_STRING_GENERAL], detachable READABLE_STRING_32]): detachable ARRAY [READABLE_STRING_32]
|
||||
-- Array of string values for query parameter `a_name' if relevant.
|
||||
local
|
||||
i: INTEGER
|
||||
n: INTEGER
|
||||
do
|
||||
from
|
||||
i := 1
|
||||
n := 1
|
||||
create Result.make_filled ("", 1, 5)
|
||||
until
|
||||
i = 0
|
||||
loop
|
||||
if attached a_item_fct.item ([req, a_name + "[" + i.out + "]"]) as v then
|
||||
Result.force (v, n)
|
||||
n := n + 1
|
||||
i := i + 1
|
||||
else
|
||||
i := 0 -- Exit
|
||||
end
|
||||
end
|
||||
Result.keep_head (n - 1)
|
||||
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
|
||||
Reference in New Issue
Block a user