Updated workbook Eiffel code to follow new EWF concurrent design.

This commit is contained in:
2015-06-16 20:34:57 +02:00
parent c0d5b7c968
commit 80709578d6
26 changed files with 1409 additions and 1244 deletions

View File

@@ -1,13 +1,11 @@
note
description : "Basic Service that show how to handle a GET request"
date : "$Date$"
revision : "$Revision$"
description: "Basic Service launcher"
class
APPLICATION
inherit
WSF_DEFAULT_SERVICE
WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION]
redefine
initialize
end
@@ -23,90 +21,4 @@ feature {NONE} -- Initialization
set_service_option ("port", 9090)
end
feature -- Basic operations
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute the incomming request
local
file: WSF_FILE_RESPONSE
l_parameter_names: STRING
l_answer: STRING
idioms: LIST[STRING]
l_raw_data: STRING
do
if req.is_get_request_method then
if req.path_info.same_string ("/") then
create file.make_html ("form.html")
res.send (file)
elseif req.path_info.same_string ("/search") then
-- (1) the parameter is case sensitive
if not (attached req.query_parameter ("GIVEN-NAME")) then
-- Wrong `GIVEN-NAME' need to be in lower case.
end
-- (2) Multiple values
if attached {WSF_MULTIPLE_STRING} req.query_parameter ("languages") as l_languages then
-- Get all the associated values
create {ARRAYED_LIST[STRING]} idioms.make (2)
across l_languages as ic loop idioms.force (ic.item.value) end
elseif attached {WSF_STRING} req.query_parameter ("languages") as l_language then
-- Single value
print (l_language.value)
else
-- Value Missing
end
-- Read the all parameters names and his values.
create l_parameter_names.make_from_string ("<h2>Parameters Names</h2>")
l_parameter_names.append ("<br>")
create l_answer.make_from_string ("<h2>Parameter Names and Values</h2>")
l_answer.append ("<br>")
across req.query_parameters as ic loop
l_parameter_names.append (ic.item.key)
l_parameter_names.append ("<br>")
l_answer.append (ic.item.key)
l_answer.append_character ('=')
if attached {WSF_STRING} req.query_parameter (ic.item.key) as l_value then
l_answer.append_string (l_value.value)
end
l_answer.append ("<br>")
end
l_parameter_names.append ("<br>")
l_parameter_names.append_string (l_answer)
res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_parameter_names.count.out]>>)
res.put_string (l_parameter_names)
elseif req.path_info.same_string ("/link") then
-- WSF_TABLE example
create l_parameter_names.make_from_string ("<h2>Parameters Name</h2>")
if attached {WSF_TABLE} req.query_parameter ("tab") as l_tab then
l_parameter_names.append ("<br>")
l_parameter_names.append (l_tab.name)
from
l_tab.values.start
until
l_tab.values.after
loop
l_parameter_names.append ("<br>")
l_parameter_names.append (l_tab.values.key_for_iteration)
if attached {WSF_STRING} l_tab.value (l_tab.values.key_for_iteration) as l_value then
l_parameter_names.append ("=")
l_parameter_names.append (l_value.value)
end
l_tab.values.forth
end
l_parameter_names.append ("<br>")
res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_parameter_names.count.out]>>)
res.put_string (l_parameter_names)
end
else
-- Here we should handle unexpected errors.
end
end
end
end

View File

@@ -0,0 +1,101 @@
note
description : "Basic Service that show how to handle a GET request"
date : "$Date$"
revision : "$Revision$"
class
APPLICATION_EXECUTION
inherit
WSF_EXECUTION
create
make
feature -- Basic operations
execute
-- Execute the incomming request
local
file: WSF_FILE_RESPONSE
l_parameter_names: STRING
l_answer: STRING
idioms: LIST[STRING]
l_raw_data: STRING
do
if request.is_get_request_method then
if request.path_info.same_string ("/") then
create file.make_html ("form.html")
response.send (file)
elseif request.path_info.same_string ("/search") then
-- (1) the parameter is case sensitive
if not (attached request.query_parameter ("GIVEN-NAME")) then
-- Wrong `GIVEN-NAME' need to be in lower case.
end
-- (2) Multiple values
if attached {WSF_MULTIPLE_STRING} request.query_parameter ("languages") as l_languages then
-- Get all the associated values
create {ARRAYED_LIST[STRING]} idioms.make (2)
across l_languages as ic loop idioms.force (ic.item.value) end
elseif attached {WSF_STRING} request.query_parameter ("languages") as l_language then
-- Single value
print (l_language.value)
else
-- Value Missing
end
-- Read the all parameters names and his values.
create l_parameter_names.make_from_string ("<h2>Parameters Names</h2>")
l_parameter_names.append ("<br>")
create l_answer.make_from_string ("<h2>Parameter Names and Values</h2>")
l_answer.append ("<br>")
across request.query_parameters as ic loop
l_parameter_names.append (ic.item.key)
l_parameter_names.append ("<br>")
l_answer.append (ic.item.key)
l_answer.append_character ('=')
if attached {WSF_STRING} request.query_parameter (ic.item.key) as l_value then
l_answer.append_string (l_value.value)
end
l_answer.append ("<br>")
end
l_parameter_names.append ("<br>")
l_parameter_names.append_string (l_answer)
response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_parameter_names.count.out]>>)
response.put_string (l_parameter_names)
elseif request.path_info.same_string ("/link") then
-- WSF_TABLE example
create l_parameter_names.make_from_string ("<h2>Parameters Name</h2>")
if attached {WSF_TABLE} request.query_parameter ("tab") as l_tab then
l_parameter_names.append ("<br>")
l_parameter_names.append (l_tab.name)
from
l_tab.values.start
until
l_tab.values.after
loop
l_parameter_names.append ("<br>")
l_parameter_names.append (l_tab.values.key_for_iteration)
if attached {WSF_STRING} l_tab.value (l_tab.values.key_for_iteration) as l_value then
l_parameter_names.append ("=")
l_parameter_names.append (l_value.value)
end
l_tab.values.forth
end
l_parameter_names.append ("<br>")
response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_parameter_names.count.out]>>)
response.put_string (l_parameter_names)
end
else
-- Here we should handle unexpected errors.
end
end
end
end

View File

@@ -1,13 +1,11 @@
note
description : "Reading Parameters from a HTML FORM (method POST) "
date : "$Date$"
revision : "$Revision$"
description: "Basic Service launcher"
class
APPLICATION
inherit
WSF_DEFAULT_SERVICE
WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION]
redefine
initialize
end
@@ -23,72 +21,4 @@ feature {NONE} -- Initialization
set_service_option ("port", 9090)
end
feature -- Basic operations
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute the incomming request
local
file: WSF_FILE_RESPONSE
l_parameter_names: STRING
l_answer: STRING
idioms: LIST[STRING]
l_raw_data: STRING
do
if req.is_get_request_method then
create file.make_html ("form.html")
res.send (file)
elseif req.is_post_request_method then
req.set_raw_input_data_recorded (True)
-- (3) Read Raw Data
create l_raw_data.make_empty
req.read_input_data_into (l_raw_data)
-- (1) the parameter is case sensitive
if not (attached req.form_parameter ("GIVEN-NAME")) then
-- Wrong `GIVEN-NAME' need to be in lower case.
end
-- (2) Multiple values
if attached {WSF_MULTIPLE_STRING} req.form_parameter ("languages") as l_languages then
-- Get all the associated values
create {ARRAYED_LIST[STRING]} idioms.make (2)
across l_languages as ic loop idioms.force (ic.item.value) end
elseif attached {WSF_STRING} req.form_parameter ("langauges") as l_language then
-- Single value
print (l_language.value)
else
-- Value Missing
end
-- Read the all parameters names and his values.
create l_parameter_names.make_from_string ("<h2>Parameters Names</h2>")
l_parameter_names.append ("<br>")
create l_answer.make_from_string ("<h2>Parameter Names and Values</h2>")
l_answer.append ("<br>")
across req.form_parameters as ic loop
l_parameter_names.append (ic.item.key)
l_parameter_names.append ("<br>")
l_answer.append (ic.item.key)
l_answer.append_character ('=')
if attached {WSF_STRING} req.form_parameter (ic.item.key) as l_value then
l_answer.append_string (l_value.value)
end
l_answer.append ("<br>")
end
l_parameter_names.append ("<br>")
l_parameter_names.append_string (l_answer)
l_parameter_names.append ("<br>")
l_parameter_names.append ("<h2>Raw content</h2>")
l_parameter_names.append (l_raw_data)
res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_parameter_names.count.out]>>)
res.put_string (l_parameter_names)
else
-- Here we should handle unexpected errors.
end
end
end

View File

@@ -0,0 +1,83 @@
note
description : "Reading Parameters from a HTML FORM (method POST) "
date : "$Date$"
revision : "$Revision$"
class
APPLICATION_EXECUTION
inherit
WSF_EXECUTION
create
make
feature -- Basic operations
execute
-- Execute the incomming request
local
file: WSF_FILE_RESPONSE
l_parameter_names: STRING
l_answer: STRING
idioms: LIST[STRING]
l_raw_data: STRING
do
if request.is_get_request_method then
create file.make_html ("form.html")
response.send (file)
elseif request.is_post_request_method then
request.set_raw_input_data_recorded (True)
-- (3) Read Raw Data
create l_raw_data.make_empty
request.read_input_data_into (l_raw_data)
-- (1) the parameter is case sensitive
if not (attached request.form_parameter ("GIVEN-NAME")) then
-- Wrong `GIVEN-NAME' need to be in lower case.
end
-- (2) Multiple values
if attached {WSF_MULTIPLE_STRING} request.form_parameter ("languages") as l_languages then
-- Get all the associated values
create {ARRAYED_LIST[STRING]} idioms.make (2)
across l_languages as ic loop idioms.force (ic.item.value) end
elseif attached {WSF_STRING} request.form_parameter ("langauges") as l_language then
-- Single value
print (l_language.value)
else
-- Value Missing
end
-- Read the all parameters names and his values.
create l_parameter_names.make_from_string ("<h2>Parameters Names</h2>")
l_parameter_names.append ("<br>")
create l_answer.make_from_string ("<h2>Parameter Names and Values</h2>")
l_answer.append ("<br>")
across request.form_parameters as ic loop
l_parameter_names.append (ic.item.key)
l_parameter_names.append ("<br>")
l_answer.append (ic.item.key)
l_answer.append_character ('=')
if attached {WSF_STRING} request.form_parameter (ic.item.key) as l_value then
l_answer.append_string (l_value.value)
end
l_answer.append ("<br>")
end
l_parameter_names.append ("<br>")
l_parameter_names.append_string (l_answer)
l_parameter_names.append ("<br>")
l_parameter_names.append ("<h2>Raw content</h2>")
l_parameter_names.append (l_raw_data)
response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_parameter_names.count.out]>>)
response.put_string (l_parameter_names)
else
-- Here we should handle unexpected errors.
end
end
end

