I have an application that sends a XML request document to a external vendor. The Vendor then responds with an XML document. The respond XML can be relatively large (> 5 MB) and therefore takes a long time to receive back over the WAN. The vendor recommended adding 'Accept-Encoding: gzip' to the request which allows them to compress the response. The compressed file is much smaller. However I am not familiar with how to un-compress the new response in order to convert it back to and XML file I can process using Progress 4GL. Has anyone developed a solution for a similar process that can share ideas. I am running progress OpenEdge 11 on a Windows 2008 Server.
Code I am running looks as follows
Code I am running looks as follows
Code:
DEFINE INPUT PARAMETER pmop-file AS MEMPTR NO-UNDO. /* Memptr of XML request file */
DEFINE VARIABLE vcposturl AS CHARACTER NO-UNDO.
DEFINE VARIABLE vcfilepath_ZIP AS CHARACTER NO-UNDO.
DEFINE VARIABLE vcHost AS CHARACTER INITIAL "xml.vendor.com" NO-UNDO.
DEFINE VARIABLE vcPort AS CHARACTER INITIAL "7080" NO-UNDO.
DEFINE VARIABLE vhSocket AS HANDLE NO-UNDO.
ASSIGN
vcposturl = "http://xml.vendor.com"
vcfilepath_ZIP = "C:/.../response.zip".
CREATE SOCKET vhSocket.
vhSocket:CONNECT('-H ' + vcHost + ' -S ' + vcPort) NO-ERROR.
IF vhSocket:CONNECTED() = FALSE THEN
DO:
MESSAGE "Vendor Connection failure" VIEW-AS ALERT-BOX.
RETURN.
END.
ELSE
DO:
MESSAGE "Vendor Connection successful" VIEW-AS ALERT-BOX.
END.
vhSocket:SET-READ-RESPONSE-PROCEDURE('getResponse').
RUN PostRequest (INPUT vcposturl).
WAIT-FOR READ-RESPONSE OF vhSocket.
vhSocket:DISCONNECT() NO-ERROR.
DELETE OBJECT vhSocket.
/* QUIT. */
RETURN.
PROCEDURE getResponse:
DEFINE VARIABLE vcWebResp AS LONGCHAR NO-UNDO.
DEFINE VARIABLE vcXMLExtract AS LONGCHAR NO-UNDO.
DEFINE VARIABLE viWebRespIdx AS INTEGER NO-UNDO.
DEFINE VARIABLE lSucess AS LOGICAL NO-UNDO.
DEFINE VARIABLE mResponse AS MEMPTR NO-UNDO.
IF vhSocket:CONNECTED() = FALSE THEN do:
MESSAGE "Vendor getResponse Not Connected" VIEW-AS ALERT-BOX.
RETURN.
END.
lSucess = TRUE.
DO WHILE vhSocket:GET-BYTES-AVAILABLE() > 0:
SET-SIZE(mResponse) = vhSocket:GET-BYTES-AVAILABLE() + 1.
SET-BYTE-ORDER(mResponse) = BIG-ENDIAN.
vhSocket:READ(mResponse,1,1,vhSocket:GET-BYTES-AVAILABLE()).
vcWebResp = vcWebResp + GET-STRING(mResponse,1).
END.
/* Code below saves response to file. However I don't think I have this correct as the zip file gives errors when I try to extract files from it */
vcXMLExtract = vcWebResp.
OUTPUT TO VALUE(vcfilepath_ZIP).
EXPORT vcXMLExtract.
OUTPUT CLOSE.
/* Need ideas on how to process zip file to uncompress and extract XML file(s) for processing using progress */
END.
PROCEDURE PostRequest:
DEFINE INPUT PARAMETER postUrl AS CHAR.
DEFINE VARIABLE vcRequest AS CHARACTER.
vcRequest = 'POST ' + postUrl + ' HTTP/1.1~r~n' +
'Host: xml.vendor.com~r~n' +
'Content-Type: application/x-www-form-urlencoded~r~n' +
'Content-Length: ' + STRING(LENGTH(STRING(pmop-file))) + '~r~n' +
'Accept-Encoding: gzip ' + '~r~n' +
'~r~n' +
STRING(pmop-file) + '~r~n'.
SET-SIZE(pmop-file) = 0.
SET-SIZE(pmop-file) = LENGTH(vcRequest) + 1.
SET-BYTE-ORDER(pmop-file) = BIG-ENDIAN.
PUT-STRING(pmop-file,1) = vcRequest .
vhSocket:WRITE(pmop-file, 1, LENGTH(vcRequest)).
vhSocket:WRITE(pmop-file, 1, GET-SIZE(pmop-file)).
END PROCEDURE.
Last edited: