« - »

The Approval Service: POJOs and repackaging

10 February 2008

I have repackaged the components so that there is a single .ear file now: Example.ear. Currently, this file contains four .war files and two .jar files:

The RFA sample data is available from the ApprovalWeb.war via the following URIs:

The WhoAmI servlet is available from the IdentityWeb.war, but the example page that uses the WhoAmI servlet has been moved to the ExampleWeb.war, where we will be placing all of the example pages that use the services developed:

All of the common scripts and css I moved to the CoreWeb.war, where it can be made available to all applications. I also added a common error routine to our ajaxcall.js script to complete that element:

// ajaxcall.js

/**
 * This function processes the Ajax URL to GET data
 */
function ajaxGet(url, responseFunction, errorFunction) {
  var httpRequest = getNewHttpRequestObject(url);

  httpRequest.onreadystatechange = function() {
    if (httpRequest.readyState == 4) {
      try {
        if (httpRequest.status == 200) {
          eval(responseFunction + '(httpRequest.responseXML)');
        } else {
          eval(errorFunction + '(httpRequest)');
        }
      } catch (e) {
        if (window.XMLHttpRequest) {
          alert('There has been an error processing this request for URL '
               + httpRequest.originalURL + ':\n' + e);
        } else {
          alert('There has been an error processing this request:\n' + e);
        }
      }
    }
  }

  //Request the XML document
  httpRequest.open('GET', url, true);
  httpRequest.send('');
}

/**
 * This function processes the Ajax URL to PUT data
 */
function ajaxPut(url, data, responseFunction, errorFunction) {
  var httpRequest = getNewHttpRequestObject(url);

  httpRequest.onreadystatechange = function() {
    if (httpRequest.readyState == 4) {
      try {
        if (httpRequest.status == 200) {
          eval(responseFunction + '(httpRequest.responseXML)');
        } else {
          eval(errorFunction + '(httpRequest)');
        }
      } catch (e) {
        if (window.XMLHttpRequest) {
          alert('There has been an error processing this request for URL '
               + httpRequest.originalURL + ':\n' + e);
        } else {
          alert('There has been an error processing this request:\n' + e);
        }
      }
    }
  }

  httpRequest.open('PUT', url, true);
  httpRequest.setRequestHeader("Content-type", "text/xml");
  httpRequest.setRequestHeader("Content-length", data.length);
  httpRequest.send(data);
}

/**
 * This function processes the Ajax URL to POST data
 */
function ajaxPost(url, parameters, responseFunction, errorFunction) {
  var httpRequest = getNewHttpRequestObject(url);

  httpRequest.onreadystatechange = function() {
    if (httpRequest.readyState == 4) {
      try {
        if (httpRequest.status == 200) {
          eval(responseFunction + '(httpRequest.responseXML)');
        } else {
          eval(errorFunction + '(httpRequest)');
        }
      } catch (e) {
        if (window.XMLHttpRequest) {
          alert('There has been an error processing this request for URL '
               + httpRequest.originalURL + ':\n' + e);
        } else {
          alert('There has been an error processing this request:\n' + e);
        }
      }
    }
  }

    httpRequest.open('POST', url, true);
    httpRequest.setRequestHeader("Content-type",
                 "application/x-www-form-urlencoded");
    httpRequest.setRequestHeader("Content-length", parameters.length);
    httpRequest.send(parameters);
}

/**
 * This function processes the Ajax URL to DELETE data
 */
function ajaxDelete(url, responseFunction, errorFunction) {
  var httpRequest = getNewHttpRequestObject(url);

  httpRequest.onreadystatechange = function() {
    if (httpRequest.readyState == 4) {
      try {
        if (httpRequest.status == 200) {
          eval(responseFunction + '(httpRequest.responseXML)');
        } else {
          eval(errorFunction + '(httpRequest)');
        }
      } catch (e) {
        if (window.XMLHttpRequest) {
          alert('There has been an error processing this request for URL '
               + httpRequest.originalURL + ':\n' + e);
        } else {
          alert('There has been an error processing this request:\n' + e);
        }
      }
    }
  }

  //Request the XML document
  httpRequest.open('DELETE', url, true);
  httpRequest.send('');
}

/**
 * This function builds and returns an httpRequest object
 */
function getNewHttpRequestObject(url) {
  var httpRequest = null;

  if (window.XMLHttpRequest) {
    httpRequest = new XMLHttpRequest();
    httpRequest.originalURL = url;
  } else if (window.ActiveXObject) {
    var objects = [
      "MSXML2.XMLHTTP.8.0",
      "MSXML2.XMLHTTP.7.0",
      "MSXML2.XMLHTTP.6.0",
      "MSXML2.XMLHTTP.5.0",
      "MSXML2.XMLHTTP.4.0",
      "MSXML2.XMLHTTP.3.0",
      "MSXML2.XMLHTTP.2.6",
      "MSXML2.XMLHTTP",
      "Microsoft.XMLHTTP.1.0",
      "Microsoft.XMLHTTP.1",
      "Microsoft.XMLHTTP"];
    for (var i=0; i<objects.length; i++) {
      try {
        httpRequest = new ActiveXObject(objects[i]);
        i = objects.length;
      } catch (e) {
      }
    }
  }

  return httpRequest;
}

/**
 * This function is the default error handler
 */
function ajaxError(httpRequest) {
  var message = 'An invalid response was received while
                             handling this request';
  if (window.XMLHttpRequest) {
    message += ' for URL ' + httpRequest.originalURL;
  }
  message += ':\nResponse code: ';
  message += httpRequest.status;
  message += '\nResponse: ';
  message += httpRequest.statusText;
  alert(message);
}

I also added new POJOs to the Approval service for the RFA, RFA approvers, and the RFA audit log. We’ll get into the details of those next time when we start building the RFA servlet.


http://blog.restafarian.org/2008/02/the-approval-service-pojos-and-repackaging/

Comments are closed.

Sorry, the comment form is closed at this time.