Make a simple hello world based on nino
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
note
|
||||
description: "Summary description for {GW_NINO_APPLICATION}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GW_NINO_APPLICATION
|
||||
|
||||
create
|
||||
make,
|
||||
make_custom
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
make (a_callback: like {GW_AGENT_APPLICATION}.callback)
|
||||
-- Initialize `Current'.
|
||||
do
|
||||
make_custom (a_callback, Void)
|
||||
end
|
||||
|
||||
make_custom (a_callback: like {GW_AGENT_APPLICATION}.callback; a_base_url: detachable STRING)
|
||||
-- Initialize `Current'.
|
||||
local
|
||||
app: GW_AGENT_APPLICATION
|
||||
do
|
||||
create app.make (a_callback)
|
||||
create connector.make_with_base (app, a_base_url)
|
||||
end
|
||||
|
||||
connector: GW_NINO_CONNECTOR
|
||||
-- Web server connector
|
||||
|
||||
feature -- Status settings
|
||||
|
||||
configuration: HTTP_SERVER_CONFIGURATION
|
||||
do
|
||||
Result := connector.configuration
|
||||
end
|
||||
|
||||
force_single_threaded
|
||||
-- Force single threaded behavior
|
||||
do
|
||||
configuration.force_single_threaded := True
|
||||
end
|
||||
|
||||
feature -- Server
|
||||
|
||||
listen (a_port: INTEGER)
|
||||
do
|
||||
configuration.http_server_port := a_port
|
||||
connector.launch
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
5949 Hollister Ave., Goleta, CA 93117 USA
|
||||
Telephone 805-685-1006, Fax 805-685-6869
|
||||
Website http://www.eiffel.com
|
||||
Customer support http://support.eiffel.com
|
||||
]"
|
||||
end
|
||||
@@ -9,11 +9,10 @@
|
||||
</file_rule>
|
||||
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="provisional">
|
||||
</option>
|
||||
<setting name="concurrency" value="thread"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="ewsgi" location="..\..\ewsgi-safe.ecf" readonly="false"/>
|
||||
<library name="connector_cgi" location="..\..\connectors\cgi\cgi-safe.ecf" readonly="false"/>
|
||||
<library name="connector_nino" location="..\..\connectors\nino\nino-safe.ecf" readonly="false"/>
|
||||
<library name="connector_libfcgi" location="..\..\connectors\libfcgi\libfcgi-safe.ecf" readonly="false"/>
|
||||
<library name="ewsgi" location="..\..\ewsgi-safe.ecf" readonly="false"/>
|
||||
<cluster name="src" location="src\" recursive="true"/>
|
||||
</target>
|
||||
</system>
|
||||
|
||||
@@ -7,54 +7,24 @@ note
|
||||
class
|
||||
HELLO_WORLD
|
||||
|
||||
inherit
|
||||
GW_APPLICATION_IMP
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- Initialize `Current'.
|
||||
local
|
||||
conn: detachable GW_CONNECTOR
|
||||
nino_conn: GW_NINO_CONNECTOR
|
||||
do
|
||||
if is_nino then
|
||||
create nino_conn.make_with_base (Current, "/hello_world")
|
||||
if attached nino_conn.server.server_configuration as cfg then
|
||||
cfg.http_server_port := 8080
|
||||
cfg.force_single_threaded := True
|
||||
end
|
||||
conn := nino_conn
|
||||
elseif is_cgi then
|
||||
create {GW_CGI_CONNECTOR} conn.make (Current)
|
||||
elseif is_libfcgi then
|
||||
create {GW_LIBFCGI_CONNECTOR} conn.make (Current)
|
||||
else
|
||||
io.error.put_string ("Unsupported connector")
|
||||
end
|
||||
if conn /= Void then
|
||||
conn.launch
|
||||
end
|
||||
end
|
||||
|
||||
is_nino: BOOLEAN = True
|
||||
is_cgi: BOOLEAN = False
|
||||
is_libfcgi: BOOLEAN = False
|
||||
|
||||
feature -- Execution
|
||||
|
||||
execute (ctx: GW_REQUEST_CONTEXT)
|
||||
-- Execute the request
|
||||
print ("Example: start a Nino web server on port " + port_number.out + ", %Nand reply Hello World for any request such as http://localhost:8123/%N")
|
||||
(create {GW_NINO_APPLICATION}.make (agent (ctx: GW_REQUEST_CONTEXT)
|
||||
do
|
||||
ctx.output.put_header (200, <<["Content-Type", "text/plain"]>>)
|
||||
ctx.output.put_string ("Hello World!%N")
|
||||
if attached ctx.execution_variable ("REQUEST_COUNT") as rq_count then
|
||||
ctx.output.put_string ("Request #" + rq_count + "%N")
|
||||
end
|
||||
)).listen (port_number)
|
||||
end
|
||||
|
||||
port_number: INTEGER = 8123
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
note
|
||||
description: "Summary description for {GW_AGENT_APPLICATION}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GW_AGENT_APPLICATION
|
||||
|
||||
inherit
|
||||
GW_APPLICATION_IMP
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
make (a_callback: like callback)
|
||||
-- Initialize `Current'.
|
||||
do
|
||||
callback := a_callback
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
callback: PROCEDURE [ANY, TUPLE [like new_request_context]]
|
||||
-- Procedure called on `execute'
|
||||
|
||||
execute (ctx: like new_request_context)
|
||||
-- Execute the request
|
||||
do
|
||||
callback.call ([ctx])
|
||||
end
|
||||
|
||||
invariant
|
||||
callback_attached: callback /= Void
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
5949 Hollister Ave., Goleta, CA 93117 USA
|
||||
Telephone 805-685-1006, Fax 805-685-6869
|
||||
Website http://www.eiffel.com
|
||||
Customer support http://support.eiffel.com
|
||||
]"
|
||||
end
|
||||
Reference in New Issue
Block a user