Migrated most of the example and library to new design.
This commit is contained in:
@@ -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
|
||||
|
||||
51
library/server/wsf/tests/server/test_execution.e
Normal file
51
library/server/wsf/tests/server/test_execution.e
Normal 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
|
||||
|
||||
195
library/server/wsf/tests/server/test_execution_i.e
Normal file
195
library/server/wsf/tests/server/test_execution_i.e
Normal 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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user