HTTP Server Example

To give an example of how a workflow acting as a HTTP server may be designed, suppose there is an HTML login page requiring login name and password. The login parameters are checked against a user database, opening a new HTML page if authentication succeeded. If not, a new login attempt is requested.



The login page and the resulting message page, in case of failed authentication

An example of how such a workflow may be designed is shown below. Each of the Analysis agents will perform a validation, resulting in either the HTTP UDR being sent back with an updated response field to the collector, or it is sent unchanged to a subsequent agent.

  1. The HTTPD agent sends a request to the Query agent which checks that the correct page is requested. If the page does not exist, an error message is sent back to the HTTPD agent on the not_found route.

  2. If the page exists, the HTTP UDR is routed on to the Welcome or Login agents, depending on if the login page was addressed.

  3. The Login agent checks if the user exists in the database. If authentication fails, the HTTP UDR is routed to the Failure agent which displays a new page stating the username/password is incorrect.

  4. If authentication succeeds, a new page is opened.



A workflow acting as an HTTP Server



Note!

The data sent to the HTTP agent in the example (the content field) is an HTML page. Since UFDL cannot handle the HTML protocol, the field is defined as a string. If, for instance, XML was used instead (which may be handled with UFDL), this would require an Analysis agent, which turned the field into a bytearray and then decoded it (use the APL functions strToBA and udrDecode).



The Format Definition

Create an instance of the built-in HTTP format definition. Additional fields may be entered. This is useful mainly for transport of variable values to subsequent agents. In this case, re-usage of the username as parsed from the login page is desired.

internal MYHTTPD: extends_class ("com.digitalroute.wfc.http.HttpdUDR") { string username; };


The Analysis Agents

The Analysis agents handle all validation and response handling.

Query

The query agent checks if the addressed page exists. If it does not, an error message is inserted into the response field and the UDR is returned to the collector.

consume { if (input.query == "/") { // Show welcome page. udrRoute(input, "index"); return; } if (input.query == "/login") { // Try to log in. udrRoute(input, "form"); return; } // The request is not found here. input.response = "HTTP ERROR: 404, Not Found"; input.responseStatusCode = "404 Not Found"; input.responseType = "text/plain"; udrRoute(input, "not_found"); }

Welcome

Populates the response field with an HTML page, and send the UDR back to the collector.

final string welcome = "<html > <title >Welcome</title > <body bgcolor=#3b7d73 > <font face=Verdana,Arial > <h2 >HTTPD Doc Example</h2 > Login<p ><form action=/login method=post > <table ><tr ><td align=right > Username</td ><td ><input name=username ></td ></tr > <tr ><td align=right >Password</td > <td ><input name=passwd type=password ></td ></tr > <tr ><td >&nbsp;</td > <td ><input name=Login type=submit ></td ></tr> </table></form ></body ></html >"; consume { input.responseType="text/html"; input.response = welcome; udrRoute(input); }

Login

Verifies that the user is authenticated, by performing a lookup against a database table.

Success

The response field is populated with an HTML page.

Failure

The response field is populated with an HTML page.