Salesforce

Handling compressed/zipped responses in httpclient.

« Go Back

Information

 
TitleHandling compressed/zipped responses in httpclient.
URL NameHandling-compressed-zipped-responses-in-httpclient
Article Number000110756
EnvironmentProduct: Openedge
Version: 11.7.x
OS: All supported platforms
Other: httpclient
Question/Problem Description
Application uses the httpclient to make a request to a web service. 
The response to the request needs to be used in subsequent requests.
Using the TYPE-OF API, the response seems to be a memptr.
How can the json format string be extracted from the payload?

 
Steps to ReproduceRun attached code
Clarifying Information
RequestBuilder call included the following:        :AddHeader("Accept-Encoding","gzip,deflate") 
The response from the service is encoded in gzip format.
Error MessageInvalid character data found in MEMPTR for codepage (12012)
Defect Number
Enhancement Number
Cause
The httpclient does not directly support gzipped payloads.
Resolution
Do not include a header that allows gzip encoded responses.
Workaround
There is no straight forward method for handling gzip encoded payloads.
The following multi-step process could be used:

1) This first step is a code snippet showing how to extract the encoded payload from the response entity and write it to a file.
/* assume an httpclient request has already been created  in variable oRequest */
DEFINE VARIABLE oMyEntity AS Object NO-UNDO.
DEFINE VARIABLE mRsp AS OpenEdge.core.MEMPTR.
DEFINE VARIABLE mPtrResp AS MEMPTR NO-UNDO.
DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO.
DEFINE VARIABLE oResponse AS IHttpResponse NO-UNDO.
oResponse = ClientBuilder:Build():Client:Execute(oRequest).
oMyEntity = oResponse:Entity.
IF TYPE-OF (oMyEntity, Memptr) THEN DO:
        mRsp = CAST(oMyEntity, OpenEdge.Core.Memptr).
        mPtrResp = mRsp:VALUE.
        COPY-LOB mPtrResp to file session:temp-dir + "entity.zip".
END.


This results in a gzip file being created, named entity.zip. It contains a file named entity.
2) Use OS-COMMAND to call an unzip program.
The output file might be called entity.json.
3) Read in file entity.json via ObjectModelParser 
     For example ObjectModelParser('entity.json').
 
Notes
References to other Documentation:
https://docs.progress.com/bundle/openedge-abl-reference-117/page/ParseFile-method.html
https://docs.progress.com/bundle/openedge-abl-develop-http-clients/page/Execute-an-HTTP-request.html
https://documentation.progress.com/output/oehttpclient/117/index.html?OpenEdge.Net.HTTP.HttpClient.html
https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvpin/openedge.net.http.httpclient.html

Progress Article(s):
 Is there an HTTP client for OpenEdge?

Please note:
The following code gets to the same result but might be a little more memory efficient:

IF TYPE-OF (oMyEntity, Memptr) THEN DO:
    COPY-LOB CAST(oMyEntity, OpenEdge.Core.Memptr):VALUE to file session:temp-dir + "entity.zip".
END.

 
Keyword Phrase
Last Modified Date2/12/2021 2:34 PM

Powered by