REST-API, receive gzip compressed data

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
Jurgen.Rentinck
Posts: 11
Joined: Wed Nov 25, 2015 9:02 pm
Location: Amsterdam
Contact:

REST-API, receive gzip compressed data

Post by Jurgen.Rentinck »

Hi,

I have a situation where it is mandatory to add the HTTP header variable Accept-Encoding: gzip to the request.
The API will now return the JSON compressed as expected but how do we now use the JSON?

Is there a utility in Visual LANSA to deflate the data?

Thanks,
Jurgen
Jurgen.Rentinck
Posts: 11
Joined: Wed Nov 25, 2015 9:02 pm
Location: Amsterdam
Contact:

Re: REST-API, receive gzip compressed data

Post by Jurgen.Rentinck »

I found out this is not yet supported natively in Visual LANSA.
There is an option that can be used as a workaround this is a Windows only solution.

The gzip.exe tool can be downloaded here http://gnuwin32.sourceforge.net/packages/gzip.htm .
In the sample code below it assumed the content of the bin directory is copied to the gzip directory located in the LANSA Root directory, e..g. c:\program files\lansa\gzip.
In this gzip directory there also needs to be a temp directory, c:\program files\lansa\gzip\temp.

Following sample code can than be used as a reference:

#ucGZippedFile is a Unicode string
#ucRequest is a XPRIM_HttpRequest

If (#ucAPIUtils.umDecompressGzipContent( #ucRequest #ucGzippedFile ))
#ucHttp.Response.SetContentFile FileName(#ucGzippedFile) RemoveAfterSend(True)
Endif

Mthroutine Name(umDecompressGzipContent)
Define_Map For(*Input) Class(#XPRIM_HttpRequest) Name(#iRequest) Pass(*By_Reference)
Define_Map For(*Output) Class(#prim_alph) Name(#oDecompressedFile)
Define_Map For(*Result) Class(#prim_boln) Name(#rResult)

Define_Com Class(#PRIM_ALPH) Name(#ucGzippedFile)
Define_Com Class(#PRIM_ALPH) Name(#ucGZIPCommand)

#rResult := False

#ucGzippedFile := *ROOT_DIR + "\gzip\temp\" + *GUID + ".gz"
#iRequest.Response.AsFile Path(#ucGzippedFile)

#ucGZIPCommand := *ROOT_DIR + "\gzip\gzip.exe -d " + #ucGzippedFile
Use Builtin(SYSTEM_COMMAND) With_Args("B" #ucGZIPCommand) To_Get(#std_num)
If (#std_num = 0)
#rResult := True
#oDecompressedFile := #ucGzippedFile.Remove( ".gz" )
Endif
Endroutine

Post Reply