How to read the plain text response to a ClientBuilder call?

Posted by Mike_M_Carlson on 13-Mar-2018 13:22

Using the .Net.HTTP Request/Response to a 3rd party API. Normally the responses are sent as JSON objects, which are handled fine, but when making a call to an API that we are not authorized to access, no object is returned and the status code shows 200.  When making the same call using curl on the command-line, a plain text message is returned stating "...does not have authorization...".    

How can we capture that plain text message from the ClientBuilder response ? We just get the error :

Invalid cast from OpenEdge.Core.Memptr to Progress.Json.ObjectModel.JsonObject. (12869) Invalid handle. Not initialized or points to a deleted object. (3135)

Thank you,

Mike

Posted by Mike_M_Carlson on 13-Mar-2018 16:13

Forgot about that file. It holds exactly what I see when issuing the curl command-line script.

And casting the response to a memptr and dumping to a file gets the exact message.

I think I can handle it from here. I was trying to see that message to be able to parse it in code.

I want to thank you and Mike F. very much for your helpful and quick responses!

Mike

All Replies

Posted by Peter Judge on 13-Mar-2018 13:32
If you run with log-manager:logging-level of = 5 you will get a request-raw.txt and response-data-reeived.txt in the session’s temp-dir.
What’s the ContentType of the response object?
 
 
 
Posted by Mike_M_Carlson on 13-Mar-2018 15:27

Here is the basic code.

oCredentials = NEW Credentials('application',cUserID,cPassword).

oRequestObj = NEW JsonObject().

oRequestObj:Add("SerialNumber":U, cSerialNumber).

oRequest = RequestBuilder:Post(cURL, oRequestObj)

               :AcceptJson()

               :UsingBasicAuthentication(oCredentials)

               :Request.

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

From the log-manager:

[18/03/13@15:24:21.174-0500] P-009448 T-008584 1 4GL LogMgrWrtr     [OE.N.HTTP.L.ABLS.ABLSocketLibrary ERROR] EXTRACT ENTITY ERROR

[18/03/13@15:24:21.174-0500] P-009448 T-008584 1 4GL LogMgrWrtr     Error(s) raised: Progress.Json.JsonParserError

[18/03/13@15:24:21.174-0500] P-009448 T-008584 1 4GL LogMgrWrtr     Json Parser Error at offset 144: parse error: client cancelled parse via callback return value. (16068) (16068)

[18/03/13@15:24:21.175-0500] P-009448 T-008584 1 4GL LogMgrWrtr     [OE.N.HTTP.L.ABLS.ABLSocketLibrary ERROR] EXTRACT ENTITY: Response entity contains raw message body

[18/03/13@15:24:21.176-0500] P-009448 T-008584 1 4GL LogMgrWrtr     [OE.N.HTTP.L.ABLS.ABLSocketLibrary ERROR] EXTRACT ENTITY: Response Content-Type changed from application/json to application/octet-stream

Posted by Mike Fechner on 13-Mar-2018 15:31

CAST (oResponse:Entity, OpenEdge.Core.String):Value .

Posted by Mike_M_Carlson on 13-Mar-2018 15:48

code:

DEFINE VARIABLE oResponse AS IHttpResponse NO-UNDO.   /* to show how its defined */

CAST(oResponse:Entity, OpenEdge.Core.String):VALUE

run error:

Invalid cast from OpenEdge.Core.Memptr to OpenEdge.Core.String. (12869)

Posted by Mike Fechner on 13-Mar-2018 15:54
OK, so your response is binary - or at least interpreted as such.

Then assign CAST(oResponse:Entity, OpenEdge.Core.String):VALUE to a MEMPTR variable and COPY-LOB that to a file for diagnostics.

 
 
Posted by Peter Judge on 13-Mar-2018 15:54
What’s in the response-data-received.txt file? Is it value real JSON? There will be a bumch of nulls at the end, ignore those.
 
You can also do copy-lob cast(response:Entity, OpenEdge.Core.Memptr):Value to file ‘dump.txt’.
 
Posted by Mike_M_Carlson on 13-Mar-2018 16:13

Forgot about that file. It holds exactly what I see when issuing the curl command-line script.

And casting the response to a memptr and dumping to a file gets the exact message.

I think I can handle it from here. I was trying to see that message to be able to parse it in code.

I want to thank you and Mike F. very much for your helpful and quick responses!

Mike

This thread is closed