Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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.


Image Added

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.


Image Added

A workflow acting as an HTTP Server


Note
titleNote!

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.

Code Block
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.

Code Block
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.

Code Block
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.

Code Block
table tmp_tab;

initialize {
  tmp_tab = tableCreate("Default.DatabaseProfile","select user_Name, user_PW from users");
}

consume
{
  if (input.requestMethod != "POST") {
    input.response = "Wrong method.";
    udrRoute(input, "no");
    return;
  }

  // Find username.

  string p = input.content;

int i = strIndexOf(p, "username=");
  p = strSubstring(p, i + 9, strLength(p));
  i = strIndexOf(p, "&");
  string u = strSubstring(p, 0, i);
  p = strSubstring(p, i + 1, strLength(p));
  i = strIndexOf(p, "passwd=");
  p = strSubstring(p, i + 7, strLength(p));
  i = strIndexOf(p, "&");
  p = strSubstring(p, 0, i);

  // Verify the login.

  table rowFound_u = tableLookup(tmp_tab, "user_Name", "=", u);
  int hit_u = tableRowCount(rowFound_u);

 if (hit_u == 1) {
      if (p == (string)tableGet(rowFound_u,0,1)) {
          input.username = (string)tableGet(rowFound_u,0,0);
          udrRoute( input, "yes" );
      } else {
          input.response = "Wrong password.";
          udrRoute(input, "no");
      } 
  } else {
      input.response = "Wrong username.";
      udrRoute(input, "no");;
  } 
} 

Success

The response field is populated with an HTML page.

Code Block
final string success1 = " <html > <title >Welcome </title >
		    <body bgcolor=#3b7d73 > <font face=Verdana,Arial >
		    <h2 >HTTPD Doc Example </h2 >Welcome ";

final string success2 = "! <p > <a href=/ >Back to start page </a > 
		    </body > </html >";

consume
{
  input.responseType = "text/html";
  input.response = success1 + input.username + success2;
  udrRoute(input);
} 

Failure

The response field is populated with an HTML page.

Code Block
final string failure1 = "<html><title>Welcome</title>
		    <body bgcolor=#3b7d73><font face=Verdana,Arial>
		    <h2>HTTPD Doc Example</h2>Failed to log in; ";

final string failure2 = "<p><a href=/>Back to start page</a>
		    </body></html>";

consume
{
    input.responseType = "text/html";
    input.response = failure1 + input.response + failure2;        
    udrRoute(input);
}	


Scroll pagebreak