2016-10-25 10 views
0

REST APIでgzipフィルタを使用するにはどうすればよいですか? また、実装を1か所にまとめたいとします。 20種類のAPIの中から設定する方法はありますか?それを使用するAPIはほんのわずかです。gzip REST APIでの実装

すべてのドキュメントが参考になります。

+0

質問を明確にしてください。私は本当にあなたが何を意味するか分からない。 –

+0

@CássioMazzochiMolin:編集中。あなたの疑問を明確にしたら教えてください –

+0

あなたはこれまでに試したことを見せていただけますか? –

答えて

0

それは、WriterInterceptorで達成することができます

public class GZIPWriterInterceptor implements WriterInterceptor { 

    @Override 
    public void aroundWriteTo(WriterInterceptorContext context) 
       throws IOException, WebApplicationException { 
     final OutputStream outputStream = context.getOutputStream(); 
     context.setOutputStream(new GZIPOutputStream(outputStream)); 
     context.proceed(); 
    } 
} 

次に、あなたのResourceConfig/ApplicationサブクラスでWriterInterceptorを登録:特定のリソースメソッドやクラスにインターセプターをバインドするには

@ApplicationPath("/api") 
public class MyApplication extends ResourceConfig { 

    public MyApplication() { 
     register(GZIPWriterInterceptor.class); 
    } 
} 

、あなたは可能性がありname binding annotationsを使用してください。

詳細については、Jersey documentation about filters and interceptorsをご確認ください。

+0

郵便配達側のクライアント側で何かするのですか? –

+0

それは動作します。応答にヘッダーを追加する必要があるかもしれませんが –

関連する問題