Parsing an IHttpResponse

Posted by Tim Kuehn on 08-Mar-2016 17:36

I've got a call that looks like so: 

oResponse = ClientBuilder
  :Build()
  :Client
  :Execute(oRequest)
  .

oResponse is an instance of an IHttpResponse interface. I expect it to have a payload that looks something like this:

{
  "commit" : "localhost:7474/.../commit",
  "results" : [ {
    "columns" : [ "n" ],
    "data" : [ {
      "row" : [ {
        "name" : "My Node"
      } ]
    } ]
  } ],
  "transaction" : {
    "expires" : "Wed, 13 Jan 2016 00:00:00 +0000"
  },
  "errors" : [ ]
}

Problem is - I can't find any docs on how to get the payload / header out of the oResponse object instance. Looking at https://documentation.progress.com/output/oehttpclient/index.html I see an "Entity" property - that's protected, so I can't get to it .

How should I proceed? 

All Replies

Posted by Shelley Chase on 08-Mar-2016 19:00

Hi Tim,

Take a look at:

community.progress.com/.../1800

-Shelley

Posted by Peter Judge on 08-Mar-2016 19:28

By definition properties in interfaces must be public :)
 
You were heading in the right direction though: The Entity property contains the message entity (sometimes called the body; the name 'entity' comes from the RFC2616 spec).  Since we don't have generics in the language (yet) it's defined as a P.L.Object and you have to manually cast to an appropriate type.
 
Cast to what, you might be asking around about now. You can check the type of the Entity property via TYPE-OF() or you can use <response>:Entity:GetClass():IsA(). You can also look at the ContentType property which gives you a hint via the MIME type it contains.
 
The Status and StatusCode properties give you the 200 (int) and OK (char) values.
Take a look at the GetHeader(s) properties to get the header values. Similarly GetCookie(s) for tasty treats.
 
Some headers have their own properties – ContentType, ContentLength and others - but the values 'behind' are the same as in the headers.
 
In your case, the Entity property will be of type JsonObject . You can always cast to JsonObject or JsonConstruct but that will somewhat depend on how generalised the calling code is (ie how sure are you that you will always get a JSON entity in the body).
 

Posted by Tim Kuehn on 08-Mar-2016 21:50

Thanks Shelley!

Posted by Tim Kuehn on 08-Mar-2016 22:49

Agreed on the public property interfaces - so I'm thinking the docs that list it as protected is error, or the entity property isn't part of the interface.

Based on what you wrote I was able to get the data where it belonged, and this is the result: 

oJsonObject = CAST(oResponse:Entity, JsonObject).

ASSIGN 
    chCommit        = oJsonObject:GetCharacter("commit")
    oResultArray    = oJsonObject:GetJsonArray("results")
    oTransJson      = oJsonObject:GetJsonObject("transaction")
    oJsonErrorArray = oJsonObject:GetJsonArray("errors")
    .

Thx!

Posted by Peter Judge on 09-Mar-2016 08:02

That's clearly a bug in the API doc : it's public (and intended to hold the entity/body)
 

This thread is closed