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_HEADERSyet. And we don't want to roll out changes without prior notifying to the clients and that'll take time. - The default
ACCEPTheader API Gateway's Integration Request uses isAPPLICATION/JSON. - So, S3 responds with
Content-Type:APPLICATION/JSONheader. However, the content is of typeAPPLICATION/OCTET-STREAM. - On de deserialization of content I encounter
java.util.zip.ZipException: incorrect header checkerror due toContent-Typemismatch.
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
ACCEPTheader with value ofAPPLICATION/OCTET-STREAMand 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.