ws-soap-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scott Nichol" <>
Subject Re: Compressing response
Date Wed, 15 Sep 2004 13:14:28 GMT
The line of code

    resCtx = new SOAPContext(); // get rid of old one

from RPCRouterServlet, only runs when an exception is thrown.

The code that runs is something like this


        provider.locate( dd, callEnv, call, call.getMethodName(), fullTargetID, 
                         reqCtx );
        ServerUtils.setResponseGzip(dd, reqCtx, resCtx);


        if (Boolean.TRUE.equals(reqCtx.getAcceptGzip())) {
          // Request specified gzip OK
          Hashtable props = dd.getProps();
          String gzip = props != null ? (String) props.get("gzip") : null;
          resCtx.setGzip(gzip != null && SoapEncUtils.decodeBooleanValue(gzip));
        } else if (Boolean.FALSE.equals(reqCtx.getAcceptGzip())) {
          // Request specified gzip not OK
        } else {
          // Request specified nothing, for now do not gzip
          // TODO: should accept be required?


        provider.invoke( reqCtx, resCtx );


        Response resp = RPCRouter.invoke( dd, call, targetObject, 
                                          reqContext, resContext );


    return new Response (call.getTargetObjectURI (), call.getMethodName (),
                         ret, null, null, respEncStyle, resCtx);


        Envelope env = resp.buildEnvelope();
        StringWriter  sw = new StringWriter(1024);
        env.marshall( sw, call.getSOAPMappingRegistry(), resContext );
        resContext.setRootPart( sw.toString(), Constants.HEADERVAL_CONTENT_TYPE_UTF8);


      // Generate response.
      TransportMessage sres = new TransportMessage(null, resCtx, null );

      // Generate response byte array.;


        if (Boolean.TRUE.equals(ctx.getGzip())) {
            // Deflate
            ByteArrayOutputStream baos =
                               new ByteArrayOutputStream(bytes.length);
            GZIPOutputStream gzos = new GZIPOutputStream(baos);
            gzos.write(bytes, offset, bytes.length - offset);
            bytes = baos.toByteArray();
            offset = 0;

            headers.put(Constants.HEADER_CONTENT_ENCODING, Constants.HEADERVAL_CONTENT_ENCODING);


      // Write.
      for (Enumeration headers = sres.getHeaderNames();
           headers.hasMoreElements(); ) {
          String name = (String)headers.nextElement();
          res.setHeader(name, sres.getHeader(name));

      OutputStream outStream = res.getOutputStream();

In order to have your service gzip the result, the client must specify that it accepts gzip,
and the deployment descriptor must have the option set to allow gzip.  Remember that when
you change the deployment descriptor, you must re-deploy the service.

Scott Nichol

Do not send e-mail directly to this e-mail address,
because it is filtered to accept only mail from
specific mail lists.
----- Original Message ----- 
From: "Michał Małecki" <>
To: <>
Sent: Monday, September 13, 2004 9:32 AM
Subject: Compressing response

> Hello,
> I'm trying to compress SOAP messages (second day). The SOAP from client to
> server was archived with no problems. However, soap from server to client is
> still plain-text. I have added option "gzip", I have disabled Norton
> firewall (killed accepted-encoding header). I searched the source code
> (ws-soap_20040912104811) and I can't find out how ever the compression could
> be archived - the outputStream is gzipped if SOAPSontext.getGzip return
> true, but TransportMessage is created like this:
> new TransportMessage(null, resCtx, null );
> and resCtx is created few lines before:
> resCtx = new SOAPContext(); // get rid of old one
> so where the gzip of soapcontext could be set?
> I beg you - please tell me how to archive this??
> Michał Małecki

View raw message