View File

@@ -1,14 +1,11 @@
note
description : "Basic Service that Read a Request, a "
date : "$Date$"
revision : "$Revision$"
EIS: "name=Browser detection using user agent","src=https://developer.mozilla.org/en-US/docs/Browser_detection_using_the_user_agent", "protocol=url"
description: "Basic Service launcher"
class
APPLICATION
inherit
WSF_DEFAULT_SERVICE
WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION]
redefine
initialize
end
@@ -22,88 +19,6 @@ feature {NONE} -- Initialization
-- Initialize current service.
do
set_service_option ("port", 9090)
set_service_option ("verbose", true)
end
feature -- Basic operations
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute the incomming request
local
l_raw_data: STRING
l_page_response: STRING
l_rows: STRING
do
create l_page_response.make_from_string (html_template)
if req.path_info.same_string ("/") then
-- retrieve the user-agent
if attached req.http_user_agent as l_user_agent then
l_page_response.replace_substring_all ("$user_agent", l_user_agent)
l_page_response.replace_substring_all ("$browser", get_browser_name (l_user_agent))
else
l_page_response.replace_substring_all ("$user_agent", "[]")
l_page_response.replace_substring_all ("$browser", "Unknown, the user-agent was not present.")
end
res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_page_response.count.out]>>)
res.put_string (l_page_response)
end
end
feature -- Browser utility
get_browser_name (a_user_agent: READABLE_STRING_8):READABLE_STRING_32
-- Must contain Must not contain
-- Firefox Firefox/xyz Seamonkey/xyz
-- Seamonkey Seamonkey/xyz
-- Chrome Chrome/xyz Chromium/xyz
-- Chromium Chromium/xyz
-- Safari Safari/xyz Chrome/xyz
-- Chromium/xyz
-- Opera OPR/xyz [1]
-- Opera/xyz [2]
-- Internet Explorer ;MSIE xyz; Internet Explorer doesn't put its name in the BrowserName/VersionNumber format
do
if
a_user_agent.has_substring ("Firefox") and then
not a_user_agent.has_substring ("Seamonkey")
then
Result := "Firefox"
elseif a_user_agent.has_substring ("Seamonkey") then
Result := "Seamonkey"
elseif a_user_agent.has_substring ("Chrome") and then not a_user_agent.has_substring ("Chromium")then
Result := "Chrome"
elseif a_user_agent.has_substring ("Chromium") then
Result := "Chromiun"
elseif a_user_agent.has_substring ("Safari") and then not (a_user_agent.has_substring ("Chrome") or else a_user_agent.has_substring ("Chromium")) then
Result := "Safari"
elseif a_user_agent.has_substring ("OPR") or else a_user_agent.has_substring ("Opera") then
Result := "Opera"
elseif a_user_agent.has_substring ("MSIE") or else a_user_agent.has_substring ("Trident")then
Result := "Internet Explorer"
else
Result := "Unknown"
end
end
html_template: STRING = "[
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>EWF service example: Showing Browser Dectection Using User-Agent</h1> <br>
<strong>User Agent:</strong> $user_agent <br>
<h2>Enjoy using $browser </h2>
</body>
</html>
]"
end

