Updated code to remove obsolete call on recent version of json library.

Updated upload_image example to use PATH instead of DIRECTORY_NAME or similar.
Removed unused local variables.
This commit is contained in:
2015-04-07 19:27:30 +02:00
parent b7a12eddaf
commit 881625a0f6
25 changed files with 131 additions and 112 deletions

View File

@@ -133,8 +133,9 @@ feature {NONE} -- Initialization
-- Show the Response body
if attached Result.body as m then
create j.make_parser (m)
if j.is_parsed and attached j.parse_object as j_o then
create j.make_with_string (m)
j.parse_content
if j.is_valid and then attached j.parsed_json_object as j_o then
if attached {JSON_STRING} j_o.item ("id") as l_id then
id := l_id.item
end

View File

@@ -97,7 +97,7 @@ feature -- Conversion
Result.put (json.value (o.location), location_key)
Result.put (json.value (o.status), status_key)
from
create ja.make_array
create ja.make_empty
o.items.start
until
o.items.after
@@ -117,48 +117,48 @@ feature -- Conversion
feature {NONE} -- Implementation
id_key: JSON_STRING
once
create Result.make_json ("id")
create Result.make_from_string ("id")
end
location_key: JSON_STRING
once
create Result.make_json ("location")
create Result.make_from_string ("location")
end
status_key: JSON_STRING
once
create Result.make_json ("status")
create Result.make_from_string ("status")
end
items_key : JSON_STRING
once
create Result.make_json ("items")
create Result.make_from_string ("items")
end
name_key : JSON_STRING
once
create Result.make_json ("name")
create Result.make_from_string ("name")
end
size_key : JSON_STRING
once
create Result.make_json ("size")
create Result.make_from_string ("size")
end
quantity_key : JSON_STRING
once
create Result.make_json ("quantity")
create Result.make_from_string ("quantity")
end
option_key : JSON_STRING
once
create Result.make_json ("option")
create Result.make_from_string ("option")
end
feature -- Validation
@@ -171,6 +171,6 @@ feature -- Validation
end
note
copyright: "2011-2012, Javier Velilla and others"
copyright: "2011-2015, Javier Velilla and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -559,8 +559,9 @@ feature {NONE} -- Implementation Repository Layer
do
create joc.make
json.add_converter(joc)
create parser.make_parser (l_post)
if attached parser.parse as jv and parser.is_parsed then
create parser.make_with_string (l_post)
parser.parse_content
if parser.is_valid and then attached parser.parsed_json_value as jv then
if attached {like extract_order_request} json.object (jv, "ORDER") as res then
Result := res
end
@@ -568,6 +569,6 @@ feature {NONE} -- Implementation Repository Layer
end
note
copyright: "2011-2014, Javier Velilla and others"
copyright: "2011-2015, Javier Velilla and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -385,8 +385,12 @@ feature {NONE} -- Implementation Repository Layer
do
create joc.make
json.add_converter(joc)
create parser.make_parser (l_post)
if attached parser.parse as jv and parser.is_parsed then
create parser.make_with_string (l_post)
parser.parse_content
if
parser.is_valid and then
attached parser.parsed_json_value as jv
then
if attached {like extract_order_request} json.object (jv, "ORDER") as res then
Result := res
end
@@ -394,6 +398,6 @@ feature {NONE} -- Implementation Repository Layer
end
note
copyright: "2011-2013, Javier Velilla and others"
copyright: "2011-2015, Javier Velilla and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -21,6 +21,8 @@ inherit
WSF_DEFAULT_SERVICE
SHARED_EXECUTION_ENVIRONMENT
create
make
@@ -46,7 +48,7 @@ feature {NONE} -- Initialization
map_uri_template_agent_with_request_methods ("/upload/{name}{?nb}", agent execute_upload_put, router.methods_put)
map_uri_template_agent ("/upload{?nb}", agent execute_upload)
create www.make (document_root)
create www.make_with_path (document_root)
www.set_directory_index (<<"index.html">>)
www.set_not_found_handler (agent execute_not_found)
router.handle_with_request_methods ("", www, router.methods_GET)
@@ -54,31 +56,18 @@ feature {NONE} -- Initialization
feature -- Configuration
document_root: READABLE_STRING_8
document_root: PATH
-- Document root to look for files or directories
local
e: EXECUTION_ENVIRONMENT
dn: DIRECTORY_NAME
once
create e
create dn.make_from_string (e.current_working_directory)
dn.extend ("htdocs")
Result := dn.string
if Result [Result.count] = Operating_environment.directory_separator then
Result := Result.substring (1, Result.count - 1)
end
Result := execution_environment.current_working_path.extended ("htdocs")
ensure
not Result.ends_with (Operating_environment.directory_separator.out)
not Result.name.ends_with (Operating_environment.directory_separator.out)
end
files_root: READABLE_STRING_8
files_root: PATH
-- Uploaded files will be stored in `files_root' folder
local
dn: DIRECTORY_NAME
once
create dn.make_from_string (document_root)
dn.extend ("files")
Result := dn.string
Result := document_root.extended ("files")
end
feature -- Execution
@@ -114,8 +103,7 @@ feature -- Execution
n := 1
end
if attached {WSF_STRING} req.query_parameter ("demo") as p_demo then
create fn.make_from_string (document_root)
fn := fn.extended (p_demo.value)
fn := document_root.extended (p_demo.value)
l_body.append ("File: <input type=%"file%" name=%"uploaded_file[]%" size=%"60%" value=%""+ html_encode (fn.name) +"%"></br>%N")
end
@@ -139,9 +127,8 @@ feature -- Execution
n := n + 1
l_body.append ("<li>")
l_body.append ("<div>" + c.item.name + "=" + html_encode (c.item.filename) + " size=" + c.item.size.out + " type=" + c.item.content_type + "</div>")
create fn.make_from_string (files_root)
l_safe_filename := c.item.safe_filename
fn := fn.extended (l_safe_filename)
fn := files_root.extended (l_safe_filename)
if c.item.move_to (fn.name) then
if c.item.content_type.starts_with ("image") then
l_body.append ("%N<a href=%"../files/" + url_encode (l_safe_filename) + "%"><img src=%"../files/"+ l_safe_filename +"%" /></a>")
@@ -187,8 +174,7 @@ feature -- Execution
if attached new_temporary_output_file ("tmp-uploaded-file_" + n.out) as f then
req.read_input_data_into_file (f)
f.close
create fn.make_from_string (files_root)
fn := fn.extended (l_safe_filename)
fn := files_root.extended (l_safe_filename)
f.rename_file (fn.name)
l_body.append ("<li>")
l_body.append ("<div>Input data : size=" + f.count.out + " (" + req.content_length_value.out + ")</div>")