import ws.*;

// Example of using WServer class on Passage Server

public class api_WServer
{
  public WTableList Request(WServer oServer, WParamList oParamList)
  { 
    int rc;
    String     szSessionID, szVar, szNote;
    WParamList oParamListRun;
    WTableList oTableList, oTableListRun;
    WTable     oTableRun, oTable;

    oParamListRun = oServer.newParamList();
    oTableList    = oServer.newTableList();
    oTable        = oServer.newTable();

    // Request
    oParamListRun.clear();
    oParamListRun.add("myparam1");
    oParamListRun.add("myparam2");
    oTableListRun = oServer.request("myrequest", oParamListRun);
    if (oTableListRun.getEC() != 0)
      return oTableListRun;
    oTableRun = oTableListRun.get(0); // Get table 0
    oTableList.add(oTableRun);        // table 0

    oTable.addCol(100);  // 0 Msg
    oTable.addRow();

    // Login
    rc = oServer.login("demo"); // "demo" is a Passage Server UserName
    if (rc != 0)
    {
      oServer.setPage("p_LoginFailed");
      oTable.set(0,0,"Invalid Passage Server UserName. Please contact technical support.");
      oTableList.add(oTable);
      return oTableList; 
    }

    // Cookie
    // In "Cookie" terminology [i.e. Domain and Path]
    // - default Domain is used, for example http://127.0.0.1 or http://mydomain.com
    // - Each Request belongs to certain Application
    // - Application Name acts as a Path
    // - Login(...) and SetCookie(...) methods use Application Name [automatically lowercased] as a Path to create cookies
    // - Path is case sensitive, i.e. should be equal to application folder name in URL http://127.0.0.1/demo/p_Login(UserName)
    //   if not equal, cookie is not sent by the browser
    // Example:
    // URL http://127.0.0.1/demo/p_Login(UserName) - works
    // URL http://127.0.0.1/Demo/p_Login(UserName) - does not work
    // URL http://127.0.0.1/demo/p_MyRequest(...) and SetCookie("mycookie","123") - works
    // URL http://127.0.0.1/Demo/p_MyRequest(...) and SetCookie("mycookie","123") - does not work

    oServer.setCookie("mycookie","123");  // creates cookie mycookie=123
    String szValue = oServer.getCookie("mycookie"); // returns "123"

    // Var
    oServer.setVar("myvar","123");              // creates the var
    szVar = oServer.getVar("myvar");            // returns 123 

    // Trace
    oServer.trace("my message");                // puts message to ws_app.log

    // Logout
    rc = oServer.logout();

    oServer.setPage("mypage");                  // returns mypage.html

    return oTableList; 
  }
}