Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Jesperrekuh
Specialist
Specialist

How to uncompress (inflate) gzip REST Api response?

Hi

 

Would love to know how to decompress / uncompress (inflate) gzip String?  Please : Without saving it as a zip file.

It's response of a rest-api call UTF-8 compressed 

Would be nice if there are some functions related to string-handling: package (doc) util.java zip


cheers + thanks!

 

 

Labels (4)
6 Replies
manodwhb
Champion II
Champion II

Jesperrekuh
Specialist
Specialist
Author

@manodw , sorry, but not a proper solution. very inefficient! 

 

I get a server response (gzip) -> (allready in memory) -> disk i/o-> fileOut ->  fileIn -> disk i/o -> (unzip process) ->  back in memory
should be server response (gzip) -> (allready in memory) -> decrypt bytes in memory -> save to db / disk i/o OR do whatever I wanna do.

 

 

Sarye
Contributor III
Contributor III

Hi everyone,0683p000009Lzxi.png

 

I'm facing exactly the same issue as @Dijke:

- I perform an API call through tRESTClient.
- The server's response has the header:     content-encoding: [gzip]
     -- So It's gzip compressed. The API documentation formally stipulate that clients has to activate gzip handling, because the response is always gziped.
- But tRESTClient's output schema has default values and the gzip content is cast as a string in the default field "string" 0683p000009M0Og.png. As a result, I can not read the response. Here the tLogRow Output :

 

 

Does anyone has found a solution ? Thanks.

Sarye
Contributor III
Contributor III

Hi, I found a solution and here it is!

I've also opened a Jira ticket to report the issue: https://jira.talendforge.org/browse/TDI-41702, fell free to vote it up.

 

Here is a piece of Java code that inflat a GZIPed API response. For the demo I used StackExchange API which by default GZIP its reponses.

 

tJava Advanced Settings

import java.util.zip.GZIPInputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.net.HttpURLConnection;
import java.net.URL;

tJava Basic Settings

// Ini API CALL
URL url = new URL("https://api.stackexchange.com/2.2/info?site=stackoverflow");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("User-Agent", "Test");

// Store ResponseCode
int status = con.getResponseCode();

// Inflat gzip stream (the API response content is gziped)
GZIPInputStream gzis = new GZIPInputStream(con.getInputStream());
InputStreamReader reader = new InputStreamReader(gzis);
BufferedReader in = new BufferedReader(reader);

// Send the output to next component, line by line
String readed;
while ((readed = in.readLine()) != null) {
//   System.out.println(readed);
	row2.content = readed;
}

 

rgagnon
Contributor
Contributor

 

In Talend 7.1.1, the tESBConsumer component supports GZIP encoding.

RGriveau
Contributor III
Contributor III

How do you do a REST call with a tESBConsumer?