2014-05-12 113 views
0

首先,我看到一些例子,說明如何在澤西島上使用GZIP壓縮。澤西+ GZIP編碼

雖然,我看到的是沒有參加,因爲I'm使用澤西1.6和新澤西急劇變化,從1.9到2.0,我正在開發的系統的需求。除此之外,我看到的所有完整例子都在Jersey 2.0中。

在1.9或更低的搜索範圍內搜索完整的示例,我發現配置文件位於web.xml

<init-param> 
    <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name> 
    <param-value>com.sun.jersey.api.container.filter.GZIPContentEncodingFilter</param-value> 
</init-param> 
<init-param> 
    <param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name> 
    <param-value>com.sun.jersey.api.container.filter.GZIPContentEncodingFilter</param-value> 
</init-param> 

我認爲我必須做更多的事情,讓GZIP壓縮。 注意:我也配置了一個歡迎文件。

編輯:這是我的完整web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    version="2.5"> 
    <display-name>app</display-name> 
    <servlet> 
     <servlet-name>app-servlet</servlet-name> 
     <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> 
     <init-param> 
      <param-name>com.sun.jersey.config.property.packages</param-name> 
      <param-value>com.app.controllers</param-value> 
     </init-param> 
     <init-param> 
      <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name> 
      <param-value>true</param-value> 
     </init-param> 
     <init-param> 
      <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name> 
      <param-value>com.sun.jersey.api.container.filter.GZIPContentEncodingFilter</param-value> 
     </init-param> 
     <init-param> 
      <param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name> 
      <param-value>com.sun.jersey.api.container.filter.GZIPContentEncodingFilter</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>app-servlet</servlet-name> 
     <url-pattern>/service/*</url-pattern> 
    </servlet-mapping> 
    <welcome-file-list> 
     <welcome-file>hotel-application.html</welcome-file> 
    </welcome-file-list> 

    <!-- BEGIN Spring Security Config --> 
    <listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 
<servlet> 
     <servlet-name>dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
     <servlet-name>dispatcher</servlet-name> 
     <url-pattern>/login/*</url-pattern> 
</servlet-mapping> 
    <filter> 
     <filter-name>springSecurityFilterChain</filter-name> 
     <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 
<!-- END Spring Security Config --> 

回答

0

你怎麼測試你的servlet?標題中必須有Accept-Encoding:gzip。如果您在瀏覽器中測試您的Web服務,瀏覽器可能會解壓縮所有內容並顯示給您。試試這個:curl -H Accept-Encoding:gzip -i -u user:pass http://your/web/service