Submitting Request Examples

Examples are provided of setting up requests and submitting them to the server.

Synchronous Examples

In the following examples, the optional parameters are omitted, so they will wait for the server to respond, and they will return the response XML:

Example 1:

...
var request = com.tibco.wcc.base.Requests.ping(requestId);
var oResponseXml = this.executeServerRequests(socketId, [request]);
...

Example 2:

...
var oResponseXml = this.executeServerRequests(socketId, 
[ com.tibco.wcc.base.Requests.ping(requestId) ] );
...

Example 3:

...
var requests = new Array();
requests.push(com.tibco.wcc.base.Requests.ping(requestId));
requests.push(com.tibco.wcc.base.Requests.
getUserPrivileges(requestId, txtResourceGuid));
var oResponseXml = this.executeServerRequests(socketId, requests);
...

Example 4:

...
var oResponseXml = this.executeServerRequests(socketId, 
[ com.tibco.wcc.base.Requests.ping(requestId),
com.tibco.wcc.base.Requests.getUserPrivileges(requestId,
txtResourceGuid) ] );
...

Asynchronous Example

In the following example, the optional parameters are provided, causing it to be executed asynchronously.

...
classProto.submitServerRequest = function () {
   var requests = new Array();
   requests.push(com.tibco.wcc.base.Requests.ping(requestId));
   requests.push(com.tibco.wcc.base.Requests
   .getUserPrivileges(requestId, txtResourceGuid));
   this.executeServerRequests(socketId, requests, this,
   'handleServerResponse');
};
classProto.handleServerResponse = function (socketId, oResponseXml) {
   var txtReturnCode = oResponseXml.selectSingleNode
   ('/ap:ActionResult/ap:Status/ap:ReturnCode').getValue();
   var txtReturnComment = oResponseXml.selectSingleNode
   ('/ap:ActionResult/ap:Status/ap:ReturnComment').getValue();
   If (txtReturnCode != "0") {
   alert(txtReturnCode  + " - " + txtReturnComment );
   }
}
...

Since the function handling the response from the server is defined as part of the same class as the function executing the requests, the keyword 'this' can be used to identify the class.

The response XML is returned in a jsx3.xml.Document object so it can be examined or manipulated using the features of that object as described in the TIBCO General Interface documentation. In the code above, the return code and return comment are retrieved.