Migrated most of the example and library to new design.

This commit is contained in:
2015-03-31 14:50:20 +02:00
parent 7d2ce8a77f
commit 4907bc3085
124 changed files with 2399 additions and 1789 deletions

View File

@@ -8,7 +8,7 @@ class
ECHO_SERVER
inherit
WSF_DEFAULT_SERVICE
WSF_DEFAULT_SERVICE [ECHO_SERVER_EXECUTION]
create
make
@@ -23,53 +23,4 @@ feature {NONE} -- Initialization
make_and_launch
end
feature -- Execution
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
local
page: WSF_PAGE_RESPONSE
l_body: STRING_8
do
create l_body.make (1024)
create page.make_with_body (l_body)
page.header.put_content_type_text_plain
l_body.append ("REQUEST_METHOD=" + req.request_method + "%N")
l_body.append ("REQUEST_URI=" + req.request_uri + "%N")
l_body.append ("PATH_INFO=" + req.path_info + "%N")
l_body.append ("QUERY_STRING=" + req.query_string + "%N")
l_body.append ("Query parameters:%N")
across
req.query_parameters as q
loop
l_body.append ("%T"+ q.item.name + "=" + q.item.string_representation +"%N")
end
l_body.append ("Form parameters:%N")
across
req.form_parameters as q
loop
l_body.append ("%T"+ q.item.name + "=" + q.item.string_representation +"%N")
end
l_body.append ("Meta variables:%N")
across
req.meta_variables as q
loop
l_body.append ("%T"+ q.item.name + "=" + q.item.string_representation +"%N")
end
res.send (page)
end
feature -- Access
feature -- Change
feature {NONE} -- Implementation
invariant
-- invariant_clause: True
end

View File

@@ -0,0 +1,59 @@
note
description : "Objects that ..."
author : "$Author$"
date : "$Date$"
revision : "$Revision$"
class
ECHO_SERVER_EXECUTION
inherit
WSF_EXECUTION
create
make
feature -- Execution
execute
local
req: WSF_REQUEST; res: WSF_RESPONSE
page: WSF_PAGE_RESPONSE
l_body: STRING_8
do
req := request
res := response
create l_body.make (1024)
create page.make_with_body (l_body)
page.header.put_content_type_text_plain
l_body.append ("REQUEST_METHOD=" + req.request_method + "%N")
l_body.append ("REQUEST_URI=" + req.request_uri + "%N")
l_body.append ("PATH_INFO=" + req.path_info + "%N")
l_body.append ("QUERY_STRING=" + req.query_string + "%N")
l_body.append ("Query parameters:%N")
across
req.query_parameters as q
loop
l_body.append ("%T"+ q.item.name + "=" + q.item.string_representation +"%N")
end
l_body.append ("Form parameters:%N")
across
req.form_parameters as q
loop
l_body.append ("%T"+ q.item.name + "=" + q.item.string_representation +"%N")
end
l_body.append ("Meta variables:%N")
across
req.meta_variables as q
loop
l_body.append ("%T"+ q.item.name + "=" + q.item.string_representation +"%N")
end
res.send (page)
end
end

View File

@@ -2,9 +2,9 @@ class
TEST
inherit
WSF_DEFAULT_SERVICE
WSF_DEFAULT_SERVICE [TEST_EXECUTION]
TEST_SERVICE
TEST_SERVICE [TEST_EXECUTION]
create
make
@@ -22,38 +22,6 @@ feature {NONE} -- Initialization
make_and_launch
end
feature -- Helper
server_log_path: STRING
local
fn: FILE_NAME
once
create fn.make_from_string ("server_test.log")
Result := fn.string
end
server_log (m: STRING_8)
local
f: RAW_FILE
do
create f.make (server_log_path)
f.open_append
f.put_string (m)
f.put_character ('%N')
f.close
end
base_url: detachable STRING
test_url (a_query_url: READABLE_STRING_8): READABLE_STRING_8
local
b: like base_url
do
b := base_url
if b = Void then
b := ""
end
Result := "/" + b + a_query_url
end
end