View File

@@ -0,0 +1,97 @@
note
description : "Basic Service that Read a Request, a "
date : "$Date$"
revision : "$Revision$"
EIS: "name=Browser detection using user agent","src=https://developer.mozilla.org/en-US/docs/Browser_detection_using_the_user_agent", "protocol=url"
class
APPLICATION_EXECUTION
inherit
WSF_EXECUTION
create
make
feature -- Basic operations
execute
-- Execute the incomming request
local
l_raw_data: STRING
l_page_response: STRING
l_rows: STRING
do
create l_page_response.make_from_string (html_template)
if request.path_info.same_string ("/") then
-- retrieve the user-agent
if attached request.http_user_agent as l_user_agent then
l_page_response.replace_substring_all ("$user_agent", l_user_agent)
l_page_response.replace_substring_all ("$browser", browser_name (l_user_agent))
else
l_page_response.replace_substring_all ("$user_agent", "[]")
l_page_response.replace_substring_all ("$browser", "Unknown, the user-agent was not present.")
end
response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_page_response.count.out]>>)
response.put_string (l_page_response)
end
end
feature -- Browser utility
browser_name (a_user_agent: READABLE_STRING_8): STRING_8
-- Must contain Must not contain
-- Firefox Firefox/xyz Seamonkey/xyz
-- Seamonkey Seamonkey/xyz
-- Chrome Chrome/xyz Chromium/xyz
-- Chromium Chromium/xyz
-- Safari Safari/xyz Chrome/xyz
-- Chromium/xyz
-- Opera OPR/xyz [1]
-- Opera/xyz [2]
-- Internet Explorer ;MSIE xyz; Internet Explorer doesn't put its name in the BrowserName/VersionNumber format
do
if
a_user_agent.has_substring ("Firefox") and then
not a_user_agent.has_substring ("Seamonkey")
then
Result := "Firefox"
elseif a_user_agent.has_substring ("Seamonkey") then
Result := "Seamonkey"
elseif a_user_agent.has_substring ("Chrome") and then not a_user_agent.has_substring ("Chromium")then
Result := "Chrome"
elseif a_user_agent.has_substring ("Chromium") then
Result := "Chromiun"
elseif a_user_agent.has_substring ("Safari") and then not (a_user_agent.has_substring ("Chrome") or else a_user_agent.has_substring ("Chromium")) then
Result := "Safari"
elseif a_user_agent.has_substring ("OPR") or else a_user_agent.has_substring ("Opera") then
Result := "Opera"
elseif a_user_agent.has_substring ("MSIE") or else a_user_agent.has_substring ("Trident")then
Result := "Internet Explorer"
else
Result := "Unknown"
end
end
html_template: STRING = "[
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>EWF service example: Showing Browser Dectection Using User-Agent</h1> <br>
<strong>User Agent:</strong> $user_agent <br>
<h2>Enjoy using $browser </h2>
</body>
</html>
]"
end

View File

