日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

cxf添加拦截器_在CXF API和拦截器中添加Gzip压缩

發布時間:2023/12/3 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 cxf添加拦截器_在CXF API和拦截器中添加Gzip压缩 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

cxf添加攔截器

如今,由于我們在響應中發送大量數據,因此必須對API響應執行Gziping。 它節省了網絡帶寬和交付時間,當然還節省了Internet上的空間。

CXF提供了以多種方式使用Gzip壓縮的選項。

  • 藍圖
  • 注解


  • 藍圖:

    <bean id="gZipInterceptor" class="org.apache.cxf.transport.common.gzip.GZIPOutInterceptor" /><jaxrs:server id="rsServer" address="/gZip"><jaxrs:outInterceptors><ref component-id="gZipInterceptor" /></jaxrs:outInterceptors></jaxrs:server>

    注解:

    首先,您需要在out攔截器列表中注冊GZIPOutInterceptor 。 為此,您需要加入CXF初始化類。

    public class InterceptorManager extends AbstractFeature {private static final Logger LOGGER = Logger.getLogger( "simcore" );private static final Interceptor< Message > GZIP = new GZIPOutInterceptor();//private static final Interceptor< Message > GZIP = new GZIPOutInterceptor(512);/* (non-Javadoc)* @see org.apache.cxf.feature.AbstractFeature#initializeProvider(org.apache.cxf.interceptor.InterceptorProvider, org.apache.cxf.Bus)*/@Overrideprotected void initializeProvider( InterceptorProvider provider, Bus bus ) {/*** Adding Gzip interceptor to all outbound requests/responses*/LOGGER.debug( " ############## Adding Gzip as OUT Interceptor ##############" );provider.getOutInterceptors().add( GZIP );} }

    GZIPOutInterceptor帶有一個選項,用于將閾值設置為字節數。 如果響應大小低于此閾值,則將不會對其進行壓縮。 當我們僅發送空列表和狀態消息/代碼時,這將非常有用,因為壓縮這些小的響應將在服務器端增加開銷。

    但是,我們還必須考慮另一個因素,即請求響應的用戶數量。 因此,請考慮可能出現的所有情況,以適當地設置此值。

    @GZIP

    現在,我們可以在任何Web服務控制器上使用此批注,以對該類中提供的所有API實施壓縮。

    @WebService @Consumes ( { MediaType.TEXT_PLAIN, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @Produces ( MediaType.APPLICATION_JSON ) @GZIP public interface WebServicesController {@GET@Path ( "/myGzipData" )@Produces ( { MediaType.APPLICATION_JSON } )Response getZipData( );}

    此外,我們可以在Gzip注釋中設置不同的參數。

    @GZIP ( force = true, threshold = 512 )

    翻譯自: https://www.javacodegeeks.com/2014/11/adding-gzip-compression-in-cxf-apis-and-interceptors.html

    cxf添加攔截器

    總結

    以上是生活随笔為你收集整理的cxf添加拦截器_在CXF API和拦截器中添加Gzip压缩的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。