XFire webservice 服务端开发(二)

web service 传数据如果较大,可能会引发性能问题。所以我们可以采用filter去压缩,这与web service本身没有太大关系。
在上一章已经加入包了,只需要在web.xml加入
 

    <filter>
        <filter-name>CompressingFilter</filter-name>
        <filter-class>com.planetj.servlet.filter.compression.CompressingFilter</filter-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>false</param-value>
        </init-param>
        <init-param>
            <param-name>statsEnabled</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>CompressingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

注意,上面配置在<url-pattern>/*</url-pattern>是所有的都进行了压缩包括web容器中的内容,如果只需要对webservice进行压缩,可以进行目录分类。statsEnabled设置为true以后,可以统计压缩信息。

%@ page import="com.planetj.servlet.filter.compression.*" %>
<html>
<head>
<title>WAR Status</title>
</head>
<body>

<%
CompressingFilterStats stats = (CompressingFilterStats)application.getAttribute(CompressingFilterStats.STATS_KEY);
%>

<h4>GZIP Servlet Statistics. CompressingFilter</h4>
<table border="1">
    <tr>
        <td>resp num compressed</td>
        <td><%= stats.getNumResponsesCompressed() %></td>
    </tr>
    <tr>
        <td>resp num not compressed</td>
        <td><%= stats.getTotalResponsesNotCompressed() %></td>
    </tr>
    <tr>
        <td>resp input bytes</td>
        <td><%= stats.getResponseInputBytes() %></td>
    </tr>
    <tr>
        <td>resp compressed out bytes</td>
        <td><%= stats.getResponseCompressedBytes() %></td>
    </tr>
    <tr>
        <td>resp mean compression ratio</td>
        <td><%= stats.getResponseAverageCompressionRatio() %></td>
    </tr>
    <tr>
        <td>req num compressed</td>
        <td><%= stats.getNumRequestsCompressed() %></td>
    </tr>
    <tr>
        <td>req num not compressed</td>
        <td><%= stats.getTotalRequestsNotCompressed() %></td>
    </tr>
    <tr>
        <td>req input bytes</td>
        <td><%= stats.getRequestInputBytes() %></td>
    </tr>
    <tr>
        <td>req compressed out bytes</td>
        <td><%= stats.getRequestCompressedBytes() %></td>
    </tr>
    <tr>
        <td>req mean compression ratio</td>
        <td><%= stats.getRequestAverageCompressionRatio() %></td>
    </tr>
</table>
</body>
</html>

posted on 2008-09-20 22:06  八哥  阅读(723)  评论(0编辑  收藏  举报

导航