axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Doug Davis" <...@us.ibm.com>
Subject Re: cvs commit: xml-axis/java/src/org/apache/axis/client Service.java
Date Tue, 26 Mar 2002 16:58:55 GMT
Like I said in my commit - there are plenty of other tweaks that can be
made to this and adding something to fix the problem you're talking
about would be one of them.  More immediate, yes, if a person's WSDL
changes that much then they should not use the caching - but in a real
world scenario it won't change that often.
-Dug


Glyn Normington/UK/IBM@IBMGB on 03/26/2002 11:58:13 AM

Please respond to axis-dev@xml.apache.org

To:    axis-dev@xml.apache.org
cc:
Subject:    Re: cvs commit: xml-axis/java/src/org/apache/axis/client
       Service.java



This sounds good for performance, but if a WSDL file changes, there is no
logic to remove the stale data from the cache. So what can users do to
avoid unpredictable behaviour (except turn caching off or freeze their
WSDL)? Must they restart their servers, webapps, etc.?

Glyn



                      dug@apache.org
                                               To:
                                               xml-axis-cvs@apache.org
                      26/03/02 12:44           cc:
                      Please respond to        Subject:  cvs commit:
                      xml-axis/java/src/org/apache/axis/client Service.java
                      axis-dev





dug         02/03/26 04:44:47

  Modified:    java/src/org/apache/axis/client Service.java
  Log:
  Add some basic caching of WSDL.  WSDL will not change very often
  so cache what we see - the improvement in speed in cases where
  we reuse the same WSDL(but not the same Service object) is quite
dramatic.
  Some thing nice to add in the future would be some basic algorithm that
  would limit the size of the cache and drop the least-used (or last used)
  one.

  Revision  Changes    Path
  1.45      +56 -7
xml-axis/java/src/org/apache/axis/client/Service.java

  Index: Service.java
  ===================================================================
  RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/client/Service.java,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- Service.java             20 Mar 2002 21:52:23 -0000          1.44
  +++ Service.java             26 Mar 2002 12:44:46 -0000          1.45
  @@ -55,6 +55,7 @@

   package org.apache.axis.client ;

  +import javax.wsdl.extensions.soap.SOAPAddress;
   import org.apache.axis.AxisEngine;
   import org.apache.axis.EngineConfiguration;
   import org.apache.axis.configuration.DefaultEngineConfigurationFactory;
  @@ -65,11 +66,11 @@
   import javax.naming.Reference;
   import javax.naming.Referenceable;
   import javax.naming.StringRefAddr;
  +
   import javax.wsdl.Binding;
   import javax.wsdl.Definition;
   import javax.wsdl.Port;
   import javax.wsdl.PortType;
  -import javax.wsdl.extensions.soap.SOAPAddress;
   import javax.wsdl.factory.WSDLFactory;
   import javax.wsdl.xml.WSDLReader;
   import javax.xml.rpc.ServiceException;
  @@ -79,14 +80,15 @@
   import java.io.FileNotFoundException;
   import java.io.InputStream;
   import java.io.Serializable;
  -import java.lang.reflect.Proxy;
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.util.HashSet;
  +import java.util.HashMap;
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
   import java.util.Set;
  +import java.lang.reflect.Proxy;

   /**
    * Axis' JAXRPC Dynamic Invoation Interface implementation of the
Service
  @@ -114,6 +116,9 @@
        * Thread local storage used for storing the last call object
        */
       private static ThreadLocal previousCall = new ThreadLocal();
  +    static private HashMap      cachedWSDL  = new HashMap();
  +    static private boolean      cachingWSDL = true ;
  +

       Definition getWSDLDefinition() {
           return( wsdlDefinition );
  @@ -158,8 +163,16 @@
       public Service(URL wsdlDoc, QName serviceName) throws
ServiceException {
           engine = getAxisClient();
           this.wsdlLocation = wsdlDoc;
  -        Document doc = XMLUtils.newDocument(wsdlDoc.toString());
  -        initService(doc, serviceName);
  +        Definition def = null ;
  +
  +        if ( cachingWSDL &&
  +             (def = (Definition)
cachedWSDL.get(this.wsdlLocation.toString())) != null ){
  +          initService( def, serviceName );
  +        }
  +        else {
  +          Document doc = XMLUtils.newDocument(wsdlDoc.toString());
  +          initService(doc, serviceName);
  +        }
       }

       /**
  @@ -183,9 +196,16 @@
           }
           try {
               // Start by reading in the WSDL using WSDL4J
  -            FileInputStream      fis = new
FileInputStream(wsdlLocation);
  -            Document doc = XMLUtils.newDocument(fis);
  -            initService(doc, serviceName);
  +            Definition def = null ;
  +            if ( cachingWSDL &&
  +                 (def = (Definition)
cachedWSDL.get(this.wsdlLocation.toString())) != null ) {
  +              initService( def, serviceName );
  +            }
  +            else {
  +              FileInputStream  fis = new FileInputStream(wsdlLocation);
  +              Document         doc = XMLUtils.newDocument(fis);
  +              initService(doc, serviceName);
  +            }
           }
           catch( FileNotFoundException exp ) {
               throw new ServiceException(
  @@ -226,6 +246,20 @@
               reader.setFeature("javax.wsdl.verbose", false);
               Definition           def    = reader.readWSDL( null, doc );

  +            if ( cachingWSDL && this.wsdlLocation != null )
  +              cachedWSDL.put( this.wsdlLocation.toString(), def );
  +
  +            initService( def, serviceName );
  +        }
  +        catch( Exception exp ) {
  +            throw new ServiceException(
  +                    JavaUtils.getMessage("wsdlError00", "" + "", "\n" +
exp) );
  +        }
  +    }
  +
  +    private void initService(Definition def, QName serviceName)
  +            throws ServiceException {
  +        try {
               this.wsdlDefinition = def ;

               // grrr!  Too many flavors of QName
  @@ -576,5 +610,20 @@
       public Call getCall() throws ServiceException {
           Call call = (Call) previousCall.get();
           return call;
  +    }
  +
  +    /**
  +     * Tells whether or not we're caching WSDL
  +     */
  +    public boolean getCacheWSDL() {
  +      return cachingWSDL ;
  +    }
  +
  +    /**
  +     * Allows users to turn caching of WSDL documents on or off.
  +     * Default is 'true' (on).
  +     */
  +    public void setCacheWSDL(boolean flag) {
  +      cachingWSDL = flag ;
       }
   }










Mime
View raw message