0

What is the issue?

  • We use AWS API Gateway for integration with the AWS S3 using REST calls.
  • In the API Gateway transformation we haven't supported HTTP_HEADERS yet. And we don't want to roll out changes without prior notifying to the clients and that'll take time.
  • The default ACCEPT header API Gateway's Integration Request uses is APPLICATION/JSON.
  • So, S3 responds with Content-Type : APPLICATION/JSON header. However, the content is of type APPLICATION/OCTET-STREAM.
  • On de deserialization of content I encounter java.util.zip.ZipException: incorrect header check error due to Content-Type mismatch.

Code Snippet:

    String apiUrl = "https://url";

    //REQUEST 
    final var client = HttpClients.createDefault();
    HttpGet httpGet = new HttpGet(apiUrl);
    httpGet.addHeader("Accept", "application/octet-stream"); //IT IS USELESS TO ADD HERE (IGNORED).


    //RESPONSE      
    var response = client.execute(httpGet);
 

    //DESERIALIZATION
    byte[] responseString = EntityUtils.toByteArray(response.getEntity());

         
    CustomObject fullValuationObject = CompressedReadWriteFormat.deserializeDeflated(responseString);

What I've already tried?

  • WORKED: I've created an another API Gateway that accepts ACCEPT header with value of APPLICATION/OCTET-STREAM and the response got successfully de serialized. However, we don't want to create another API Gateway for the same.

Any solution that could apparently change the content on the Application layer(Java) would be great.

I'll highly appreciate for any solution.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.