views:

429

answers:

3

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/"&gt;
   <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"&gt;12345&lt;/ns2:column&gt;
               <ns2:column xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;XYZ&lt;/ns2:column&gt;
               <ns2:column xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/&gt;
               <ns2:column xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;ABC&lt;/ns2:column&gt;
            </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"&gt;32345&lt;/ns2:column&gt;
               <ns2:column xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;OPC&lt;/ns2:column&gt;
               <ns2:column xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/&gt;
               <ns2:column xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;QWE&lt;/ns2:column&gt;
            </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"&gt;
   <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>

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?

+3  A: 

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.

Jon Skeet
yes, we are considering this. On the server side there is an apache so mod_deflate should do the job ... but the .NET client needs to be able to deal with the compressed response.
Thomas Einwaller
A: 

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.

The MYYN
+1  A: 

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.

skaffman
we have a .NET client that needs to deal with the response ... could this be done with Fast Infoset?
Thomas Einwaller
FastInfoset is a microsoft invention, so that shouldn't be a problem.
skaffman