<< 使用 Spring 2.5 基于注解驱动的 Spring MVC | 首页 | 在 xfire中使用 GZip来 压缩 传输量 - secyaher的日志 - 网易博客 >>

How to Use SOAP Compression with Apache Axis 1.X

Configuring the Server

The configuration of the client and the server are independent. First, you can set up and test the server. After the server configuration is working you can move on to the client side.

We will use a Servlet filter to decompress the requests and compress the responses. Although a lot of other filters can only compress the response, our free filter can both compress the response and decompress the request. To use the filter for SOAP compression, it has to be added to the Axis Web application containing the Web Services. The filter is packaged into the library 2wayfilter-1.2.jar. Download the library and copy it into the Axis Web application's lib folder.

Now, you can configure the Web application to use the filter. Include the following filter and filter-mapping elements in the Web application's deployment descriptor. The deployment descriptor is in the file web.xml in the folder WEB-INF.

<web-app>     ...     <filter>         <filter-name>2WayFilter</filter-name>         <filter-class>com.osmoticweb.gzipfilter.GZIP2WayFilter</filter-class>     </filter>     <filter-mapping>         <filter-name>2WayFilter</filter-name>         <url-pattern>/*</url-pattern>     </filter-mapping>     ... </web-app> 

Configuring the Client

To use the compression feature of the server, the client must be able to compress requests and decompress responses. Apache Axis can be extended with the SOAP compression transport sender which supports compression and decompression of SOAP messages. The extension can be installed without recompiling or modifying Axis itself.

Download the library soap-compression-1.2.jar containing the extension and place it into the classpath of the Axis client. The library contains the classcom.osmoticweb.soapcompression.CompressionHTTPSender which can be used instead of the built-in sender. To instruct the Axis client to use the new class a client side deployment descriptor is necessary. Create a file named client-config.wsdd, with the following content, and place it in the directory where the Axis client is started. See the Axis WSDD Reference for more details about the deployment descriptor.

The compression sender is compatible with Axis 1.1 or newer. The configuration is different depending on which version of Axis is used. The difference lies in how parameters are declared in the file client-config.wsdd. Use the corresponding configuration for your Axis version. For details see the SOAP compression sender description.

Axis 1.2 Beta or Newer

       
<?xml version="1.0" encoding="UTF-8"?>
<deployment name="defaultClientConfig"
            xmlns="http://xml.apache.org/axis/wsdd/"
            xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

    <transport name="http" pivot="java:com.osmoticweb.soapcompression.CompressionHTTPSender">          <parameter name="compressRequest" value="true"/>          <parameter name="acceptEncodingHeader" value="true"/>      </transport>

    <transport name="local" pivot="java:org.apache.axis.transport.local.LocalSender"/>
    <transport name="java" pivot="java:org.apache.axis.transport.java.JavaSender"/>
 
</deployment>

Axis 1.1

<?xml version="1.0" encoding="UTF-8"?>
<deployment name="defaultClientConfig"
            xmlns="http://xml.apache.org/axis/wsdd/"
            xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

    <transport name="http" pivot="java:com.osmoticweb.soapcompression.CompressionHTTPSender">         <requestFlow>              <handler type="java:com.osmoticweb.soapcompression.PutOptionsHandler">                  <parameter name="compressRequest" value="true"/>                  <parameter name="acceptEncodingHeader" value="true"/>              </handler>          </requestFlow>     </transport>

    <transport name="local" pivot="java:org.apache.axis.transport.local.LocalSender"/>
    <transport name="java" pivot="java:org.apache.axis.transport.java.JavaSender"/>
  
</deployment>

java org.apache.axis.utils.tcpmon

After starting tcpmon, a new session can be added to intercept our calls. For the test, we will use listen port 2000. The session will act as a listener for the target host 127.0.0.1 on target port8080. See the screenshot below.

Now the test page can be requested from a Web browser that supports HTTP compression, for example, Mozilla, Firefox and Microsoft Internet Explorer.

 

阅读全文……

标签 :



发表评论 发送引用通报