Merge branch 'v1' into es17.01
This commit is contained in:
24
docs/workbook/handling_request/form/get/application.e
Normal file
24
docs/workbook/handling_request/form/get/application.e
Normal file
@@ -0,0 +1,24 @@
|
||||
note
|
||||
description: "Basic Service launcher"
|
||||
|
||||
class
|
||||
APPLICATION
|
||||
|
||||
inherit
|
||||
WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION]
|
||||
redefine
|
||||
initialize
|
||||
end
|
||||
|
||||
create
|
||||
make_and_launch
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
initialize
|
||||
-- Initialize current service.
|
||||
do
|
||||
set_service_option ("port", 9090)
|
||||
end
|
||||
|
||||
end
|
||||
101
docs/workbook/handling_request/form/get/application_execution.e
Normal file
101
docs/workbook/handling_request/form/get/application_execution.e
Normal 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
|
||||
51
docs/workbook/handling_request/form/get/form.ecf
Normal file
51
docs/workbook/handling_request/form/get/form.ecf
Normal file
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-16-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.eiffel.com/developers/xml/configuration-1-16-0.xsd" name="form" uuid="4BF86AB0-AEEE-46BF-93DE-0463E3510ACE">
|
||||
<target name="common" abstract="true">
|
||||
<file_rule>
|
||||
<exclude>/.svn$</exclude>
|
||||
<exclude>/CVS$</exclude>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
</file_rule>
|
||||
<option warning="true">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
|
||||
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http.ecf"/>
|
||||
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf.ecf"/>
|
||||
</target>
|
||||
<target name="form_standalone" extends="common">
|
||||
<root class="APPLICATION" feature="make_and_launch"/>
|
||||
<option warning="true">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<capability>
|
||||
<void_safety support="all"/>
|
||||
</capability>
|
||||
<library name="default_standalone" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\standalone.ecf"/>
|
||||
<cluster name="form" location=".\" recursive="true"/>
|
||||
</target>
|
||||
<target name="form_cgi" extends="common">
|
||||
<root class="APPLICATION" feature="make_and_launch"/>
|
||||
<option warning="true">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<capability>
|
||||
<void_safety support="all"/>
|
||||
</capability>
|
||||
<library name="default_cgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\cgi.ecf"/>
|
||||
<cluster name="form" location=".\" recursive="true"/>
|
||||
</target>
|
||||
<target name="form_libfcgi" extends="common">
|
||||
<root class="APPLICATION" feature="make_and_launch"/>
|
||||
<option warning="true">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<capability>
|
||||
<void_safety support="all"/>
|
||||
</capability>
|
||||
<library name="default_libfcgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\libfcgi.ecf"/>
|
||||
<cluster name="form" location=".\" recursive="true"/>
|
||||
</target>
|
||||
<target name="form" extends="form_standalone">
|
||||
</target>
|
||||
</system>
|
||||
49
docs/workbook/handling_request/form/get/form.html
Normal file
49
docs/workbook/handling_request/form/get/form.html
Normal file
@@ -0,0 +1,49 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>EWF Handling Client Request: Search Form example </title>
|
||||
</head>
|
||||
<body>
|
||||
<h1> EWF Handling Search Request: Form example </h1>
|
||||
<form action="/search" method="GET">
|
||||
<fieldset>
|
||||
<legend>Search by</legend>
|
||||
<div>
|
||||
<label>First Name
|
||||
<input id="given-name" name="given-name" type="text" placeholder="First name only" autofocus>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>Last Name
|
||||
<input id="family-name" name="family-name" type="text" placeholder="Last name only" autofocus>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>Date of Birth
|
||||
<input id="dob" name="dob" type="date">
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>Email
|
||||
<input id="email" name="email" type="email" placeholder="example@domain.com">
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>Languages
|
||||
<input type="checkbox" name="languages" value="Spanish"> Spanish
|
||||
<input type="checkbox" name="languages" value="English"> English
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<div>
|
||||
<button type=submit>Submit Form</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
<h2> Example link </h2>
|
||||
<div>
|
||||
<a href="/link?tab[a]=1&tab[b]=2&tab[c]=foo">Link</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
24
docs/workbook/handling_request/form/post/application.e
Normal file
24
docs/workbook/handling_request/form/post/application.e
Normal file
@@ -0,0 +1,24 @@
|
||||
note
|
||||
description: "Basic Service launcher"
|
||||
|
||||
class
|
||||
APPLICATION
|
||||
|
||||
inherit
|
||||
WSF_DEFAULT_SERVICE [APPLICATION_EXECUTION]
|
||||
redefine
|
||||
initialize
|
||||
end
|
||||
|
||||
create
|
||||
make_and_launch
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
initialize
|
||||
-- Initialize current service.
|
||||
do
|
||||
set_service_option ("port", 9090)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -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
|
||||
51
docs/workbook/handling_request/form/post/form.ecf
Normal file
51
docs/workbook/handling_request/form/post/form.ecf
Normal file
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-16-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.eiffel.com/developers/xml/configuration-1-16-0.xsd" name="form" uuid="C28C4F53-9963-46C0-A080-8F13E94E7486">
|
||||
<target name="common" abstract="true">
|
||||
<file_rule>
|
||||
<exclude>/.svn$</exclude>
|
||||
<exclude>/CVS$</exclude>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
</file_rule>
|
||||
<option warning="true">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
|
||||
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http.ecf"/>
|
||||
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf.ecf"/>
|
||||
</target>
|
||||
<target name="form_standalone" extends="common">
|
||||
<root class="APPLICATION" feature="make_and_launch"/>
|
||||
<option warning="true">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<capability>
|
||||
<void_safety support="all"/>
|
||||
</capability>
|
||||
<library name="default_standalone" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\standalone.ecf"/>
|
||||
<cluster name="form" location=".\" recursive="true"/>
|
||||
</target>
|
||||
<target name="form_cgi" extends="common">
|
||||
<root class="APPLICATION" feature="make_and_launch"/>
|
||||
<option warning="true">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<capability>
|
||||
<void_safety support="all"/>
|
||||
</capability>
|
||||
<library name="default_cgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\cgi.ecf"/>
|
||||
<cluster name="form" location=".\" recursive="true"/>
|
||||
</target>
|
||||
<target name="form_libfcgi" extends="common">
|
||||
<root class="APPLICATION" feature="make_and_launch"/>
|
||||
<option warning="true">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<capability>
|
||||
<void_safety support="all"/>
|
||||
</capability>
|
||||
<library name="default_libfcgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\libfcgi.ecf"/>
|
||||
<cluster name="form" location=".\" recursive="true"/>
|
||||
</target>
|
||||
<target name="form" extends="form_standalone">
|
||||
</target>
|
||||
</system>
|
||||
56
docs/workbook/handling_request/form/post/form.html
Normal file
56
docs/workbook/handling_request/form/post/form.html
Normal file
@@ -0,0 +1,56 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>EWF Handling Client Request: Form example </title>
|
||||
</head>
|
||||
<body>
|
||||
<h1> EWF Handling Client Request: Form example </h1>
|
||||
<form action="/" method="POST">
|
||||
<fieldset>
|
||||
<legend>Personal details</legend>
|
||||
<div>
|
||||
<label>First Name
|
||||
<input id="given-name" name="given-name" type="text" placeholder="First name only" required autofocus>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>Last Name
|
||||
<input id="family-name" name="family-name" type="text" placeholder="Last name only" required autofocus>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>Date of Birth
|
||||
<input id="dob" name="dob" type="date" required>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>Email
|
||||
<input id="email" name="email" type="email" placeholder="example@domain.com" required>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>URL
|
||||
<input id="url" name="url" type="url" placeholder="http://mysite.com">
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>Telephone
|
||||
<input id="phone" name="phone" type="tel" placeholder="Eg. +447000 000000" required>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>Languages
|
||||
<input type="checkbox" name="languages" value="Spanish"> Spanish
|
||||
<input type="checkbox" name="languages" value="English"> English
|
||||
</label>
|
||||
</div>
|
||||
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<div>
|
||||
<button type=submit>Submit Form</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user