在我们的web服务的性能测试中,我们发现响应产生的流量远远超出了我们的期望。我们正在查询数据库并加载由行和列组成的列表。
列的类型是AnyType,因此响应中需要有类型信息。为此,web服务引擎(Axis2或JAXWS)多次添加大量命名空间信息。请参见以下示例响应:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <ns3:loadListResponse xmlns:ns3="http://example.com/test/service-types-1.0" 
      xmlns:ns2="http://example.com/lists/lists-types-1.0" >
         <ns3:value>
            <ns2:row>
               <ns2:column xsi:type="xs:int" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">12345</ns2:column>
               <ns2:column xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">XYZ</ns2:column>
               <ns2:column xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
               <ns2:column xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">ABC</ns2:column>
            </ns2:row>
            <ns2:row>
               <ns2:column xsi:type="xs:int" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">32345</ns2:column>
               <ns2:column xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">OPC</ns2:column>
               <ns2:column xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
               <ns2:column xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">QWE</ns2:column>
            </ns2:row>
             .
             .
             .
         </ns3:value>
      </ns3:loadListResponse>
   </soapenv:Body>
</soapenv:Envelope>我希望通过在顶部添加所需的名称空间并从每一列中删除它们(通常每一行大约有30列)来优化这个XML响应。结果应该如下所示:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <soapenv:Body>
      <ns3:loadListResponse xmlns:ns3="http://example.com/test/service-types-1.0" 
      xmlns:ns2="http://example.com/lists/lists-types-1.0" >
         <ns3:value>
            <ns2:row>
               <ns2:column xsi:type="xs:int" >12345</ns2:column>
               <ns2:column xsi:type="xs:string" >XYZ</ns2:column>
               <ns2:column xsi:nil="true" />
               <ns2:column xsi:type="xs:string" >ABC</ns2:column>
            </ns2:row>
            <ns2:row>
               <ns2:column xsi:type="xs:int" >32345</ns2:column>
               <ns2:column xsi:type="xs:string" >OPC</ns2:column>
               <ns2:column xsi:nil="true" />
               <ns2:column xsi:type="xs:string" >QWE</ns2:column>
            </ns2:row>
             .
             .
             .
         </ns3:value>
      </ns3:loadListResponse>
   </soapenv:Body>
</soapenv:Envelope>你会怎么做那样的事?
有没有办法告诉Axis2或JAXWS这样做?
还是需要手动操作生成的XML?
发布于 2009-12-21 09:57:42
您是否考虑过尝试以适当透明的方式压缩响应?这可能更容易做,并将非常有效的所有这些重复的数据。
发布于 2009-12-21 10:06:32
如果您对web服务的传输和/或处理效率有顾虑,则应考虑启用快速Infoset。
Fast Infoset (或FI)是一种国际标准,它指定XML信息集(XML )的二进制编码格式作为XML文档格式的替代。它旨在提供比基于文本的XML格式更高效的序列化。 可以将FI看作XML的gzip,尽管FI的目标是优化文档大小和处理性能,而gzip只对文档大小进行优化。
它对高容量web服务的影响是巨大的,我现在在可能的情况下把它作为理所当然的事情来使用。
Axis2和贾克斯-WS都支持它。
发布于 2009-12-21 09:59:54
轴1.x的servlet压缩过滤器示例。
本指南解释了如何在Apache中使用SOAP压缩。请求和响应消息都被压缩。为了压缩和解压缩客户端的SOAP消息,使用了一个用于gzip的Axis扩展。服务器端的对应方是一个Servlet过滤器。
https://stackoverflow.com/questions/1939200
复制相似问题