View File

@@ -0,0 +1,51 @@
note
description: "Summary description for {}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
TEST_EXECUTION
inherit
TEST_EXECUTION_I
create
make
feature -- Helper
server_log_path: STRING
local
fn: FILE_NAME
once
create fn.make_from_string ("server_test.log")
Result := fn.string
end
server_log (m: STRING_8)
local
f: RAW_FILE
do
create f.make (server_log_path)
f.open_append
f.put_string (m)
f.put_character ('%N')
f.close
end
base_url: detachable STRING
test_url (a_query_url: READABLE_STRING_8): READABLE_STRING_8
local
b: like base_url
do
b := base_url
if b = Void then
b := ""
end
Result := "/" + b + a_query_url
end
end

View File

@@ -0,0 +1,195 @@
note
description: "Summary description for {}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
TEST_EXECUTION_I
inherit
WSF_EXECUTION
feature -- Execution
execute
local
req: WSF_REQUEST
res: WSF_RESPONSE
q: detachable STRING_32
n: NATURAL_64
page: WSF_PAGE_RESPONSE
log_res: WSF_LOGGER_RESPONSE_WRAPPER
do
req := request
res := response
debug
server_log (req.request_uri)
if attached req.content_type as l_content_type then
server_log ("content_type:" + l_content_type.string)
end
end
if attached req.http_expect as l_expect and then l_expect.same_string ("100-continue") then
(create {EXECUTION_ENVIRONMENT}).sleep (900_000_000) -- 900 milliseconds
end
create page.make
if attached req.request_uri as l_uri then
if l_uri.starts_with (test_url ("get/01")) then
page.set_status_code (200)
page.header.put_content_type_text_plain
page.put_string ("get-01")
create q.make_empty
across
req.query_parameters as qcur
loop
if not q.is_empty then
q.append_character ('&')
end
q.append (qcur.item.name.as_string_32 + "=" + qcur.item.string_representation)
end
if not q.is_empty then
page.put_string ("(" + q + ")")
end
elseif l_uri.starts_with (test_url ("post/01")) then
page.put_header (200, <<["Content-Type", "text/plain"]>>)
page.put_string ("post-01")
create q.make_empty
across
req.query_parameters as qcur
loop
if not q.is_empty then
q.append_character ('&')
end
q.append (qcur.item.name.as_string_32 + "=" + qcur.item.string_representation)
end
if not q.is_empty then
page.put_string ("(" + q + ")")
end
create q.make_empty
-- req.set_raw_input_data_recorded (True)
across
req.form_parameters as fcur
loop
debug
server_log ("%Tform: " + fcur.item.name)
end
if not q.is_empty then
q.append_character ('&')
end
q.append (fcur.item.name.as_string_32 + "=" + fcur.item.string_representation)
end
-- if attached req.raw_input_data as d then
-- server_log ("Raw data=" + d)
-- end
if not q.is_empty then
page.put_string (" : " + q )
end
elseif l_uri.starts_with (test_url ("post/file/01")) then
page.put_header (200, <<["Content-Type", "text/plain"]>>)
page.put_string ("post-file-01")
n := req.content_length_value
if n > 0 then
req.input.read_string (n.to_integer_32)
q := req.input.last_string
page.put_string ("%N" + q)
end
else
page.put_header (200, <<["Content-Type", "text/plain"]>>)
page.put_string ("Hello")
end
else
page.put_header (200, <<["Content-Type", "text/plain"]>>)
page.put_string ("Bye")
end
if
attached new_file (req, "output.log") as l_out and
attached new_file (req, "error.log") as l_err
then
create log_res.make_from_response (res, l_out, l_err)
log_res.send (page)
l_out.close
l_err.close
else
check False end
res.send (page)
end
end
new_file (req: WSF_REQUEST; a_suffix: STRING): detachable FILE
local
dp, p, fp: FILE_NAME
d: DIRECTORY
i: INTEGER
f: detachable FILE
retried: INTEGER
do
if retried = 0 then
create dp.make_from_string ("logs")
create d.make (dp.string)
if not d.exists then
d.recursive_create_dir
end
if attached req.request_time_stamp as t then
create p.make_from_string (t.out)
else
create p.make_from_string ("")
end
from
i := 0
create fp.make_from_string (dp.string)
if p.is_empty then
fp.set_file_name (p.string + a_suffix)
else
fp.set_file_name (p.string + "-" + a_suffix)
end
create {PLAIN_TEXT_FILE} f.make (fp.string)
until
not f.exists
loop
i := i + 1
create fp.make_from_string (dp.string)
if p.is_empty then
fp.set_file_name (p.string + i.out + "-" + a_suffix)
else
fp.set_file_name (p.string + "_" + i.out + "-" + a_suffix)
end
f.make (fp.string)
end
f.open_write
elseif retried < 5 then
-- Eventually another request created the file at the same time ..
f := new_file (req, a_suffix)
else
f := Void
end
Result := f
rescue
retried := retried + 1
retry
end
feature -- Helper
server_log (s: STRING)
deferred
end
test_url (a_query_url: READABLE_STRING_8): READABLE_STRING_8
deferred
end
end

View File

@@ -5,187 +5,11 @@ note
revision: "$Revision$"
deferred class
TEST_SERVICE
TEST_SERVICE [G -> TEST_EXECUTION_I create make end]
inherit
WSF_SERVICE
feature -- Execution
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
local
q: detachable STRING_32
n: NATURAL_64
page: WSF_PAGE_RESPONSE
log_res: WSF_LOGGER_RESPONSE_WRAPPER
do
debug
server_log (req.request_uri)
if attached req.content_type as l_content_type then
server_log ("content_type:" + l_content_type.string)
end
end
if attached req.http_expect as l_expect and then l_expect.same_string ("100-continue") then
(create {EXECUTION_ENVIRONMENT}).sleep (900_000_000) -- 900 milliseconds
end
create page.make
if attached req.request_uri as l_uri then
if l_uri.starts_with (test_url ("get/01")) then
page.set_status_code (200)
page.header.put_content_type_text_plain
page.put_string ("get-01")
create q.make_empty
across
req.query_parameters as qcur
loop
if not q.is_empty then
q.append_character ('&')
end
q.append (qcur.item.name.as_string_32 + "=" + qcur.item.string_representation)
end
if not q.is_empty then
page.put_string ("(" + q + ")")
end
elseif l_uri.starts_with (test_url ("post/01")) then
page.put_header (200, <<["Content-Type", "text/plain"]>>)
page.put_string ("post-01")
create q.make_empty
across
req.query_parameters as qcur
loop
if not q.is_empty then
q.append_character ('&')
end
q.append (qcur.item.name.as_string_32 + "=" + qcur.item.string_representation)
end
if not q.is_empty then
page.put_string ("(" + q + ")")
end
create q.make_empty
-- req.set_raw_input_data_recorded (True)
across
req.form_parameters as fcur
loop
debug
server_log ("%Tform: " + fcur.item.name)
end
if not q.is_empty then
q.append_character ('&')
end
q.append (fcur.item.name.as_string_32 + "=" + fcur.item.string_representation)
end
-- if attached req.raw_input_data as d then
-- server_log ("Raw data=" + d)
-- end
if not q.is_empty then
page.put_string (" : " + q )
end
elseif l_uri.starts_with (test_url ("post/file/01")) then
page.put_header (200, <<["Content-Type", "text/plain"]>>)
page.put_string ("post-file-01")
n := req.content_length_value
if n > 0 then
req.input.read_string (n.to_integer_32)
q := req.input.last_string
page.put_string ("%N" + q)
end
else
page.put_header (200, <<["Content-Type", "text/plain"]>>)
page.put_string ("Hello")
end
else
page.put_header (200, <<["Content-Type", "text/plain"]>>)
page.put_string ("Bye")
end
if
attached new_file (req, "output.log") as l_out and
attached new_file (req, "error.log") as l_err
then
create log_res.make_from_response (res, l_out, l_err)
log_res.send (page)
l_out.close
l_err.close
else
check False end
res.send (page)
end
end
new_file (req: WSF_REQUEST; a_suffix: STRING): detachable FILE
local
dp, p, fp: FILE_NAME
d: DIRECTORY
i: INTEGER
f: detachable FILE
retried: INTEGER
do
if retried = 0 then
create dp.make_from_string ("logs")
create d.make (dp.string)
if not d.exists then
d.recursive_create_dir
end
if attached req.request_time_stamp as t then
create p.make_from_string (t.out)
else
create p.make_from_string ("")
end
from
i := 0
create fp.make_from_string (dp.string)
if p.is_empty then
fp.set_file_name (p.string + a_suffix)
else
fp.set_file_name (p.string + "-" + a_suffix)
end
create {PLAIN_TEXT_FILE} f.make (fp.string)
until
not f.exists
loop
i := i + 1
create fp.make_from_string (dp.string)
if p.is_empty then
fp.set_file_name (p.string + i.out + "-" + a_suffix)
else
fp.set_file_name (p.string + "_" + i.out + "-" + a_suffix)
end
f.make (fp.string)
end
f.open_write
elseif retried < 5 then
-- Eventually another request created the file at the same time ..
f := new_file (req, a_suffix)
else
f := Void
end
Result := f
rescue
retried := retried + 1
retry
end
feature -- Helper
server_log (s: STRING)
deferred
end
test_url (a_query_url: READABLE_STRING_8): READABLE_STRING_8
deferred
end
end

