Appendix

ENTERPRISE JAVA
Reusing CORBA Web Services With JavaScript

David Houlding
Appendix
Below is a complete listing of the JavaScript client used to illustrate the concepts in this article.


<HTML>
<HEAD>
  <SCRIPT LANGUAGE="JavaScript">
    <!—-HIDE
    // The manager of all CORBA requests.
    var manager;

    // One particular CORBA request. Could load more ...
    var loginRequest;

    function initialize() {
        // Set up out own error handler.
        window.onerror = handleError

        // Get handles to CORBA request manager and load requests.
        manager = document.RequestManager;
        loginRequest =
          manager.loadRequest( "SecurityServer1_login.ser","login");
    }

    function login() {
        // Validate the input.
        var username = document.LoginForm.UsernameTextField.value;
        var password = document.LoginForm.PasswordTextField.value;
        if( ( username == "" ) || ( password == "" ) ) {
        alert( "Invalid username/password pair. Please try again." );
            return;
        }

        // Set request input arguments.
        loginRequest.setArgParamVal("userid",username);
        loginRequest.setArgParamVal("password",password);

        // Execute request.
        loginRequest.invoke();

        // Get request results.
        var secureSessionID = loginRequest.getReturnParamVal("return");

        // Show the results.
        document.cookie = "SecureSessionID=" + secureSessionID +
                                                          ";path=/"
        // Proceed to the next page.  window.location =
                               "http://www.trcinc.com/corbabeans";
    }

    function cancel() {
        // Cancel login and proceed.
        window.location = "http://www.trcinc.com";
    }

    function handleError( message, url, lineNumber ) {
        // Check for application exceptions and handle first.
        if( message == "InvalidUseridPasswordPair" ) {
        alert( "Invalid username/password pair. Please try again." );
        }
        else {
            // System exception, problem executing request.
            alert( "An unexpected error occurred. Please restart and
                                                         try again." );
            return false;
        }

        // Suppress the generic error alert.
        return true;
    }
//HIDE—->
</SCRIPT>
  <TITLE>CORBA Bean Manager Applet Test</TITLE>
</HEAD>
<BODY BGCOLOR="#c0c0c0" onLoad="initialize()">

<APPLET CODE="corbabeans.DynamicRequestManagerApplet.class"
                 NAME="RequestManager" WIDTH="1" HEIGHT="1">
<PARAM NAME="useslibrary" VALUE="CORBA Beans">
<PARAM NAME="useslibrarycodebase" VALUE="CORBABeans.cab">
<PARAM NAME="useslibraryversion" VALUE="2,4,0,0">
</APPLET>

<FORM ACTION="dummy" NAME="LoginForm">
  <P ALIGN=Left>
  <TABLE CELLPADDING="2">
    <TR VALIGN="Top">
      <TD><P ALIGN=Left>
	  <IMG SRC="SecurityIcon.gif" BORDER="0"></TD>
      <TD><H1 ALIGN=Left>
	  Login
	</H1>
      </TD>
    </TR>
    <TR>
      <TD><P ALIGN=Left>
	  <B>Username</B></TD>
      <TD><P ALIGN=Left>
	  <INPUT TYPE="text" NAME="UsernameTextField"></TD>
    </TR>
    <TR>
      <TD><P ALIGN=Left>
	  <B>Password</B></TD>
      
<TD><P ALIGN=Left>
	<INPUT TYPE="password" NAME="PasswordTextField"></TD>
    </TR>
    <TR>
      <TD><P ALIGN=Left>
      </TD>
      <TD>
    <INPUT TYPE=button VALUE="Login" onClick="login()">
	<INPUT TYPE=button VALUE="Cancel" onClick="cancel()">
	</TD>
</TR>
  </TABLE>
  <P ALIGN=Left>
</FORM>
<P>
</BODY>
</HTML>