Uploaded image for project: 'Axis2'
  1. Axis2
  2. AXIS2-5052

Unable to send compressed message!!

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.5.4
    • Fix Version/s: 1.8.0
    • Component/s: client-api
    • Labels:
    • Environment:
      Windows xp,

      Description

      Hi,

      I have two webservices deployed on two different servers. (service1 and service2)
      From my client program I have enabled the GZIP format on the request for the serviceClient.

      When I make a call to the service1, the message is compressed and sent to the server and everything looks good.

      After some time I made a call to the service2 and the request xml is sent in compressed format and looks fine.

      But Now if I sent the message to the service1, it is in clear text and not using the compressed format.

      Am I missing any options on the ServiceClient. Please let me know if you have faced this problem.

      Here is the code I am using:
      &a! mp;n! bsp; HttpMethodRetryHandler retry_handler = new DefaultHttpMethodRetryHandler(0, false);
      HttpClientParams params = new HttpClientParams();
      params.setParameter(HttpMethodParams.RETRY_HANDLER, retry_handler);
      options.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, new org.apache.commons.httpclient.HttpClient(params, manager));
      options.setProperty(HTTPConstants.MC_GZIP_REQUEST, true);
      options.setProperty(HTTPConstants.MC_ACCEPT_GZIP, true);
      options.setProperty(HTTPConstants.MC_GZIP_RESPONSE, true);
      &! nbsp;! options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, true);

      options.setTimeOutInMilliSeconds(wsTimeOutInMilliSeconds);
      options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, wsTimeOutInMilliSeconds);
      options.setCallTransportCleanup(true);

      Any help is greatly appreciated.
      Thanks
      Anil.

      After debugging the source code I Have found that in AxisRequestEntity.java at line # 80, the condition is also looking for CHUNKED flag. Is this a must if you want to enable gzip on request?
      if (gzip != null && JavaUtils.isTrueExplicitly(gzip) && chunked)

      { outStream = new GZIPOutputStream(outStream); }

      I have another question:
      THis is the code where I create an instance of the sub.

      SERVICE 1

          /**
           * Returns (new or existing) reference to Web Service TransactionManager.
           * @return TransactionManager
           */
          public TransactionManagerStub getTransactionManagerStub(TransactionManagerStub stub, boolean retry, boolean compressMessage) throws Exception
          {
              if (stub == null)
              {
                  try
                  {
                      String url      = Gateway.getProperty("application", "TransactionWSUrl", "");
                      String user     = Gateway.getProperty("application", "WebserviceUser", "");
                      String password = Gateway.getProperty("application", "WebservicePasswd", "");
                      int wsTimeOutInMilliSeconds = Integer.parseInt(Gateway.getProperty("application", "wsTimeOutInMilliSeconds", ""));
      
                      if (logger.isDebugEnabled())
                          logger.debug(url);
                      stub = new TransactionManagerStub(url);
      
                      ServiceClient sc = stub._getServiceClient();
                      sc.cleanup();
                      // Set security options
                      org.apache.axis2.client.Options options = sc.getOptions();
                      options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, loadPolicy(AXIS2_RAMPART_POLICY));
                      MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
                      if(!retry)
                      {
          	            //This logic will turn off retry attempts. By default Axis2 will retry for 3 attempts which
          	            // results in sending the same message for three times and the application will throw duplicate key exceptions.
                          HttpMethodRetryHandler retry_handler = new DefaultHttpMethodRetryHandler(0, false);
                          HttpClientParams params = new HttpClientParams();
                          params.setParameter(HttpMethodParams.RETRY_HANDLER, retry_handler);
                          options.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, new org.apache.commons.httpclient.HttpClient(params, manager));
                      } 
                      else
                      {
                          options.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, new org.apache.commons.httpclient.HttpClient(manager));
                      }
                      if(compressMessage)
                      {
                      	options.setProperty(HTTPConstants.MC_GZIP_REQUEST, true);
                      	options.setProperty(HTTPConstants.CHUNKED, true);
                      }
                      options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, true);
                      options.setTimeOutInMilliSeconds(wsTimeOutInMilliSeconds);
                      options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, wsTimeOutInMilliSeconds);
                      options.setCallTransportCleanup(true);
                      options.setUserName(user);
                      StringEncryptionUtility util = new StringEncryptionUtility();
                      char[] pwd = util.getCSFPassword(password);
                      options.setPassword(new String(pwd));
                      Util.flushCharArray(pwd);
                      sc.setOptions(options);
                      // Enable axis2 security module
                      sc.engageModule(AXIS2_SECURITY_MODULE);
                      stub._setServiceClient(sc);
                  }
                  catch (Exception t)
                  {
                      t.printStackTrace();
                      logger.error(t);
                      throw t;
                  }
              }
              
              ServiceClient sc = stub._getServiceClient();
      //        // Set security options
              org.apache.axis2.client.Options options = sc.getOptions();
              if(compressMessage)
              {
              	options.setProperty(HTTPConstants.MC_GZIP_REQUEST, true);
              	options.setProperty(HTTPConstants.CHUNKED, true);
      //        	options.setProperty(HTTPConstants.MC_ACCEPT_GZIP, true);
      //        	options.setProperty(HTTPConstants.MC_GZIP_RESPONSE, true);
      //        	
      //        	
      //        	options.setProperty(org.apache.axis2.transport.http.HTTPConstants.MC_ACCEPT_GZIP, Boolean.TRUE);
      //        	options.setProperty(org.apache.axis2.transport.http.HTTPConstants.MC_GZIP_REQUEST, Boolean.TRUE);
      //        	options.setProperty(org.apache.axis2.transport.http.HTTPConstants.MC_GZIP_RESPONSE,Boolean.TRUE);
      //        	options.setProperty(org.apache.axis2.transport.http.HTTPConstants.COMPRESSION_GZIP,Boolean.TRUE);
      //        	options.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED,Boolean.FALSE);
              	
              }
              sc.setOptions(options);
              stub._setServiceClient(sc);
              
              return stub;
          }   
      

      SERVICE2

          /**
           * Returns (new or existing) reference to Web Services' ReturnsManager.
           * @return ReturnsManager
           */
          private ReturnsManagerStub getWSReturnsManager()
          {
              if (wsReturnsMgr == null)
              {
                  try
                  {
                      wsReturnsMgr = new ReturnsManagerStub(protocol + "://" + getReturnsManagerServerName() + ":"
                              + getReturnsManagerServerPort() + path);
      
                      ServiceClient sc = wsReturnsMgr._getServiceClient();
                      // Set security options
                      Options options = sc.getOptions();
                      options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, loadPolicy(getWebServiceSecurityPolicy()));
                      MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
                      options.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, new org.apache.commons.httpclient.HttpClient(manager));
                      options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, true);
                      options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, getTimeOutInMilliSeconds());
                      if(isCompressionAllowed())
                      {
      	            	options.setProperty(HTTPConstants.MC_GZIP_REQUEST, true);
      //	            	options.setProperty(HTTPConstants.MC_ACCEPT_GZIP, true);
      //	            	options.setProperty(HTTPConstants.MC_GZIP_RESPONSE, true);
                      }
                      options.setTimeOutInMilliSeconds(getTimeOutInMilliSeconds());
                      options.setCallTransportCleanup(true);
                      options.setUserName(getWebServiceUser());
                      char[] pwd = getWebServicePassword();
                      options.setPassword(new String(pwd));
                      Util.flushCharArray(pwd);
                      sc.setOptions(options);
                      // Enable axis2 security module
                      sc.engageModule(AXIS2_SECURITY_MODULE);
                      wsReturnsMgr._setServiceClient(sc);
                  }
                  catch (Throwable t)
                  {
                    logger.error("Unable to properly initialize the ReturnsManager webservice.", t);
                  }
              }
              return wsReturnsMgr;
          }
       

      The above method is defined in a class EnterpriseWebserviceOperation.java and I am creating multiple instances of it for every action to be called with in the webservice. I am doing this with the assumption that some of the actions are called very frequently and if there is only one instance of stub, that may cause denial of service. Is it a good idea to create multiple instances of stub for every action? Even if you create multiple instances, the underlying axis2 api will use only one instance of MultiThreadedHttpConnectionManager?

      As I have told you before I have two servcies deployed on two servers and from the client which is running in a single JVM, for one service I send the request xml as compressed and for the othere service send the clear text xml. After sending the request xml to service2 in clear text, immediately after that we will send the outcome of the previous service to the other service in compression format. Do these multiple service calls use the same MultiThreadedHttpConnectionManager and the options get overridden?

      I have also another concern here, this service is running at a corporate level and all the stores will be sending the sale transactions to this corporate server. If there are around 500 stores and if the TPS is 500 sent to this webservice, will the service be able to handle that many requests or will the server die? Currently we are using JMS for sending these transactions and my plan is to introduce webservice layer to send the transactions. will this approach work or are we going end up with scalability issues?

      Another issue under the same context, the response is not compressed after setting the following code. Do I have to do anything on the server side to allow the compression for the response.
      We are using Websphere and Weblogic application servers.
      options.setProperty(HTTPConstants.MC_GZIP_RESPONSE, true);
      options.setProperty(HTTPConstants.MC_ACCEPT_GZIP, true);

        Attachments

          Activity

            People

            • Assignee:
              veithen Andreas Veithen
              Reporter:
              bondalapati98 anil bondalapati
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: