欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

ApacheCXF中如何壓縮WebService數(shù)據(jù)

這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)Apache CXF中如何壓縮Web Service數(shù)據(jù),文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

創(chuàng)新互聯(lián)專注于瑞金企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,商城網(wǎng)站制作。瑞金網(wǎng)站建設(shè)公司,為瑞金等地區(qū)提供建站服務(wù)。全流程按需網(wǎng)站策劃,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)

在現(xiàn)實(shí)應(yīng)用中有些時(shí)候會(huì)有比較大的數(shù)據(jù)對(duì)象需要傳輸,或者在一個(gè)比較慢的網(wǎng)絡(luò)環(huán)境下發(fā)布調(diào)用web service,此時(shí)可以通過(guò)壓縮數(shù)據(jù)流的方式來(lái)減小數(shù)據(jù)包的大小,從而提高web service的性能。下面來(lái)看看怎樣來(lái)做到這一點(diǎn)。

1. 首先模擬一個(gè)可以存放大數(shù)據(jù)的pojo對(duì)象,這個(gè)對(duì)象可以通過(guò)構(gòu)造參數(shù)給定的size來(lái)模擬一個(gè)size大小的字符串。

package com.googlecode.garbagecan.cxfstudy.compress;    public class BigData {            private String name;            private String data;            public BigData() {                }            public BigData(String name, int size) {          this.name = name;          StringBuilder sb = new StringBuilder();          for (int i = 0; i < size; i++) {              sb.append("0");          }          this.data = sb.toString();      }       public String getName() {          return name;      }       public void setName(String name) {          this.name = name;      }       public String getData() {          return data;      }       public void setData(String data) {          this.data = data;      }  }

2. Web Service接口類,和普通的接口定義沒(méi)有什么區(qū)別。

package com.googlecode.garbagecan.cxfstudy.compress;   import javax.jws.WebMethod;  import javax.jws.WebParam;  import javax.jws.WebResult;  import javax.jws.WebService;   @WebService public interface BigDataService {            @WebMethod     @WebResult BigData getBigData(@WebParam String name, @WebParam int size);  }

3. Web Service實(shí)現(xiàn)類

package com.googlecode.garbagecan.cxfstudy.compress;   public class BigDataServiceImpl implements BigDataService {      public BigData getBigData(String name, int size) {          BigData bigData = new BigData(name, size);          return bigData;      }  }

4. 測(cè)試類,這片文章使用了JUnit測(cè)試類來(lái)做測(cè)試。setUpBeforeClass方法用來(lái)啟動(dòng)Service, testGetBigData方法用來(lái)測(cè)試web service。

注意setUpBeforeClass方法中的

factoryBean.getInInterceptors().add(new GZIPInInterceptor());

factoryBean.getOutInterceptors().add(new GZIPOutInterceptor());

和testGetBigData方法中的

endpoint.getInInterceptors().add(new GZIPInInterceptor());

endpoint.getOutInterceptors().add(new GZIPOutInterceptor());

上面兩段代碼就是告訴CXF使用壓縮Interceptor來(lái)壓縮和解壓縮數(shù)據(jù)包。

package com.googlecode.garbagecan.cxfstudy.compress;   import org.apache.cxf.endpoint.Client;  import org.apache.cxf.endpoint.Endpoint;  import org.apache.cxf.frontend.ClientProxy;  import org.apache.cxf.interceptor.LoggingInInterceptor;  import org.apache.cxf.interceptor.LoggingOutInterceptor;  import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;  import org.apache.cxf.jaxws.JaxWsServerFactoryBean;  import org.apache.cxf.transport.http.gzip.GZIPInInterceptor;  import org.apache.cxf.transport.http.gzip.GZIPOutInterceptor;  import org.junit.Assert;  import org.junit.BeforeClass;  import org.junit.Test;   public class BigDataServiceTest {       private static final String address = "http://localhost:9000/ws/compress/bigDataService";            @BeforeClass     public static void setUpBeforeClass() throws Exception {          JaxWsServerFactoryBean factoryBean = new JaxWsServerFactoryBean();          factoryBean.getInInterceptors().add(new LoggingInInterceptor());          factoryBean.getOutInterceptors().add(new LoggingOutInterceptor());          factoryBean.getInInterceptors().add(new GZIPInInterceptor());          factoryBean.getOutInterceptors().add(new GZIPOutInterceptor());                    factoryBean.setServiceClass(BigDataServiceImpl.class);          factoryBean.setAddress(address);          factoryBean.create();      }       @Test     public void testGetBigData() {          JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();          factoryBean.setAddress(address);          factoryBean.setServiceClass(BigDataService.class);          Object obj = factoryBean.create();                    Client client = ClientProxy.getClient(obj);          Endpoint endpoint = client.getEndpoint();          endpoint.getInInterceptors().add(new GZIPInInterceptor());          endpoint.getOutInterceptors().add(new GZIPOutInterceptor());                    BigDataService service = (BigDataService) obj;          Assert.assertNotNull(service);                    String name = "my big data";          int size = 1024 * 1024 * 10;                    long start = System.currentTimeMillis();          BigData bigData = service.getBigData(name, size);          long stop = System.currentTimeMillis();          System.out.println("Time: " + (stop - start));                    Assert.assertNotNull(bigData);          Assert.assertEquals(name, bigData.getName());          Assert.assertEquals(size, bigData.getData().length());      }  }

5. 運(yùn)行此unit test,可以在日志中看到數(shù)據(jù)包前后大小和內(nèi)容。

上述就是小編為大家分享的Apache CXF中如何壓縮Web Service數(shù)據(jù)了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

當(dāng)前文章:ApacheCXF中如何壓縮WebService數(shù)據(jù)
分享鏈接:http://aaarwkj.com/article12/pcsddc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、靜態(tài)網(wǎng)站、服務(wù)器托管、網(wǎng)頁(yè)設(shè)計(jì)公司、網(wǎng)站改版標(biāo)簽優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

微信小程序開(kāi)發(fā)
天堂av免费资源在线观看| 欧美日韩精品偷拍一区二区| av中文字幕一区二区三区| 内射久久一区二区亚洲| 欧美香蕉视频一区二区| av天堂男人站在线观看| 国产午夜精品一区二区三区| 国产一区二区日韩一区| 日本黄色高清视频一区| 亚洲综合中文字幕久久网址| av中文字幕亚洲一区二区| 亚洲国产中文日韩欧美在线| 精品人妻一区二区三区蜜桃视频| 国产在线视频不卡福利片| 日韩a国产v亚洲欧美精品| 综合久久—本道中文字幕| 激情av一区二区不卡| 午夜少妇诱惑一区二区三区| 亚洲成人午夜激情的三级网| 国产又大又长又粗又硬又猛| 欧美人与性一区二区三区| 欧美aⅴ精品一区二区三区| 很黄无遮挡在线免费网站| 精品国产一区二区三区四不卡在线| 尤物资源视频在线观看| 日本女优久久精品观看| 免费观看中国性生活片| 国产区一区二区三在线播放| 一区二区先锋深夜中文字幕| 亚洲激情久热中文字幕| 97国产成人精品视频免费| 青青草免费视频观看在线| 精品久久亚洲一区二区欧美| 青青草手机在线视频免费观看| 欧美伊人久久综合成人网| 亚洲国产a级一区二区| 亚洲精品午夜久久久伊人| 最新人妻少妇精品中文字幕视频| 日韩精品欧美视频久久| 国产999精品在线观看| 亚洲成年人黄色小说网站|