Adopted convention name and value or values for WSF_VALUE and descendant (WSF_STRING ...)
kept `key' as redirection, and also string as obsolete redirection. Router: provide a way to pass the request methods without using manifest string, thanks to WSF_ROUTER_METHODS so instead of using manifest array or manifest strings, just create an instance of WSF_ROUTER_METHODS for convenience, WSF_ROUTER provides a few `methods_...' returning prebuilt WSF_ROUTER_METHODS objects Improved code related to unicode handling in URL, and parameters (before the framework was doing too much)
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="concurrency" value="thread"/>
|
||||
<precompile name="precomp_wsf-mt" location="..\..\..\..\precomp\wsf-mt-safe.ecf"/>
|
||||
<precompile name="precomp_wsf-mt" location="..\..\..\..\precomp\wsf-mt-safe.ecf"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="wsf" location="..\..\..\..\library\server\wsf\wsf-safe.ecf"/>
|
||||
<library name="default_nino" location="..\..\..\..\library\server\wsf\default\nino-safe.ecf"/>
|
||||
|
||||
@@ -30,11 +30,10 @@ feature {NONE} -- Initialization
|
||||
do
|
||||
router.map_agent ("/hello", agent execute_hello)
|
||||
|
||||
router.map_with_request_methods ("/users/{user}/message/{mesgid}", create {USER_MESSAGE_HANDLER}, router.methods_GET_POST)
|
||||
router.map_with_request_methods ("/users/{user}/message/", create {USER_MESSAGE_HANDLER}, router.methods_GET_POST)
|
||||
|
||||
router.map_with_request_methods ("/users/{user}/message/{mesgid}", create {USER_MESSAGE_HANDLER}, <<"GET", "POST">>)
|
||||
router.map_with_request_methods ("/users/{user}/message/", create {USER_MESSAGE_HANDLER}, <<"GET", "POST">>)
|
||||
|
||||
router.map_agent_response_with_request_methods ("/users/{user}/{?op}", agent response_user, <<"GET">>)
|
||||
router.map_agent_response_with_request_methods ("/users/{user}/{?op}", agent response_user, router.methods_GET)
|
||||
end
|
||||
|
||||
feature -- Execution
|
||||
@@ -50,6 +49,7 @@ feature -- Execution
|
||||
local
|
||||
mesg: WSF_HTML_PAGE_RESPONSE
|
||||
s: STRING_8
|
||||
l_user_name: READABLE_STRING_32
|
||||
do
|
||||
--| It is now returning a WSF_HTML_PAGE_RESPONSE
|
||||
--| Since it is easier for building html page
|
||||
@@ -59,9 +59,12 @@ feature -- Execution
|
||||
--| this could be a query, or a form parameter
|
||||
if attached {WSF_STRING} req.item ("user") as u then
|
||||
--| If yes, say hello world #name
|
||||
s := "<p>Hello " + u.html_encoded_string + "!</p>"
|
||||
s.append ("Display a <a href=%"/users/" + u.url_encoded_string + "/message/%">message</a></p>")
|
||||
s.append ("<p>Click <a href=%"/users/" + u.url_encoded_string + "/?op=quit%">here</a> to quit.</p>")
|
||||
|
||||
l_user_name := (create {HTML_ENCODER}).decoded_string (u.value)
|
||||
|
||||
s := "<p>Hello " + mesg.html_encoded_string (l_user_name) + "!</p>"
|
||||
s.append ("Display a <a href=%"/users/" + u.url_encoded_value + "/message/%">message</a></p>")
|
||||
s.append ("<p>Click <a href=%"/users/" + u.url_encoded_value + "/?op=quit%">here</a> to quit.</p>")
|
||||
mesg.set_body (s)
|
||||
--| We should html encode this name
|
||||
--| but to keep the example simple, we don't do that for now.
|
||||
@@ -69,7 +72,7 @@ feature -- Execution
|
||||
--| Otherwise, ask for name
|
||||
s := (create {HTML_ENCODER}).encoded_string ({STRING_32} "Hello / ahoj / नमस्ते / Ciào / مرحبا / Hola / 你好 / Hallo / Selam / Bonjour ")
|
||||
s.append ("[
|
||||
<form action="/hello" method="POST">
|
||||
<form action="/hello" method="GET">
|
||||
What is your name?</p>
|
||||
<input type="text" name="user"/>
|
||||
<input type="submit" value="Validate"/>
|
||||
@@ -96,30 +99,33 @@ feature -- Execution
|
||||
html: WSF_HTML_PAGE_RESPONSE
|
||||
redir: WSF_HTML_DELAYED_REDIRECTION_RESPONSE
|
||||
s: STRING_8
|
||||
l_username: STRING_32
|
||||
do
|
||||
if attached {WSF_STRING} ctx.path_parameter ("user") as u then
|
||||
l_username := (create {HTML_ENCODER}).general_decoded_string (u.value)
|
||||
if
|
||||
attached {WSF_STRING} req.query_parameter ("op") as l_op
|
||||
then
|
||||
if l_op.is_case_insensitive_equal ("quit") then
|
||||
create redir.make (req.script_url ("/hello"), 5)
|
||||
redir.set_title ("Bye " + u.url_encoded_string)
|
||||
redir.set_body ("Bye " + u.url_encoded_string + ",<br/> see you soon.<p>You will be redirected to " +
|
||||
redir.set_title ("Bye " + u.url_encoded_value)
|
||||
redir.set_body ("Bye " + u.url_encoded_value + ",<br/> see you soon.<p>You will be redirected to " +
|
||||
redir.url_location + " in " + redir.delay.out + " second(s) ...</p>"
|
||||
)
|
||||
Result := redir
|
||||
else
|
||||
create html.make
|
||||
html.set_title ("Bad request")
|
||||
html.set_body ("Bad request: unknown operation '" + l_op.url_encoded_string + "'.")
|
||||
html.set_body ("Bad request: unknown operation '" + l_op.url_encoded_value + "'.")
|
||||
Result := html
|
||||
end
|
||||
else
|
||||
s := "<p>User <em>'" + u.url_encoded_string + "'</em>!</p>"
|
||||
s.append ("Display a <a href=%"/users/" + u.url_encoded_string + "/message/%">message</a></p>")
|
||||
s.append ("<p>Click <a href=%"/users/" + u.url_encoded_string + "/?op=quit%">here</a> to quit.</p>")
|
||||
create html.make
|
||||
html.set_title ("User '" + u.url_encoded_string + "'")
|
||||
|
||||
s := "<p>User <em>'" + html.html_encoded_string (l_username) + "'</em>!</p>"
|
||||
s.append ("Display a <a href=%"/users/" + u.url_encoded_value + "/message/%">message</a></p>")
|
||||
s.append ("<p>Click <a href=%"/users/" + u.url_encoded_value + "/?op=quit%">here</a> to quit.</p>")
|
||||
html.set_title ("User '" + u.url_encoded_value + "'")
|
||||
html.set_body (s)
|
||||
Result := html
|
||||
end
|
||||
|
||||
@@ -14,12 +14,15 @@ inherit
|
||||
feature -- Access
|
||||
|
||||
response (ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST): WSF_RESPONSE_MESSAGE
|
||||
local
|
||||
l_username: READABLE_STRING_32
|
||||
do
|
||||
if attached {WSF_STRING} ctx.path_parameter ("user") as u then
|
||||
l_username := html_decoded_string (u.value)
|
||||
if req.is_request_method ("GET") then
|
||||
Result := user_message_get (u, ctx, req)
|
||||
Result := user_message_get (l_username, ctx, req)
|
||||
elseif req.is_request_method ("POST") then
|
||||
Result := user_message_response_post (u, ctx, req)
|
||||
Result := user_message_response_post (l_username, ctx, req)
|
||||
else
|
||||
Result := unsupported_method_response (req)
|
||||
end
|
||||
@@ -43,12 +46,12 @@ feature -- Access
|
||||
end
|
||||
|
||||
|
||||
user_message_get (u: WSF_STRING; ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST): WSF_HTML_PAGE_RESPONSE
|
||||
user_message_get (u: READABLE_STRING_32; ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST): WSF_HTML_PAGE_RESPONSE
|
||||
local
|
||||
s: STRING_8
|
||||
do
|
||||
create Result.make
|
||||
s := "<p>No message from user '" + u.html_encoded_string + "'.</p>"
|
||||
s := "<p>No message from user '" + Result.html_encoded_string (u) + "'.</p>"
|
||||
s.append ("<form action=%""+ req.request_uri +"%" method=%"POST%">")
|
||||
s.append ("<textarea name=%"message%" rows=%"10%" cols=%"70%" ></textarea>")
|
||||
s.append ("<input type=%"submit%" value=%"Ok%" />")
|
||||
@@ -56,18 +59,32 @@ feature -- Access
|
||||
Result.set_body (s)
|
||||
end
|
||||
|
||||
user_message_response_post (u: WSF_STRING; ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST): WSF_HTML_PAGE_RESPONSE
|
||||
user_message_response_post (u: READABLE_STRING_32; ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST): WSF_HTML_PAGE_RESPONSE
|
||||
local
|
||||
s: STRING_8
|
||||
do
|
||||
create Result.make
|
||||
s := "<p>Message from user '<a href=%"/users/" + u.url_encoded_string + "/%">" + u.html_encoded_string + "</a>'.</p>"
|
||||
s := "<p>Message from user '<a href=%"/users/" + url_encoded_string (u) + "/%">" + Result.html_encoded_string (u) + "</a>'.</p>"
|
||||
if attached {WSF_STRING} req.form_parameter ("message") as m and then not m.is_empty then
|
||||
s.append ("<textarea>"+ m.string +"</textarea>")
|
||||
s.append ("<textarea>"+ m.value +"</textarea>")
|
||||
else
|
||||
s.append ("<strong>No or empty message!</strong>")
|
||||
end
|
||||
Result.set_body (s)
|
||||
end
|
||||
|
||||
url_encoded_string (s: READABLE_STRING_32): STRING_8
|
||||
do
|
||||
Result := (create {UTF8_URL_ENCODER}).encoded_string (s)
|
||||
end
|
||||
|
||||
html_decoded_string (v: READABLE_STRING_32): READABLE_STRING_32
|
||||
do
|
||||
if v.is_valid_as_string_8 then
|
||||
Result := (create {HTML_ENCODER}).decoded_string (v)
|
||||
else
|
||||
Result := v
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user