You can use the following APIs to manage the session.
Syntax |
Description |
---|---|
Loads all sessions. |
|
Gets the number of sessions in the current server instance. |
|
Kills a session. |
Loads all sessions.
Syntax: GET /api/Session/LoadAll
PowerScript code example:
Integer li_rc String ls_body httpclient lhc_client lhc_client = create httpclient lhc_client.setrequestheader("Content-Type", "application/json;charset=UTF-8",true) li_rc = lhc_client.sendrequest( "GET", "http://172.25.100.32:5000/api/Session/LoadAll") if li_rc = 1 and lhc_client.getresponsestatuscode( ) = 200 then lhc_client.getresponsebody(ls_body) end if
When successful, it returns the response status code 200 and the following response body:
When failed, it returns 400 (bad request), 401 (unauthorized), or 500 (server error).
[ { "sessionId": "string", "application": "string", "sessionState": "string", "ipAddress": "string", "serverIPAddress": "string", "duration": 0, "createTime": "2022-02-18T08:35:02.444Z", "lastVisitTime": "2022-02-18T08:35:02.444Z" } ]
You can also use the GetSessionID function of the PowerBuilder Application object to get the session ID of the current client. For example,
To get the session ID of the current application client, you can write PowerScripts as below:
String ls_SessionID ls_SessionID = Getapplication().GetSessionID()
Gets the number of sessions in the current server instance.
Syntax: GET /api/Session/GetSessionCount
PowerScript code example:
Integer li_rc String ls_body httpclient lhc_client lhc_client = create httpclient lhc_client.setrequestheader("Content-Type", "application/json;charset=UTF-8",true) li_rc = lhc_client.sendrequest( "GET", "http://172.25.100.32:5000/api/Session/GetSessionCount") if li_rc = 1 and lhc_client.getresponsestatuscode( ) = 200 then lhc_client.getresponsebody(ls_body) end if
When successful, it returns the number of sessions.
When failed, it returns 400 (bad request), 401 (unauthorized), or 500 (server error).
Kills a session.
Syntax: POST /api/Session/KillById/{sessionId}
{sessionId} indicates the session to be killed.
PowerScript code example:
Integer li_rc String ls_body httpclient lhc_client lhc_client = create httpclient lhc_client.setrequestheader("Content-Type", "application/json;charset=UTF-8",true) li_rc = lhc_client.sendrequest( "Post", "http://172.25.100.32:5000/api/Session/KillById/242E3A23-C05D-4265-9388-493EA53F76CF") if li_rc = 1 and lhc_client.getresponsestatuscode( ) = 200 then lhc_client.getresponsebody(ls_body) end if
When successful, it returns the response status code 200 and the following response body.
When failed, it returns 400 (bad request), 401 (unauthorized), or 500 (server error).
{ "sessionId": "string", "watermark": "string", "licenseMode": "string", "sessionStatus": 0, "isSuccess": true, "version": "string", "requestId": "string", "appName": "string", "namespace": "string", "session": { "errCode": 0, "errMsg": "string", "sessionId": "string" }, "type": 0, "transaction": { "transactionId": "string", "sqlCode": 0, "sqldbCode": 0, "sqlErrText": "string", "sqlnRows": 0, "sqlReturnData": "string" }, "content": "string" }