Versions Compared

Key

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

...



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("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.

...