/*------------------------------------------------------------------------
File : get_applications.p
Purpose : Returns the list of applications from a PASOE server
Notes : * this is the equivalent of curl -X GET -v http://localhost:<port>/oemanager/applications/ -u tomcat:tomcat
----------------------------------------------------------------------*/
BLOCK-LEVEL ON ERROR UNDO, THROW.
USING OpenEdge.Net.HTTP.ClientBuilder.
USING OpenEdge.Net.HTTP.Credentials.
USING OpenEdge.Net.HTTP.IHttpClient.
USING OpenEdge.Net.HTTP.IHttpRequest.
USING OpenEdge.Net.HTTP.RequestBuilder.
USING OpenEdge.Net.URI.
USING OpenEdge.Net.HTTP.IHttpResponse.
USING Progress.Json.ObjectModel.JsonObject.
/* *************************** Session config *************************** */
/* OPTIONAL FOR DEBUG/TRACING
session:error-stack-trace = true.
log-manager:logging-level = 6.
log-manager:logfile-name = session:temp-dir + 'get_applications.log'.
log-manager:clear-log().
*/
/* *************************** Main Block *************************** */
DEFINE VARIABLE oClient AS IHttpClient NO-UNDO.
define variable oUri AS URI NO-UNDO.
define variable oReq AS IHttpRequest NO-UNDO.
define variable oResp AS IHttpResponse NO-UNDO.
define variable oCreds AS Credentials NO-UNDO.
define variable oJson AS JsonObject NO-UNDO.
oClient = ClientBuilder:Build():Client.
oCreds = new Credentials('oerealm', 'tomcat', 'tomcat').
oUri = new URI('http', 'localhost', <http-port>).
oUri:Path = '/oemanager/applications/'.
oReq = RequestBuilder:Get(oUri)
:UsingCredentials(oCreds)
:Request.
oResp = oClient:Execute(oReq).
if type-of(oResp:Entity, JsonObject) then
assign oJson = cast(oResp:Entity, JsonObject).
/* do what you need to with the JSON here */
CATCH oError AS Progress.Lang.Error :
MESSAGE
oError:GetMessage(1) SKIP(2)
oError:CallStack
VIEW-AS ALERT-BOX.
END CATCH.