Salesforce

How to call getSessions OEManager REST API from an ABL client?

« Go Back

Information

 
TitleHow to call getSessions OEManager REST API from an ABL client?
URL NameHow-to-call-getSessions-OEManager-REST-API-from-an-ABL-client
Article Number000111097
EnvironmentProduct: OpenEdge
Version: 11.7.4, 12.0
OS: All Supported Platforms
Question/Problem Description
This article provides an example to demonstrate using the ABL HttpClient libraries for fetching Sessions from the OE Manager REST API for a specific agent in a Progress AppServer for OpenEdge (PASOE) instance.
 
Steps to Reproduce
Clarifying Information
Error Message
Defect Number
Enhancement Number
Cause
Resolution
The below code takes the following parameters:
  • Host Name in the pcHost parameter
  • Port Number in the pcPort parameter(optional) 
  • Instance name in the pcInstance parameter
  • Agent Id for a specific PASOE agent
Then fills the AgentSession temp-table with a list of available sessions(excluding the manager):
USING OpenEdge.Net.HTTP.RequestBuilder.
USING openedge.net.http.IHttpRequest.
USING openedge.net.http.IHttpResponse.
USING Progress.Json.ObjectModel.*.
USING OpenEdge.Net.HTTP.ClientBuilder.
USING OpenEdge.Core.String.
USING OpenEdge.Net.HTTP.ResponseBuilder.
USING OpenEdge.Net.HTTP.IHttpClientLibrary.
USING OpenEdge.Net.HTTP.Lib.ClientLibraryBuilder.
USING OpenEdge.Net.HTTP.Credentials.
USING OpenEdge.Net.HTTP.Filter.Payload.StringEntityWriter.

DEFINE TEMP-TABLE AgentSession NO-UNDO
    FIELD SessionId             AS INTEGER 
    FIELD SessionState          AS CHARACTER
    FIELD StartTime             AS CHARACTER
    FIELD EndTime               AS CHARACTER
    FIELD ThreadId              AS INTEGER FORMAT "-zzzzzzz9"
    FIELD ConnectionId          AS CHARACTER
    FIELD SessionExternalState  AS INTEGER
    FIELD SessionMemory         AS INT64
    FIELD tcInstanceName        AS CHARACTER
    FIELD tcAgentId             AS CHARACTER.

DEFINE INPUT  PARAMETER pcHost     AS CHARACTER   NO-UNDO.
DEFINE INPUT  PARAMETER pcPort     AS CHARACTER   NO-UNDO.
DEFINE INPUT  PARAMETER pcInstance AS CHARACTER   NO-UNDO.
DEFINE INPUT  PARAMETER pcAgentId  AS CHARACTER   NO-UNDO.

DEFINE VARIABLE cUrl         AS CHARACTER                NO-UNDO.
DEFINE VARIABLE cMessage     AS CHARACTER                NO-UNDO.

DEFINE VARIABLE oEntity      AS JsonObject               NO-UNDO.
DEFINE VARIABLE oSessions    AS JsonArray                NO-UNDO.
DEFINE VARIABLE oRequest     AS IHttpRequest             NO-UNDO.
DEFINE VARIABLE oResponse    AS IHttpResponse            NO-UNDO.
DEFINE VARIABLE oLib         AS IHttpClientLibrary       NO-UNDO.
DEFINE VARIABLE oCredentials AS Credentials              NO-UNDO.    

DEFINE VARIABLE lcResponse   AS LONGCHAR                 NO-UNDO.

cUrl = "http://" + pcHost + (IF (pcPort GT "") EQ TRUE THEN ":" + pcPort ELSE "") +
       "/oemanager/applications/" + pcInstance + "/agents/" +
       pcAgentId + "/sessions".

oCredentials = NEW Credentials("http://localhost","tomcat","tomcat").

ASSIGN oRequest  = RequestBuilder:Get(cUrl)
                                 :UsingBasicAuthentication(oCredentials)
                                 :Request
       oResponse = ResponseBuilder:Build():Response
       oLib      = ClientLibraryBuilder:Build():sslVerifyHost(NO):Library
    NO-ERROR.

ClientBuilder:Build()
             :UsingLibrary(oLib)
             :Client:Execute(oRequest,oResponse).
oEntity  = CAST(oResponse:Entity,JsonObject).
cMessage = oEntity:GetCharacter("errmsg").

IF (cMessage GT "") EQ TRUE THEN DO:
    MESSAGE "Request failed with the below Error:" SKIP(1)
            cMessage
        VIEW-AS ALERT-BOX INFORMATION BUTTONS OK.
    RETURN.
END.

oSessions = CAST(CAST(oEntity:GetJsonObject('result'),JsonObject):GetJsonArray('AgentSession'),JsonArray).
    
BUFFER AgentSession:READ-JSON("JsonArray",oSessions,"APPEND").
FOR EACH AgentSession:
    DISPLAY "A-" + STRING(AgentSession.sessionId).
END.

The RAW JSON Response String generated by this request is below:
{  
   "result":{  
      "AgentSession":[  
         {  
            "SessionId":4,
            "SessionState":"IDLE",
            "StartTime":"2019-03-27T08:38:58.421",
            "EndTime":null,
            "ThreadId":-1,
            "ConnectionId":null,
            "SessionExternalState":0,
            "SessionMemory":778220
         },
         {  
            "SessionId":7,
            "SessionState":"IDLE",
            "StartTime":"2019-03-27T08:38:58.421",
            "EndTime":null,
            "ThreadId":-1,
            "ConnectionId":null,
            "SessionExternalState":0,
            "SessionMemory":778220
         }
      ]
   },
   "versionNo":1,
   "outcome":"SUCCESS",
   "versionStr":"v11.7.4 ( 2018-10-10 )",
   "errmsg":"",
   "operation":""
}





 
Workaround
Notes
Keyword Phrase
Last Modified Date11/20/2020 7:01 AM

Powered by