axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject cvs commit: xml-axis-wsif/java/test/providers PlugableProvidersTest.java
Date Mon, 29 Jul 2002 12:34:44 GMT
antelder    2002/07/29 05:34:44

  Modified:    java/src/org/apache/wsif/util WSIFPluggableProviders.java
               java/test/providers PlugableProvidersTest.java
  Log:
  Changes to WSIFPluggable providers class	
  - improve javadoc comments
  - fix problem with returning to default provider after using overrideDefaultProvider
  - add overriding tests to testcase
  
  Revision  Changes    Path
  1.2       +79 -32    xml-axis-wsif/java/src/org/apache/wsif/util/WSIFPluggableProviders.java
  
  Index: WSIFPluggableProviders.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/util/WSIFPluggableProviders.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WSIFPluggableProviders.java	26 Jul 2002 14:26:15 -0000	1.1
  +++ WSIFPluggableProviders.java	29 Jul 2002 12:34:44 -0000	1.2
  @@ -74,23 +74,62 @@
   
   /**
    * Utility methods for pluggable provider support.
  + * <p>
  + * A WSIF provider is a class that implements the 
  + * org.apache.wsif.spi.Provider interface. A Provider is
  + * the logic that supports any particular WSDL binding extension.
  + * <p>
  + * WSIF providers are packaged in JAR files, and use the J2SE 1.3 
  + * JAR file extensions to support service providers. 
  + * A WSIF Provider JAR will contain the following file:
  + * <p>
  + * META-INF/services/com.ibm.wsif.spi.WSIFProvider
  + * <p>
  + * This file will contain a list of the class names of the Provider 
  + * classes in the JAR (which must implement com.ibm.wsif.spi.WSIFProvider).
  + * When the first request for a provider is made all the providers
  + * defined in the META-INF/services files will be instantiated. This can
  + * be prevented from happening by using the <code>setAutoLoadProviders<\code>
  + * method. When this is done providers must be manually defined by using the
  + * <code>overrideDefaultProvider<\code> method.
  + * <p>
  + * It is possible to have multiple providers supporting the same binding
  + * namespace. When this occurs the provider used is chosen in the following 
  + * order:
  + * 1 - the provider explicitly set for the namespace with the 
  + *     <code>overrideDefaultProvider<\code> method.
  + * 2 - the provider defined in the WSIF properties file as being the
  + *     default provider for the binding namespace
  + * 3 - the provider defined first in the META-INF/services file in the
  + *     jar file found first in the classpath.
    *
    * @author Ant Elder <antelder@apache.org>
    */
   public class WSIFPluggableProviders {
   	
  +	// defines if providers will be loaded automatically
   	private static boolean autoLoadProviders = true;
  -    private static ArrayList providersInClasspath;
  +
  +    // all the providers found in all the SPI files from
  +    // all the jar files in the classpath, in the order
  +    // they were found with the 1st in the ArrayList
  +    // being higher in the classpath.
  +    private static ArrayList providersFromSPIFiles;
  +    
  +    // a mapping of providers chosen to be supporting
  +    // a binding namespace. The mapping key is the 
  +    // namespace URI, the value is the provider
       private static HashMap defaultNSProviders;
   
       private static final String PLUGABLE_PROVIDER_FILENAME = 
          "META-INF/services/org.apache.wsif.spi.WSIFProvider";
   
       /**
  -     * Gets a WSIFProvider for a particular namespace URI.
  -     * @param namespaceURI  the URI of the namespace the WSIFProvider must support 
  -     * @return    a WSIFProvider supporting the requested URI,
  -     *            or null if no providers are available. 
  +     * Gets a WSIFProvider for a particular bindng namespace URI.
  +     * @param namespaceURI  the URI of the binding namespace 
  +     *                       that the WSIFProvider must support 
  +     * @return    a WSIFProvider supporting the requested binding
  +     *             namespace, or null if no providers are available. 
        */
       public static WSIFProvider getProvider(String namespaceURI) {
           Trc.entry(null, namespaceURI);
  @@ -124,15 +163,13 @@
       }
   
       /**
  -     * This method is deprecated as the Pluggable Provider support means the correct
  -     * provider should be located automatically.
  -     * It may still be required to use this method to override which provider is chosen,
  -     * for example to use the ApacheSoap provider instead of the default Axis SOAP provider.
  -     * Calling this method with a null provider resets the provider supporting the 
  -     * namespaceURI, so that the next request for for that namespaceURI will return
  -     * to using the default provider. 
  -     * @param providerNamespaceURI    the namespaceURI
  -     * @param provider   the WSIFProvider to be used for the namespaceURI
  +     * Change the WSIFProvider used for a particular binding namespace.
  +     * Calling this with a null provider removes the previously chosen 
  +     * provider for the binding namespace causing the next request for
  +     * a provider for the namespace to use the default search order.
  +     * 
  +     * @param providerNamespaceURI    the binding namespace to be overriden
  +     * @param provider   the WSIFProvider to be used for the binding namespace
        */
       public static void overrideDefaultProvider(
           String providerNamespaceURI,
  @@ -150,9 +187,6 @@
   
           if (provider == null) {
               WSIFProvider p = (WSIFProvider) defaultNSProviders.get(providerNamespaceURI);
  -            if ( providersInClasspath != null ) {
  -               providersInClasspath.remove( p );
  -            }
               if ( defaultNSProviders != null ) {
                  defaultNSProviders.remove(providerNamespaceURI);
               }
  @@ -165,16 +199,22 @@
       }
   
       /**
  -     * Tests if a provider is available for the given namespaces.
  +     * Tests if a provider is available for the given namespace.
        * @param ns1   the WSDL binding namespace URI
  -     * @param ns2   the WSDL port addresses namespace URI
        * @return   true if a provider is available for the given
  -     *            namespaces, otherwise false. 
  +     *            binding namespace, otherwise false. 
        */
       public static boolean isProviderAvailable(String ns1) {
       	return isProviderAvailable( ns1, ns1 );
       }
       
  +    /**
  +     * Tests if a provider is available for the given namespaces.
  +     * @param ns1   the WSDL binding namespace URI
  +     * @param ns2   the WSDL port addresses namespace URI
  +     * @return   true if a provider is available for the given
  +     *            namespaces, otherwise false. 
  +     */
       public static boolean isProviderAvailable(String ns1, String ns2) {
       	boolean supported = false;
           ArrayList ps = getSupportingProviders( ns1, false );
  @@ -197,8 +237,9 @@
       }
   
       /**
  -     * This sets if the WSIFProviders will be automatically located and loaded
  -     * using the J2SE 1.3 JAR file extensions to support service providers.
  +     * This sets if the WSIFProviders will be automatically loaded.
  +     * If this is set to false any providers required msut be explicitly 
  +     * defined by using the <code>overrideDefaultProvider<\code> method.
        * Changing the state of the auto loading of providers clears any providers
        * that have already been loaded or choosen as a default provider.  
        * @param b   true means all the WSIFProviders will be loaded automatically,
  @@ -208,13 +249,18 @@
       public static void setAutoLoadProviders(boolean b) {
           Trc.entry(null, b);
           if ( autoLoadProviders != b ) {
  -           providersInClasspath = null;
  +           providersFromSPIFiles = null;
              defaultNSProviders = null;
  +           autoLoadProviders = b;
           }
  -        autoLoadProviders = b;
           Trc.exit();
       }
   
  +    /**
  +     * Tests if providers are set to be automatically loaded.
  +     * @return true if providers will be loaded automatically,
  +     *          otherwise false.
  +     */
       public static boolean isAutoLoadProviders() {
           Trc.entry(null);
           Trc.exit(autoLoadProviders);
  @@ -233,13 +279,13 @@
       private static ArrayList getSupportingProviders(
           String namespaceURI,
           boolean issueMessage) {
  -        if (providersInClasspath == null) {
  -            providersInClasspath = getAllDynamicWSIFProviders();
  +        if (providersFromSPIFiles == null) {
  +            providersFromSPIFiles = getAllDynamicWSIFProviders();
           }
           ArrayList supportingProviders = new ArrayList();
           String[] uris;
           WSIFProvider p;
  -        for (Iterator i = providersInClasspath.iterator(); i.hasNext(); ) {
  +        for (Iterator i = providersFromSPIFiles.iterator(); i.hasNext(); ) {
           	p = (WSIFProvider) i.next();
               uris = p.getBindingNamespaceURIs();
               for (int j = 0; j < uris.length; j++) {
  @@ -297,7 +343,7 @@
             Trc.exception( ex );
             MessageLogger.log(
                "WSIF.0003W",
  -             "an error occured locating META-INF resources: " + ex.getMessage() );
  +             ex.getMessage() );
             return providers;
          }
   
  @@ -315,14 +361,15 @@
                      ", does not implement org.apache.wsif.spi.WSIFProvider" );
                }
             } catch (ClassNotFoundException ex) {
  +             Trc.exception( ex );
                MessageLogger.log(
                   "WSIF.0003W",
  -                "cannot find class - " + ex.getMessage() );
  +                ex.getMessage() );
             } catch (Exception ex) {
                Trc.exception( ex );
                MessageLogger.log(
                   "WSIF.0003W",
  -                "an error occured instantiating class - " + ex.getMessage() );
  +                ex.getMessage() );
             }
          }
   
  @@ -350,7 +397,7 @@
              Trc.exception( ex );
              MessageLogger.log(
                 "WSIF.0003W",
  -              "an error occured reading META-INF '" + u + "' file: " + ex.getMessage()
);
  +              ex.getMessage() );
       	} finally {
       		if ( in != null ) {
       		   try {
  @@ -359,7 +406,7 @@
                     Trc.exception( ex );
                     MessageLogger.log(
                        "WSIF.0003W",
  -                     "an error occured closing META-INF '" + u + "' file: " + ex.getMessage()
);
  +                     ex.getMessage() );
       		   }
       		}
       	}
  
  
  
  1.5       +43 -2     xml-axis-wsif/java/test/providers/PlugableProvidersTest.java
  
  Index: PlugableProvidersTest.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/providers/PlugableProvidersTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PlugableProvidersTest.java	26 Jul 2002 14:26:15 -0000	1.4
  +++ PlugableProvidersTest.java	29 Jul 2002 12:34:44 -0000	1.5
  @@ -64,6 +64,7 @@
   
   import org.apache.wsif.base.WSIFServiceImpl;
   import org.apache.wsif.providers.soap.apacheaxis.WSIFDynamicProvider_ApacheAxis;
  +import org.apache.wsif.providers.soap.apachesoap.WSIFDynamicProvider_ApacheSOAP;
   import org.apache.wsif.spi.WSIFProvider;
   import org.apache.wsif.util.WSIFPluggableProviders;
   
  @@ -101,13 +102,13 @@
       	     
   
       public void testSetDefaultSoapProvider() { 
  -       WSIFServiceImpl.setDynamicWSIFProvider( "http://schemas.xmlsoap.org/wsdl/soap/",
  +       WSIFPluggableProviders.overrideDefaultProvider( "http://schemas.xmlsoap.org/wsdl/soap/",
             new WSIFDynamicProvider_ApacheAxis()
          );
          assertTrue( doit("http://schemas.xmlsoap.org/wsdl/soap/",
       	     "org.apache.wsif.providers.soap.apacheaxis.WSIFDynamicProvider_ApacheAxis") );
          // set null so uses default next time
  -       WSIFServiceImpl.setDynamicWSIFProvider( 
  +       WSIFPluggableProviders.overrideDefaultProvider( 
             "http://schemas.xmlsoap.org/wsdl/soap/", null );
   
       }
  @@ -147,6 +148,46 @@
             !WSIFPluggableProviders.isProviderAvailable( 
                "http://schemas.xmlsoap.org/wsdl/xxx/") );
   
  +       // test changing the default provider
  +       WSIFProvider p1 = WSIFPluggableProviders.getProvider(
  +          "http://schemas.xmlsoap.org/wsdl/soap/" );
  +       Class c1 = p1.getClass();
  +
  +       WSIFPluggableProviders.overrideDefaultProvider( 
  +          "http://schemas.xmlsoap.org/wsdl/soap/",
  +          new WSIFDynamicProvider_ApacheAxis() );
  +       WSIFProvider p2 = WSIFPluggableProviders.getProvider(
  +          "http://schemas.xmlsoap.org/wsdl/soap/" );
  +       Class c2 = p2.getClass();
  +       assertTrue( "defaultprovider 1", !c1.equals( c2 ) );
  +
  +       WSIFPluggableProviders.overrideDefaultProvider( 
  +          "http://schemas.xmlsoap.org/wsdl/soap/",
  +          null );
  +       WSIFProvider p3 = WSIFPluggableProviders.getProvider(
  +          "http://schemas.xmlsoap.org/wsdl/soap/" );
  +       Class c3 = p3.getClass();
  +       assertTrue( "defaultprovider 2", c1.equals( c3 ) );
  +       assertTrue( "defaultprovider 3", p1 == p3 );
  +
  +       WSIFPluggableProviders.overrideDefaultProvider( 
  +          "http://schemas.xmlsoap.org/wsdl/soap/",
  +          p1 );
  +       p2 = WSIFPluggableProviders.getProvider(
  +          "http://schemas.xmlsoap.org/wsdl/soap/" );
  +       c2 = p2.getClass();
  +       assertTrue( "defaultprovider 4", c1.equals( c2 ) );
  +       assertTrue( "defaultprovider 5", p1 == p2 );
  +
  +       WSIFPluggableProviders.overrideDefaultProvider( 
  +          "http://schemas.xmlsoap.org/wsdl/soap/",
  +          null );
  +       p2 = WSIFPluggableProviders.getProvider(
  +          "http://schemas.xmlsoap.org/wsdl/soap/" );
  +       c2 = p2.getClass();
  +       assertTrue( "defaultprovider 6", c1.equals( c2 ) );
  +       assertTrue( "defaultprovider 7", p1 == p2 );
  +                 
          // test provider auto loading
          WSIFPluggableProviders.setAutoLoadProviders( false );
          assertTrue( "AutoLoadProviders 1", 
  
  
  

Mime
View raw message