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 agents temp-table with a list of available agents(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.Net.HTTP.ResponseBuilder.
USING OpenEdge.Net.HTTP.IHttpClientLibrary.
USING OpenEdge.Net.HTTP.Lib.ClientLibraryBuilder.
USING OpenEdge.Net.HTTP.Credentials.
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 VARIABLE oResponse AS IHttpResponse NO-UNDO.
DEFINE VARIABLE oEntity AS JsonObject NO-UNDO.
DEFINE VARIABLE oCredentials AS Credentials NO-UNDO.
DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO.
DEFINE VARIABLE oLib AS IHttpClientLibrary NO-UNDO.
DEFINE VARIABLE oAgents AS JsonArray NO-UNDO.
DEFINE VARIABLE cURL AS CHARACTER NO-UNDO.
DEFINE VARIABLE cMessage AS CHARACTER NO-UNDO.
DEFINE VARIABLE lcResponse AS LONGCHAR NO-UNDO.
// You can call the temp-table and the fields whatever you want,
// as long as you use SERIALIZE-NAME to ensure that the JSON parser
// knows them under the below nomenclatures when mapping the json
// from the response to temp-table records.
//
// This is by far the easiest way to consume the results from a
// getAgents request
DEFINE TEMP-TABLE agents NO-UNDO
FIELD agentId AS CHARACTER
FIELD pid AS CHARACTER
FIELD state AS CHARACTER
FIELD errmsg AS CHARACTER
FIELD versionStr AS CHARACTER
FIELD versionNo AS INTEGER
FIELD outcome AS CHARACTER
FIELD operation AS CHARACTER.
// URL: http(s)://<hostname>:<instance_manager_port>/oemanager/applications/<instance_name>/agents
cURL = "http://" + pcHost + (IF (pcPort GT "") EQ TRUE THEN ":" + pcPort ELSE "")
"/oemanager/applications/" + pcInstance + "/agents".
// You have to login with admin rights to the tomcat manager. If you've changed
// the password, or use a different admin user, you'll need to use the modified credentials
oCredentials = NEW Credentials("http://localhost","tomcat","tomcat").
// Make the HTTP call
oRequest = RequestBuilder:Get(cUrl)
:UsingBasicAuthentication(oCredentials)
:Request.
oResponse = ResponseBuilder:Build():Response.
oLib = ClientLibraryBuilder:Build():sslVerifyHost(NO):Library.
ClientBuilder:Build()
:UsingLibrary(oLib)
:Client:Execute(oRequest,oResponse).
// Cast the result of the call into a JsonObject.
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.
// The first object in the response is always named result and the
// details of the response are children of the result object
// This depicts getting the result object, then getting the agents
// temp-table (array) from that, in one long chained reference
oAgents = CAST(CAST(oEntity:GetJsonObject('result'),
JsonObject):GetJsonArray('agents'),
JsonArray).
// Read the agents temp-table in
BUFFER agents:READ-JSON("JsonArray",oAgents,"APPEND").
FOR EACH agents:
// Make some additional call, like getSessions using the agentId
// and the instance name
END.
A sample of the RAW JSON Response String from a getAgents request is below:
{
"result":{
"agents":[
{
"agentId":"EQruUKdITjqHHfDML8YmhQ",
"pid":"23924",
"state":"AVAILABLE"
}
]
},
"versionNo":1,
"outcome":"SUCCESS",
"versionStr":"v11.7.4 ( 2018-10-10 )",
"errmsg":"",
"operation":"GET AGENTS"
}