@@ -1,14 +1,11 @@
note
description : "Basic Service that shows the standard CGI variables"
date : "$Date$"
revision : "$Revision$"
EIS: "name=CGI specification","src=(https://tools.ietf.org/html/rfc3875", "protocol=url"
description: "Basic Service launcher"
class
APPLICATION
inherit
WSF_DEFAULT_SERVICE
WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION]
redefine
initialize
end
@@ -22,294 +19,6 @@ feature {NONE} -- Initialization
-- Initialize current service.
do
set_service_option ("port", 9090)
set_service_option ("verbose", true)
end
feature -- Basic operations
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute the incomming request
local
l_raw_data: STRING
l_page_response: STRING
l_rows: STRING
do
create l_page_response.make_from_string (html_template)
if req.path_info.same_string ("/") then
-- HTTP method
l_page_response.replace_substring_all ("$http_method", req.request_method)
-- URI
l_page_response.replace_substring_all ("$uri", req.path_info)
-- Protocol
l_page_response.replace_substring_all ("$protocol", req.server_protocol)
-- Fill the table rows with CGI standard variables
create l_rows.make_empty
-- Auth_type
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("AUTH_TYPE")
l_rows.append ("</td>")
l_rows.append ("<td>")
if attached req.auth_type as l_type then
l_rows.append (l_type)
else
l_rows.append ("Not present")
end
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Content length
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("CONTENT_LENGTH")
l_rows.append ("</td>")
l_rows.append ("<td>")
if attached req.content_length as l_content_length then
l_rows.append (l_content_length)
else
l_rows.append ("Not present")
end
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Content length
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("CONTENT_TYPE")
l_rows.append ("</td>")
l_rows.append ("<td>")
if attached req.content_type as l_content_type then
l_rows.append (l_content_type.string)
else
l_rows.append ("Not present")
end
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Gateway interface
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("GATEWAY_INTERFACE")
l_rows.append ("</td>")
l_rows.append ("<td>")
if attached req.gateway_interface as l_gateway_interface then
l_rows.append (l_gateway_interface)
else
l_rows.append ("Not present")
end
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Path info
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("PATH_INFO")
l_rows.append ("</td>")
l_rows.append ("<td>")
if attached req.path_info as l_path_info then
l_rows.append (l_path_info)
else
l_rows.append ("Not present")
end
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Path translated
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("PATH_TRANSLATED")
l_rows.append ("</td>")
l_rows.append ("<td>")
if attached req.path_translated as l_path_translated then
l_rows.append (l_path_translated)
else
l_rows.append ("Not present")
end
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Query string
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("QUERY_STRING")
l_rows.append ("</td>")
l_rows.append ("<td>")
if attached req.query_string as l_query_string then
l_rows.append (l_query_string)
else
l_rows.append ("Not present")
end
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Remote addr
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("REMOTE_ADDR")
l_rows.append ("</td>")
l_rows.append ("<td>")
l_rows.append (req.remote_addr)
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Remote host
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("REMOTE_HOST")
l_rows.append ("</td>")
l_rows.append ("<td>")
if attached req.remote_host as l_remote_host then
l_rows.append (l_remote_host)
else
l_rows.append ("Not present")
end
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Remote ident
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("REMOTE_IDENT")
l_rows.append ("</td>")
l_rows.append ("<td>")
if attached req.remote_ident as l_remote_ident then
l_rows.append (l_remote_ident)
else
l_rows.append ("Not present")
end
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Remote user
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("REMOTE_USER")
l_rows.append ("</td>")
l_rows.append ("<td>")
if attached req.remote_user as l_remote_user then
l_rows.append (l_remote_user)
else
l_rows.append ("Not present")
end
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Request method
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("REQUEST_METHOD")
l_rows.append ("</td>")
l_rows.append ("<td>")
l_rows.append (req.request_method)
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Script name
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("SCRIPT_NAME")
l_rows.append ("</td>")
l_rows.append ("<td>")
l_rows.append (req.script_name)
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Server name
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("SERVER_NAME")
l_rows.append ("</td>")
l_rows.append ("<td>")
l_rows.append (req.server_name)
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Server protocol
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("SERVER_PROTOCOL")
l_rows.append ("</td>")
l_rows.append ("<td>")
l_rows.append (req.server_protocol)
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Server software
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("SERVER_SOFTWARE")
l_rows.append ("</td>")
l_rows.append ("<td>")
l_rows.append (req.server_software)
l_rows.append ("</td>")
l_rows.append ("</tr>")
l_page_response.replace_substring_all ("$rows", l_rows)
-- Reading the raw header
if attached req.raw_header_data as l_raw_header then
l_page_response.replace_substring_all ("$raw_header", l_raw_header)
end
res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_page_response.count.out]>>)
res.put_string (l_page_response)
end
end
html_template: STRING = "[
<!DOCTYPE html>
<html>
<head>
<style>
thead {color:green;}
tbody {color:blue;}
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<h1>EWF service example: Showing Standard CGI Variables</h1>
<strong>HTTP METHOD:</strong>$http_method<br>
<strong>URI:</strong>$uri<br>
<strong>PROTOCOL:</strong>$protocol<br>
<br>
<table>
<thead>
<tr>
<th>CGI Name</th>
<th>Value</th>
</tr>
</thead>
<tbody>
$rows
</tbody>
</table>
<h2>Raw header</h2>
$raw_header
</body>
</html>
]"
end

View File

@@ -0,0 +1,303 @@
note
description : "Basic Service that shows the standard CGI variables"
date : "$Date$"
revision : "$Revision$"
EIS: "name=CGI specification","src=(https://tools.ietf.org/html/rfc3875", "protocol=url"
class
APPLICATION_EXECUTION
inherit
WSF_EXECUTION
create
make
feature -- Basic operations
execute
-- Execute the incomming request
local
l_raw_data: STRING
l_page_response: STRING
l_rows: STRING
do
create l_page_response.make_from_string (html_template)
if request.path_info.same_string ("/") then
-- HTTP method
l_page_response.replace_substring_all ("$http_method", request.request_method)
-- URI
l_page_response.replace_substring_all ("$uri", request.path_info)
-- Protocol
l_page_response.replace_substring_all ("$protocol", request.server_protocol)
-- Fill the table rows with CGI standard variables
create l_rows.make_empty
-- Auth_type
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("AUTH_TYPE")
l_rows.append ("</td>")
l_rows.append ("<td>")
if attached request.auth_type as l_type then
l_rows.append (l_type)
else
l_rows.append ("Not present")
end
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Content length
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("CONTENT_LENGTH")
l_rows.append ("</td>")
l_rows.append ("<td>")
if attached request.content_length as l_content_length then
l_rows.append (l_content_length)
else
l_rows.append ("Not present")
end
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Content length
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("CONTENT_TYPE")
l_rows.append ("</td>")
l_rows.append ("<td>")
if attached request.content_type as l_content_type then
l_rows.append (l_content_type.string)
else
l_rows.append ("Not present")
end
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Gateway interface
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("GATEWAY_INTERFACE")
l_rows.append ("</td>")
l_rows.append ("<td>")
if attached request.gateway_interface as l_gateway_interface then
l_rows.append (l_gateway_interface)
else
l_rows.append ("Not present")
end
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Path info
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("PATH_INFO")
l_rows.append ("</td>")
l_rows.append ("<td>")
if attached request.path_info as l_path_info then
l_rows.append (l_path_info)
else
l_rows.append ("Not present")
end
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Path translated
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("PATH_TRANSLATED")
l_rows.append ("</td>")
l_rows.append ("<td>")
if attached request.path_translated as l_path_translated then
l_rows.append (l_path_translated)
else
l_rows.append ("Not present")
end
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Query string
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("QUERY_STRING")
l_rows.append ("</td>")
l_rows.append ("<td>")
if attached request.query_string as l_query_string then
l_rows.append (l_query_string)
else
l_rows.append ("Not present")
end
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Remote addr
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("REMOTE_ADDR")
l_rows.append ("</td>")
l_rows.append ("<td>")
l_rows.append (request.remote_addr)
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Remote host
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("REMOTE_HOST")
l_rows.append ("</td>")
l_rows.append ("<td>")
if attached request.remote_host as l_remote_host then
l_rows.append (l_remote_host)
else
l_rows.append ("Not present")
end
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Remote ident
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("REMOTE_IDENT")
l_rows.append ("</td>")
l_rows.append ("<td>")
if attached request.remote_ident as l_remote_ident then
l_rows.append (l_remote_ident)
else
l_rows.append ("Not present")
end
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Remote user
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("REMOTE_USER")
l_rows.append ("</td>")
l_rows.append ("<td>")
if attached request.remote_user as l_remote_user then
l_rows.append (l_remote_user)
else
l_rows.append ("Not present")
end
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Request method
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("REQUEST_METHOD")
l_rows.append ("</td>")
l_rows.append ("<td>")
l_rows.append (request.request_method)
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Script name
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("SCRIPT_NAME")
l_rows.append ("</td>")
l_rows.append ("<td>")
l_rows.append (request.script_name)
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Server name
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("SERVER_NAME")
l_rows.append ("</td>")
l_rows.append ("<td>")
l_rows.append (request.server_name)
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Server protocol
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("SERVER_PROTOCOL")
l_rows.append ("</td>")
l_rows.append ("<td>")
l_rows.append (request.server_protocol)
l_rows.append ("</td>")
l_rows.append ("</tr>")
-- Server software
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append ("SERVER_SOFTWARE")
l_rows.append ("</td>")
l_rows.append ("<td>")
l_rows.append (request.server_software)
l_rows.append ("</td>")
l_rows.append ("</tr>")
l_page_response.replace_substring_all ("$rows", l_rows)
-- Reading the raw header
if attached request.raw_header_data as l_raw_header then
l_page_response.replace_substring_all ("$raw_header", l_raw_header)
end
response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_page_response.count.out]>>)
response.put_string (l_page_response)
end
end
html_template: STRING = "[
<!DOCTYPE html>
<html>
<head>
<style>
thead {color:green;}
tbody {color:blue;}
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<h1>EWF service example: Showing Standard CGI Variables</h1>
<strong>HTTP METHOD:</strong>$http_method<br>
<strong>URI:</strong>$uri<br>
<strong>PROTOCOL:</strong>$protocol<br>
<br>
<table>
<thead>
<tr>
<th>CGI Name</th>
<th>Value</th>
</tr>
</thead>
<tbody>
$rows
</tbody>
</table>
<h2>Raw header</h2>
$raw_header
</body>
</html>
]"
end