View File

@@ -17,14 +17,9 @@ inherit
on_clean
end
TEST_SERVICE
undefine
default_create
end
feature {NONE} -- Events
web_app: detachable NINO_SERVICE
web_app: detachable NINO_SERVICE [TEST_EXECUTION]
port_number: INTEGER
base_url: detachable STRING
@@ -32,7 +27,7 @@ feature {NONE} -- Events
on_prepare
-- <Precursor>
local
app: NINO_SERVICE
app: NINO_SERVICE [TEST_EXECUTION]
wt: WORKER_THREAD
e: EXECUTION_ENVIRONMENT
do
@@ -43,7 +38,7 @@ feature {NONE} -- Events
port_number := 0
base_url := "/test/"
create app.make_custom (to_wgi_service, base_url)
create app.make_custom (base_url)
web_app := app
create wt.make (agent app.listen (port_number))

View File

@@ -7,15 +7,13 @@ class
TEST_WSF_RESPONSE_TEST_SUITE
inherit
WSF_TO_WGI_SERVICE
rename
default_create as df_wgi,
execute as execute_wgi
end
EQA_TEST_SET
redefine
on_prepare
select
end
WGI_EXPORTER
undefine
default_create
end
@@ -23,7 +21,6 @@ feature {NONE} -- Events
on_prepare
do
make_from_service (create {WSF_SERVICE_NULL})
end
feature -- Test Cases
@@ -96,7 +93,7 @@ feature -- Test Cases
end
test_add_multiple_cookie_with_similar_cookie_name_2
test_add_multiple_cookie_with_similar_cookie_name_2
local
w_res: WSF_RESPONSE
l_cookie: WSF_COOKIE

View File

@@ -1,26 +0,0 @@
note
description: "[
Mock implementation of the WGI_SERVICE interface.
Used for testing the ewf core and also web applications
]"
date: "$Date$"
revision: "$Revision$"
class
WSF_SERVICE_NULL
inherit
WSF_SERVICE
feature -- Execute
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute the request
-- See `req.input' for input stream
-- `req.meta_variables' for the CGI meta variable
-- and `res' for output buffer
do
end
end