开发者

Optimizing XML response of web service

In performance tests of our web service we found out that the traffic generated by the response exceeded our expectations a lot. We are querying the database and loading lists consisting of rows and columns.

The type of the column is AnyType so the in the response there needs to be a type information. Therefor the web service engine (Axis2 or JAXWS) adds a lot of namespace information multiple times. See the following example response:

<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>

I would like to optimize this XML response by adding the required namespaces at the top and removing them from every column (usually there are about 30 columns per line). The result should look like this:

<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 开发者_如何学JAVAxsi: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>

How would you do something like that?

Is there a way to tell Axis2 or JAXWS to do so?

Or do I need to manipulate the generated XML manually?


Have you considered trying to compress the response instead in an appropriately transparent way? That may be easier to do, and would be very effective with all that repeated data.


If you have concerns about the transport and/or processing efficiency of your web service, you should consider enabling Fast Infoset:

Fast Infoset (or FI) is an international standard that specifies a binary encoding format for the XML Information Set (XML Infoset) as an alternative to the XML document format. It aims to provide more efficient serialization than the text-based XML format.

One can think of FI as gzip for XML, though FI aims to optimize both document size and processing performance, whereas gzip optimizes only the size.

Its effect on high volume web services is dramatic, and I now use it as a matter of course, where possible.

It is supported by both Axis2 and JAX-WS.


Example of a servlet compression filter for AXIS 1.x.

This guide explains how to use SOAP compression with Apache Axis. Both request and response messages are compressed. To compress and decompress SOAP messages on the client side, an Axis extension for gzip is used. The counterpart on the server side is a Servlet filter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