View File

@@ -1,13 +1,11 @@
note
description : "Basic Service that Read Request Headers"
date : "$Date$"
revision : "$Revision$"
description: "Basic Service launcher"
class
APPLICATION
inherit
WSF_DEFAULT_SERVICE
WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION]
redefine
initialize
end
@@ -21,97 +19,6 @@ feature {NONE} -- Initialization
-- Initialize current service.
do
set_service_option ("port", 9090)
set_service_option ("verbose", true)
end
feature -- Basic operations
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute the incomming request
local
l_raw_data: STRING
l_page_response: STRING
l_rows: STRING
do
create l_page_response.make_from_string (html_template)
if req.path_info.same_string ("/") then
-- HTTP method
l_page_response.replace_substring_all ("$http_method", req.request_method)
-- URI
l_page_response.replace_substring_all ("$uri", req.path_info)
-- Protocol
l_page_response.replace_substring_all ("$protocol", req.server_protocol)
-- Fill the table rows with HTTP Headers
create l_rows.make_empty
across req.meta_variables as ic loop
if ic.item.name.starts_with ("HTTP_") then
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append (ic.item.name)
l_rows.append ("</td>")
l_rows.append ("<td>")
l_rows.append (ic.item.value)
l_rows.append ("</td>")
l_rows.append ("</tr>")
end
end
l_page_response.replace_substring_all ("$rows", l_rows)
-- Reading the raw header
if attached req.raw_header_data as l_raw_header then
l_page_response.replace_substring_all ("$raw_header", l_raw_header)
end
res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_page_response.count.out]>>)
res.put_string (l_page_response)
end
end
html_template: STRING = "[
<!DOCTYPE html>
<html>
<head>
<style>
thead {color:green;}
tbody {color:blue;}
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<h1>EWF service example: Showing Request Headers</h1>
<strong>HTTP METHOD:</strong>$http_method<br>
<strong>URI:</strong>$uri<br>
<strong>PROTOCOL:</strong>$protocol<br>
<strong>REQUEST TIME:</strong>$time<br>
<br>
<table>
<thead>
<tr>
<th>Header Name</th>
<th>Header Value</th>
</tr>
</thead>
<tbody>
$rows
</tbody>
</table>
<h2>Raw header</h2>
$raw_header
</body>
</html>
]"
end

View File

