TRTH v2 using Unirest java http client vbd gzip download issue

We’re having issues while trying to programmatically run DSS StandardExtractions UserPackageDelivery using Unirest java http client.

When trying to stream the file contents using ‘StandardExtractions/UserPackageDeliveries({id})/$value’ request we do not get the file in compressed ‘gzip’ format as advised by the API documentation.

While sending the http GET request we’re sending the header ‘Accept-Encoding: gzip’ as advised. We can also see the response header correctly puts ‘Content-Encoding=gzip’, the response body however appears to be plain text format. How can we receive the streamed file contents in gzip format for StandardExtractions?

Best Answer

  • Jirapongse
    Answer ✓
    @Arvind Kaushik

    I think that you are correct. From my test, the response always contain "Content-Encoding: gzip" no matter the "Accept-Encoding: gzip" is present, or not. It conflicts with the statement mentioned in the documents. I will contact the development team to verify it.

    For now, to get the raw gz file, you can use this kind of Java code.

    		HttpClient client = HttpClients.custom().disableContentCompression().build();

    HttpGet httpget = new HttpGet("https://hosted.datascopeapi.reuters.com/RestApi/v1/StandardExtractions/UserPackageDeliveries('0x05d0f50a992b2f96')/$value");
    httpget.addHeader("Authorization", "Token <token>");
    CloseableHttpResponse response;
    try {
    response = (CloseableHttpResponse) client.execute(httpget);
    InputStream is = response.getEntity().getContent();
    FileOutputStream fos = new FileOutputStream(new File("c:\\output.cvs.gz"));
    int inByte;
    while((inByte = is.read()) != -1)
    fos.write(inByte);
    is.close();
    fos.close();
    } catch (ClientProtocolException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

Answers