I'm trying to compress a Post's payload with (pako.js) in an angular application and get the answer in a Java back-end application via rest communication. In the back-end, I write an interceptor, and try to decompress the request via GZIPInputStream. But,I always have a "Not in GZIP format" message.
The problem is probably in the encoding of the inputstream, but I can't figure out how to solve my issue. I test many solutions, but none of them work.
If I look at the byte[] of the input stream,this is the first indexes
[31, -62, -117, 8, 0, 0, 0, 0...
What am I doing wrong?
Angular's part
var stingtogzip = encodeURIComponent(JSON.stringify(criteria));
var gzipstring= pako.gzip(stingtogzip , { to : 'string'});
options.headers = new Headers();
options.headers.append("Content-Encoding","gzip");
options.body = gzipstring;
options.method = 'POST';
return this.http.request(req, options)
The interceptor code:
@Provider
public class GZIPReaderInterceptor implements ReaderInterceptor {
public Object aroundReadFrom(ReaderInterceptorContext ctx)
throws IOException {
String encoding = ctx.getHeaders().getFirst("Content-Encoding");
if (!"gzip".equalsIgnoreCase(encoding)) {
return ctx.proceed();
}
InputStream gzipInputStream = new GZIPInputStream(ctx.getInputStream());
ctx.setInputStream(gzipInputStream);
return ctx.proceed();
}
}