Skip to content

Commit 9424b1e

Browse files
committed
Merge branch 'master' into v1
2 parents 64463df + 61f90bb commit 9424b1e

File tree

73 files changed

+5913
-82
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+5913
-82
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package nino
2+
3+
project
4+
nino = "nino-safe.ecf"
5+
nino = "nino.ecf"
6+
7+
note
8+
title: Eiffel Nino Web Server
9+
description: Simple HTTPd server written in Eiffel
10+
tags: web, httpd, server
11+
license: Eiffel Forum v2
12+
copyright: Javier Velilla, Jocelyn Fiat.
13+
14+
end

doc/workbook/SERVICE_TEMPLATE.png

13.1 KB
Loading

doc/workbook/basics/basics.md

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
Nav: [Workbook](../workbook.md) | [Handling Requests: Form/Query Parameter](/workbook/handling_request/form.md)
2+
3+
4+
## EWF basic service
5+
6+
##### Table of Contents
7+
- [Basic Structure](#structure)
8+
- [Service to Generate Plain Text](#text)
9+
- [Source code](#source_1)
10+
- [Service to Generate HTML](#html)
11+
- [Source code](#source_2)
12+
13+
14+
<a name="structure"/>
15+
## EWF service structure
16+
17+
The following code describes the basic structure of an EWF basic service that handles HTTP requests.
18+
19+
```eiffel
20+
class
21+
SERVICE_TEMPLATE
22+
23+
inherit
24+
WSF_DEFAULT_SERVICE -- Todo explain this, and the concept of launchers and connectors ()
25+
26+
create
27+
make_and_launch
28+
29+
feature -- Basic operations
30+
31+
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
32+
do
33+
-- To read incoming HTTP request, we need to use `req'
34+
35+
-- May require talking to databases or other services.
36+
37+
-- To send a response we need to setup, the status code and
38+
-- the response headers and the content we want to send out our client
39+
end
40+
end
41+
```
42+
43+
When using the "nino" connector, by default the service listens on port 80, but often this port is already used by other applications, so it is recommended to use another port.
44+
To define another port, redefine the feature `initialize' and set up a new port number using the service options (see below).
45+
46+
```eiffel
47+
class
48+
SERVICE_TEMPLATE
49+
inherit
50+
WSF_DEFAULT_SERVICE
51+
redefine
52+
initialize
53+
end
54+
55+
create
56+
make_and_launch
57+
58+
feature {NONE} -- Initialization
59+
60+
initialize
61+
-- Initialize current service.
62+
-- on port 9090
63+
do
64+
set_service_option ("port", 9090)
65+
end
66+
67+
feature -- Basic operations
68+
69+
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
70+
-- Execute the incoming request.
71+
do
72+
-- To read incoming HTTP requires, we need to use `req'
73+
74+
-- May require talking to databases or other services.
75+
76+
-- To send a response we need to setup, the status code and
77+
-- the response headers and the content we want to send out client
78+
end
79+
end
80+
```
81+
82+
The **WSF_REQUEST** gives access to the incoming data; the class provides features to get information such as request method, form data, query parameters, uploaded files, HTTP request headers, and hostname of the client among others.
83+
The **WSF_RESPONSE** provides features to define the response with information such as HTTP status codes (10x,20x, 30x, 40x, and 50x), response headers (Content-Type, Content-Length, etc.) and obviously the body of the message itself.
84+
85+
**SERVICE_TEMPLATE** is the root class of our example, it launches the application, using the corresponding connector, Which connector? this depends how you want to run it cgi, fcgi or nino. For development is recommended to use Nino, a standalone web server written in Eiffel, and run the execution within the EiffelStudio debugger. For production fcgi (or cgi) using Apache or another popular web server.
86+
87+
The **SERVICE_TEMPLATE** class inherits from _WSF_DEFAULT_SERVICE_ class, and this one also inherits from other interfaces. Let’s describe them in a few words.
88+
89+
![Service Template Hierarchy](/workbook/SERVICE_TEMPLATE.png "Service Template")
90+
91+
**WS_LAUNCHABLE_SERVICE** inherit from **WS_SERVICE** class, which is the low level entry point in EWF, handling each incoming request with a single procedure ```execute (req: WSF_REQUEST; res: WSF_RESPONSE) ...```. And also provides a way to launch our application using different kind of connectors. Below a [BON diagram] (http://www.bon-method.com/index_normal.htm) showing the different kind of connectors.
92+
93+
![Launcher Hierarchy](/app/doc/WSF_SERVICE_LAUNCHER.png "Launcher")
94+
95+
A basic EWF service inherits from **WSF_DEFAULT_SERVICE** (for other options see [?]).
96+
And then you only need to implement the **execute** feature, get data from the request *req* and write the response in *res*.
97+
98+
<a name="text"/>
99+
## A simple Service to Generate Plain Text.
100+
101+
Before to continue, it is recommended to review the getting started guided.
102+
103+
```eiffel
104+
class
105+
APPLICATION
106+
107+
inherit
108+
WSF_DEFAULT_SERVICE
109+
redefine
110+
initialize
111+
end
112+
113+
create
114+
make_and_launch
115+
116+
feature {NONE} -- Initialization
117+
118+
initialize
119+
-- Initialize current service.
120+
do
121+
set_service_option ("port", 9090)
122+
end
123+
124+
feature -- Basic operations
125+
126+
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
127+
-- Execute the incomming request
128+
do
129+
-- To send a response we need to setup, the status code and
130+
-- the response headers.
131+
res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/plain"], ["Content-Length", "11"]>>)
132+
res.put_string ("Hello World")
133+
end
134+
135+
end
136+
```
137+
<a name="source_1"></a>
138+
##### Source code
139+
The source code is available on Github. You can get it by running the command:
140+
141+
```git clone https://github.com/EiffelWebFramework/ewf_examples.git```
142+
143+
The example of simple service that generate plain text response is located in the directory $PATH/ewf_examples/workbook/basics/simple, where $PATH is where you run ```git clone``` . Just double click on the simple.ecf file and select the simple_nino target or if you prefer the command line, run the command:
144+
145+
```estudio -config simple.ecf -target simple_nino```
146+
147+
<a name="html"></a>
148+
## A Service to Generate HTML.
149+
To generate HTML, it's needed
150+
151+
1. Change the Content-Type : "text/html"
152+
2. Build an HTML page
153+
154+
```eiffel
155+
class
156+
APPLICATION
157+
158+
inherit
159+
WSF_DEFAULT_SERVICE
160+
redefine
161+
initialize
162+
end
163+
164+
create
165+
make_and_launch
166+
167+
feature {NONE} -- Initialization
168+
169+
initialize
170+
-- Initialize current service.
171+
do
172+
set_service_option ("port", 9090)
173+
end
174+
175+
feature -- Basic operations
176+
177+
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
178+
-- Execute the incomming request
179+
do
180+
-- To send a response we need to setup, the status code and
181+
-- the response headers.
182+
res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html"], ["Content-Length", web_page.count.out]>>)
183+
res.put_string (web_page)
184+
end
185+
186+
187+
web_page: STRING = "[
188+
<!DOCTYPE html>
189+
<html>
190+
<head>
191+
<title>Resume</title>
192+
</head>
193+
<body>
194+
Hello World
195+
</body>
196+
</html>
197+
]"
198+
199+
end
200+
```
201+
##### Source code
202+
The source code is available on Github. You can get it by running the command:
203+
204+
```git clone https://github.com/EiffelWebFramework/ewf_examples.git```
205+
206+
The example of the service that generates HTML is located in the directory $PATH/ewf_examples/workbook/basics/simple_html, where $PATH is where you run ```git clone``` . Just double click on the simple_html.ecf file and select the simple_html_nino target or if you prefer the command line, run the command:
207+
208+
```estudio -config simple_html.ecf -target simple_html_nino```
209+
210+
Nav: [Workbook](../workbook.md) | [Handling Requests: Form/Query Parameter](/workbook/handling_request/form.md)
211+

doc/workbook/basics/reading_request_data.md

Whitespace-only changes.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
note
2+
description : "Basic Service that Generates Plain Text"
3+
date : "$Date$"
4+
revision : "$Revision$"
5+
6+
class
7+
APPLICATION
8+
9+
inherit
10+
WSF_DEFAULT_SERVICE
11+
redefine
12+
initialize
13+
end
14+
15+
create
16+
make_and_launch
17+
18+
feature {NONE} -- Initialization
19+
20+
initialize
21+
-- Initialize current service.
22+
do
23+
set_service_option ("port", 9090)
24+
end
25+
26+
feature -- Basic operations
27+
28+
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
29+
-- Execute the incomming request
30+
do
31+
-- To send a response we need to setup, the status code and
32+
-- the response headers.
33+
res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/plain"], ["Content-Length", "11"]>>)
34+
res.put_string ("Hello World")
35+
end
36+
37+
end
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="ISO-8859-1"?>
2+
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="simple" uuid="C28C4F53-9963-46C0-A080-8F13E94E7486" library_target="simple">
3+
<target name="common" abstract="true">
4+
<file_rule>
5+
<exclude>/EIFGENs$</exclude>
6+
<exclude>/CVS$</exclude>
7+
<exclude>/.svn$</exclude>
8+
</file_rule>
9+
<option warning="true" full_class_checking="false" is_attached_by_default="true" void_safety="transitional" syntax="transitional">
10+
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
11+
</option>
12+
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
13+
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
14+
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf-safe.ecf"/>
15+
</target>
16+
<target name="simple_nino" extends="common">
17+
<root class="APPLICATION" feature="make_and_launch"/>
18+
<option warning="true" is_attached_by_default="true" void_safety="transitional" syntax="transitional">
19+
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
20+
</option>
21+
<library name="default_nino" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\nino-safe.ecf"/>
22+
<cluster name="simple" location=".\" recursive="true"/>
23+
</target>
24+
<target name="simple_cgi" extends="common">
25+
<root class="APPLICATION" feature="make_and_launch"/>
26+
<option warning="true" is_attached_by_default="true" void_safety="transitional" syntax="transitional">
27+
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
28+
</option>
29+
<library name="default_cgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\cgi-safe.ecf"/>
30+
<cluster name="simple" location=".\" recursive="true"/>
31+
</target>
32+
<target name="simple_libfcgi" extends="common">
33+
<root class="APPLICATION" feature="make_and_launch"/>
34+
<option warning="true" is_attached_by_default="true" void_safety="transitional" syntax="transitional">
35+
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
36+
</option>
37+
<library name="default_libfcgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\libfcgi-safe.ecf"/>
38+
<cluster name="simple" location=".\" recursive="true"/>
39+
</target>
40+
<target name="simple" extends="simple_nino">
41+
</target>
42+
</system>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
##Run simple_html example on Apache with FCGI on Windows.
2+
3+
4+
5+
####Prerequisites
6+
7+
* This tutorial was written for people working under Windows environment, and using Apache Server with FCGI connector
8+
* Compile the ewf application from command line.
9+
* Assuming you have installed Apache Server under C:/home/server/Apache24.
10+
* Assuming you have placed your current project under C:/home/server/Apache24/fcgi-bin.
11+
* Assuming you have setted the Listen to 8888, the defautl value is 80 .
12+
13+
14+
15+
####FCGI module
16+
If you don't have the FCGI module installed, you can get it from https://www.apachelounge.com/download/, download the module based on your platform [modules-2.4-win64-VC11.zip](https://www.apachelounge.com/download/VC11/modules/modules-2.4-win64-VC11.zip) or [modules-2.4-win32-VC11.zip](https://www.apachelounge.com/download/VC11/modules/modules-2.4-win32-VC11.zip), uncompress it
17+
and copy the _mod_fcgid.so_ to C:/home/server/Apache24/modules
18+
19+
####Compile the project simple_html using the fcgi connector.
20+
21+
ec -config simple_html.ecf -target simple_html_fcgi -finalize -c_compile -project_path .
22+
23+
Copy the genereted exe to C:/home/server/Apache24/fcgi-bin folder.
24+
25+
Check if you have _libfcgi.dll_ in your PATH.
26+
27+
28+
####Apache configuration
29+
Add to httpd.conf the content, you can get the configuration file [here](config.conf)
30+
31+
```
32+
LoadModule fcgid_module modules/mod_fcgid.so
33+
34+
<IfModule mod_fcgid.c>
35+
<Directory "C:/home/server/Apache24/fcgi-bin">
36+
SetHandler fcgid-script
37+
Options +ExecCGI +Includes +FollowSymLinks -Indexes
38+
AllowOverride All
39+
Require all granted
40+
</Directory>
41+
ScriptAlias /simple "C:/home/server/Apache24/fcgi-bin/simple_html.exe"
42+
</IfModule>
43+
```
44+
45+
Test if your httpd.conf is ok
46+
>httpd -t
47+
48+
Luanch the server
49+
>httpd
50+
51+
Check the application
52+
>http://localhost:8888/simple
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
LoadModule fcgid_module modules/mod_fcgid.so
2+
3+
<IfModule mod_fcgid.c>
4+
<Directory "C:/home/server/Apache24/fcgi-bin">
5+
SetHandler fcgid-script
6+
Options +ExecCGI +Includes +FollowSymLinks -Indexes
7+
AllowOverride All
8+
Require all granted
9+
</Directory>
10+
ScriptAlias /simple "C:/home/server/Apache24/fcgi-bin/simple_html.exe"
11+
</IfModule>
12+

0 commit comments

Comments
 (0)