Jerseyサービスでgzipエンコーディングを有効にすることはできません。Jersey 2/GrizzlyでのGZIPエンコーディング
がGetting Started Guideから
jersey-quickstart-grizzly2
原型で始まっ:これは私が試したものです。追加さ
rc.register(org.glassfish.grizzly.http.GZipContentEncoding.class);
(また
rc.register(org.glassfish.jersey.message.GZipEncoder.class);
を試みた)mvn exec:java
curl --compressed -v -o - http://localhost:8080/myapp/myresource
でテスト
スタート
結果は以下である:
> GET /myapp/myresource HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 zlib/1.2.3.4 ...
> Host: localhost:8080
> Accept: */*
> Accept-Encoding: deflate, gzip
>
< HTTP/1.1 200 OK
< Content-Type: text/plain
< Date: Sun, 03 Nov 2013 08:07:10 GMT
< Content-Length: 7
<
* Connection #0 to host localhost left intact
* Closing connection #0
Got it!
つまり、リクエストにAccept-Encoding: deflate, gzip
がありますが、応答にはContent-Encoding: gzip
はありません。
私はここで何が欠けていますか?あなたにもorg.glassfish.jersey.server.filter.EncodingFilter
を登録する必要が
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(
BASE_URI, rc, false);
CompressionConfig compressionConfig =
httpServer.getListener("grizzly").getCompressionConfig();
compressionConfig.setCompressionMode(CompressionConfig.CompressionMode.ON); // the mode
compressionConfig.setCompressionMinSize(1); // the min amount of bytes to compress
compressionConfig.setCompressableMimeTypes("text/plain", "text/html"); // the mime types to compress
httpServer.start();
このトリックを行うようです。私はGrizzly 2.2.3の考えであったので、私は 'CompressConfig'を持っていませんでしたが、対応するメソッドは' NetworkListener'で利用できました。ありがとう! – aioobe
はい、pls。 Grizzly 2.3.5以降を使用する – alexey