明確化:この質問は JAX-WS ベースの REST サービスの GZIPping に関するものでしたが、見つけやすくするためにトピックを変更することにしました
JAX-WS 経由で REST サービスを実装しProvider <Source>
、標準で公開していますEndpoint
(理由は、サーブレット コンテナーまたはアプリケーション サーバーの使用を避けたいためです)。
存在する場合、サーバーを gzip 応答コンテンツにする方法はありAccept-Encoding: gzip
ますか?
方法
によって提供されるサンプルはnicore
実際に機能し、サーブレット コンテナーを使用せずに組み込みの軽量サーバー上に JAX-RS スタイルのサーバーを作成できますが、考慮すべき点がほとんどありません。
自分でクラスを管理したい (そして起動時の時間を節約したい) 場合は、次を使用できます。
例
JAX-RS ハローワールドクラス:
@Path("/helloworld")
public class RestServer {
@GET
@Produces("text/html")
public String getMessage(){
System.out.println("sayHello()");
return "Hello, world!";
}
}
主な方法:
シンプルなサーバーの場合:
public static void main(String[] args) throws Exception{
DefaultResourceConfig resourceConfig = new DefaultResourceConfig(RestServer.class);
// The following line is to enable GZIP when client accepts it
resourceConfig.getContainerResponseFilters().add(new GZIPContentEncodingFilter());
Closeable server = SimpleServerFactory.create("http://0.0.0.0:5555", resourceConfig);
try {
System.out.println("Press any key to stop the service...");
System.in.read();
} finally {
server.close();
}
}
Grizzly2の場合:
public static void main(String[] args) throws Exception{
DefaultResourceConfig resourceConfig = new DefaultResourceConfig(RestServer.class);
// The following line is to enable GZIP when client accepts it
resourceConfig.getContainerResponseFilters().add(new GZIPContentEncodingFilter());
HttpServer server = GrizzlyServerFactory.createHttpServer("http://0.0.0.0:5555" , resourceConfig);
try {
System.out.println("Press any key to stop the service...");
System.in.read();
} finally {
server.stop();
}
}
解決された依存関係:
単純:
グリズリー:
- グリズリーフレームワーク
- グリズリー http
- grizzly-http-server (別のリポジトリ!)
- ジャージ-グリズリー2
ジャージー:
知らせ
javax.ws.rs
Jersey の実装と競合するため、アーカイブがクラスパスに入っていないことを確認してください。ここで最悪なのは、ログなしのサイレント 404 エラーFINER
です。レベルに関する小さなメモのみがログに記録されます。