不锈钢网站样板,html教程下载,比较好的网站建设平台,Wordpress博客怎么盈利cxf添加拦截器如今#xff0c;由于我们在响应中发送大量数据#xff0c;因此必须对API响应执行Gziping。 它节省了网络带宽和交付时间#xff0c;当然还节省了Internet上的空间。 CXF提供了以多种方式使用Gzip压缩的选项。 蓝图 注解 蓝图#xff1a; bean id由于我们在响应中发送大量数据因此必须对API响应执行Gziping。 它节省了网络带宽和交付时间当然还节省了Internet上的空间。 CXF提供了以多种方式使用Gzip压缩的选项。 蓝图 注解 蓝图 bean idgZipInterceptor classorg.apache.cxf.transport.common.gzip.GZIPOutInterceptor /jaxrs:server idrsServer address/gZipjaxrs:outInterceptorsref component-idgZipInterceptor //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 {GETPath ( /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.htmlcxf添加拦截器