@@ -0,0 +1,105 @@
note
description : "Basic Service that Read Request Headers"
date : "$Date$"
revision : "$Revision$"
class
APPLICATION_EXECUTION
inherit
WSF_EXECUTION
create
make
feature -- Basic operations
execute
-- Execute the incomming request
local
l_raw_data: STRING
l_page_response: STRING
l_rows: STRING
do
create l_page_response.make_from_string (html_template)
if request.path_info.same_string ("/") then
-- HTTP method
l_page_response.replace_substring_all ("$http_method", request.request_method)
-- URI
l_page_response.replace_substring_all ("$uri", request.path_info)
-- Protocol
l_page_response.replace_substring_all ("$protocol", request.server_protocol)
-- Fill the table rows with HTTP Headers
create l_rows.make_empty
across request.meta_variables as ic loop
if ic.item.name.starts_with ("HTTP_") then
l_rows.append ("<tr>")
l_rows.append ("<td>")
l_rows.append (ic.item.name)
l_rows.append ("</td>")
l_rows.append ("<td>")
l_rows.append (ic.item.value)
l_rows.append ("</td>")
l_rows.append ("</tr>")
end
end
l_page_response.replace_substring_all ("$rows", l_rows)
-- Reading the raw header
if attached request.raw_header_data as l_raw_header then
l_page_response.replace_substring_all ("$raw_header", l_raw_header)
end
response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", l_page_response.count.out]>>)
response.put_string (l_page_response)
end
end
html_template: STRING = "[
<!DOCTYPE html>
<html>
<head>
<style>
thead {color:green;}
tbody {color:blue;}
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<h1>EWF service example: Showing Request Headers</h1>
<strong>HTTP METHOD:</strong>$http_method<br>
<strong>URI:</strong>$uri<br>
<strong>PROTOCOL:</strong>$protocol<br>
<strong>REQUEST TIME:</strong>$time<br>
<br>
<table>
<thead>
<tr>
<th>Header Name</th>
<th>Header Value</th>
</tr>
</thead>
<tbody>
$rows
</tbody>
</table>
<h2>Raw header</h2>
$raw_header
</body>
</html>
]"
end

View File

@@ -1,13 +1,11 @@
note
description : "Basic Service that show how to Upload a file"
date : "$Date$"
revision : "$Revision$"
description: "Basic Service launcher"
class
APPLICATION
inherit
WSF_DEFAULT_SERVICE
WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION]
redefine
initialize
end
@@ -23,47 +21,4 @@ feature {NONE} -- Initialization
set_service_option ("port", 9090)
end
feature -- Basic operations
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute the incomming request
local
file: WSF_FILE_RESPONSE
l_answer: STRING
do
if req.is_get_request_method then
if req.path_info.same_string ("/") then
create file.make_html ("upload.html")
res.send (file)
else
-- Here we should handle unexpected errors.
end
elseif req.is_post_request_method then
if req.path_info.same_string ("/upload") then
-- Check if we have an uploaded file
if req.has_uploaded_file then
-- iterate over all the uploaded files
create l_answer.make_from_string ("<h1>Uploaded File/s</h1><br>")
across req.uploaded_files as ic loop
l_answer.append ("<strong>FileName:</strong>")
l_answer.append (ic.item.filename)
l_answer.append ("<br><strong>Size:</strong>")
l_answer.append (ic.item.size.out)
l_answer.append ("<br>")
end
res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-type","text/html"],["Content-lenght", l_answer.count.out]>>)
res.put_string (l_answer)
else
-- Here we should handle unexpected errors.
create l_answer.make_from_string ("<strong>No uploaded files</strong><br>")
create l_answer.append ("Back to <a href='/'>Home</a>")
res.put_header ({HTTP_STATUS_CODE}.bad_request, <<["Content-type","text/html"],["Content-lenght", l_answer.count.out]>>)
res.put_string (l_answer)
end
else
-- Handle error
end
end
end
end

View File

@@ -0,0 +1,58 @@
note
description : "Basic Service that show how to Upload a file"
date : "$Date$"
revision : "$Revision$"
class
APPLICATION_EXECUTION
inherit
WSF_EXECUTION
create
make
feature -- Basic operations
execute
-- Execute the incomming request
local
file: WSF_FILE_RESPONSE
l_answer: STRING
do
if request.is_get_request_method then
if request.path_info.same_string ("/") then
create file.make_html ("upload.html")
response.send (file)
else
-- Here we should handle unexpected errors.
end
elseif request.is_post_request_method then
if request.path_info.same_string ("/upload") then
-- Check if we have an uploaded file
if request.has_uploaded_file then
-- iterate over all the uploaded files
create l_answer.make_from_string ("<h1>Uploaded File/s</h1><br>")
across request.uploaded_files as ic loop
l_answer.append ("<strong>FileName:</strong>")
l_answer.append (ic.item.filename)
l_answer.append ("<br><strong>Size:</strong>")
l_answer.append (ic.item.size.out)
l_answer.append ("<br>")
end
response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-type","text/html"],["Content-lenght", l_answer.count.out]>>)
response.put_string (l_answer)
else
-- Here we should handle unexpected errors.
create l_answer.make_from_string ("<strong>No uploaded files</strong><br>")
l_answer.append ("Back to <a href='/'>Home</a>")
response.put_header ({HTTP_STATUS_CODE}.bad_request, <<["Content-type","text/html"],["Content-lenght", l_answer.count.out]>>)
response.put_string (l_answer)
end
else
-- Handle error
end
end
end
end