You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by rs...@apache.org on 2002/10/09 02:43:05 UTC

cvs commit: xml-axis/java/src/org/apache/axis/components/net SocketFactoryFactory.java

rsitze      2002/10/08 17:43:05

  Modified:    java/src/org/apache/axis/components/jms
                        JMSVendorAdapterFactory.java
               java/src/org/apache/axis/components/image
                        ImageIOFactory.java
               java/lib commons-discovery.jar
               java/src/org/apache/axis/components/compiler
                        CompilerFactory.java
               java/src/org/apache/axis AxisProperties.java
               java/test/chains TestChainFault.java
               java/src/org/apache/axis/configuration
                        EngineConfigurationFactoryFinder.java
               java/src/org/apache/axis/components/net
                        SocketFactoryFactory.java
  Log:
  Pushing logic back into core-discovery model.
  
  Revision  Changes    Path
  1.2       +7 -5      xml-axis/java/src/org/apache/axis/components/jms/JMSVendorAdapterFactory.java
  
  Index: JMSVendorAdapterFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/components/jms/JMSVendorAdapterFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JMSVendorAdapterFactory.java	24 Sep 2002 23:47:01 -0000	1.1
  +++ JMSVendorAdapterFactory.java	9 Oct 2002 00:43:04 -0000	1.2
  @@ -75,14 +75,16 @@
    */
   public class JMSVendorAdapterFactory
   {
  -    private static final SPInterface spInterface = new SPInterface(JMSVendorAdapter.class);
  -    private static final Class defaultClass = JNDIVendorAdapter.class;
  +    static {
  +//        AxisProperties.setClassOverrideProperty(JMSVendorAdapter.class, "?");
  +
  +        AxisProperties.setClassDefault(JMSVendorAdapter.class,
  +                                       "org.apache.axis.components.jms.JNDIVendorAdapter");
  +    }
   
       public static final JMSVendorAdapter getJMSVendorAdapter()
       {
  -        return (JMSVendorAdapter)AxisProperties.newInstance(spInterface,
  -                                                            defaultClass);
  -
  +        return (JMSVendorAdapter)AxisProperties.newInstance(JMSVendorAdapter.class);
       }
   
   }
  
  
  
  1.5       +23 -32    xml-axis/java/src/org/apache/axis/components/image/ImageIOFactory.java
  
  Index: ImageIOFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/components/image/ImageIOFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ImageIOFactory.java	4 Sep 2002 17:05:56 -0000	1.4
  +++ ImageIOFactory.java	9 Oct 2002 00:43:04 -0000	1.5
  @@ -73,6 +73,21 @@
       protected static Log log =
               LogFactory.getLog(ImageIOFactory.class.getName());
   
  +    static {
  +        AxisProperties.setClassOverrideProperty(ImageIO.class, "axis.ImageIO");
  +
  +        // If the imageIO is not configured look for the following:
  +        // 1.  Try the JDK 1.4 classes
  +        // 2.  Try the JIMI classes
  +        // 3.  If all else fails, try the JDK 1.3 classes
  +        AxisProperties.setClassDefaults(ImageIO.class,
  +                                        new String [] {
  +                                             "org.apache.axis.components.image.MerlinIO",
  +                                             "org.apache.axis.components.image.JimiIO",
  +                                             "org.apache.axis.components.image.JDK13IO",
  +                                        });
  +    }
  +
       /**
        * Get the ImageIO implementation.  This method follows a precedence:
        * 1.  Use the class defined by the System property axis.ImageIO.
  @@ -81,40 +96,16 @@
        * 4.  If that fails, instantiate the limited JDK13IO implementation.
        */
       public static ImageIO getImageIO() {
  -        // If the imageIO property is configured, use it.
  -        // Note:  I wish AxisProperties.newInstance could return null,
  -        // but it doesn't seem to; makes the following if check a bit more complex,
  -        // and disallows someone explicitly forcing JDK13IO over the others.
  -        ImageIO imageIO =
  -            (ImageIO)AxisProperties.newInstance(
  -                         new SPInterface(ImageIO.class, "axis.ImageIO"), "org.apache.axis.components.image.JDK13IO");
  +        ImageIO imageIO = (ImageIO)AxisProperties.newInstance(ImageIO.class);
           
  -        if (imageIO == null || imageIO.getClass() ==
  -                org.apache.axis.components.image.JDK13IO.class) {
  -            // If the imageIO is not configured look for the following:
  -            // 1.  Try the JDK 1.4 classes
  -            // 2.  Try the JIMI classes
  -            // 3.  If all else fails, try the JDK 1.3 classes
  -            try {
  -                ClassUtils.forName("javax.imageio.ImageWriter");
  -                imageIO = (ImageIO) ClassUtils.forName(
  -                        "org.apache.axis.components.image.MerlinIO").
  -                        newInstance();
  -            }
  -            catch (Throwable t1) {
  -                try {
  -                    ClassUtils.forName("com.sun.jimi.core.Jimi");
  -                    imageIO = (ImageIO) ClassUtils.forName(
  -                            "org.apache.axis.components.image.JimiIO").
  -                            newInstance();
  -                }
  -                catch (Throwable t2) {
  -                    imageIO = new JDK13IO();
  -                }
  -            }
  +        /**
  +         * This shouldn't be needed, but seems to be a common feel-good:
  +         */
  +        if (imageIO == null) {
  +            imageIO = new JDK13IO();
           }
   
  -        log.debug("axis.ImageIO:" + imageIO.getClass().getName());
  +        log.debug("axis.ImageIO: " + imageIO.getClass().getName());
           return imageIO;
       }
   }
  
  
  
  1.15      +91 -99    xml-axis/java/lib/commons-discovery.jar
  
  	<<Binary file>>
  
  
  1.9       +11 -4     xml-axis/java/src/org/apache/axis/components/compiler/CompilerFactory.java
  
  Index: CompilerFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/components/compiler/CompilerFactory.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- CompilerFactory.java	18 Sep 2002 16:10:42 -0000	1.8
  +++ CompilerFactory.java	9 Oct 2002 00:43:05 -0000	1.9
  @@ -76,12 +76,19 @@
       protected static Log log =
           LogFactory.getLog(CompilerFactory.class.getName());
   
  +    static {
  +        AxisProperties.setClassOverrideProperty(Compiler.class, "axis.Compiler");
  +
  +        AxisProperties.setClassDefault(Compiler.class,
  +                                       "org.apache.axis.components.compiler.Javac");
  +    }
  +
       public static Compiler getCompiler() {
  -        Compiler compiler =
  -            (Compiler)AxisProperties.newInstance(
  -                         new SPInterface(Compiler.class, "axis.Compiler"),
  -                         Javac.class);
  +        Compiler compiler = (Compiler)AxisProperties.newInstance(Compiler.class);
           
  +        /**
  +         * This shouldn't be needed, but seems to be a common feel-good:
  +         */
           if (compiler == null) {
               log.debug(Messages.getMessage("defaultCompiler"));
               compiler = new Javac();
  
  
  
  1.18      +121 -29   xml-axis/java/src/org/apache/axis/AxisProperties.java
  
  Index: AxisProperties.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/AxisProperties.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- AxisProperties.java	8 Oct 2002 22:24:00 -0000	1.17
  +++ AxisProperties.java	9 Oct 2002 00:43:05 -0000	1.18
  @@ -55,6 +55,7 @@
   
   package org.apache.axis;
   
  +import java.lang.reflect.InvocationTargetException;
   import java.security.AccessController;
   import java.security.PrivilegedAction;
   import java.util.Enumeration;
  @@ -62,10 +63,18 @@
   import java.util.Properties;
   
   import org.apache.axis.components.logger.LogFactory;
  -import org.apache.axis.components.net.SocketFactory;
   import org.apache.axis.utils.Messages;
  +import org.apache.commons.discovery.ResourceClassIterator;
   import org.apache.commons.discovery.ResourceNameDiscover;
  +import org.apache.commons.discovery.ResourceNameIterator;
  +import org.apache.commons.discovery.resource.ClassLoaders;
  +import org.apache.commons.discovery.resource.classes.DiscoverClasses;
  +import org.apache.commons.discovery.resource.names.DiscoverMappedNames;
   import org.apache.commons.discovery.resource.names.DiscoverNamesInAlternateManagedProperties;
  +import org.apache.commons.discovery.resource.names.DiscoverNamesInManagedProperties;
  +import org.apache.commons.discovery.resource.names.DiscoverServiceNames;
  +import org.apache.commons.discovery.resource.names.NameDiscoverers;
  +import org.apache.commons.discovery.tools.ClassUtils;
   import org.apache.commons.discovery.tools.DefaultClassHolder;
   import org.apache.commons.discovery.tools.DiscoverClass;
   import org.apache.commons.discovery.tools.ManagedProperties;
  @@ -109,25 +118,124 @@
           LogFactory.getLog(AxisProperties.class.getName());
   
       private static DiscoverNamesInAlternateManagedProperties altNameDiscoverer;
  +    private static DiscoverMappedNames mappedNames;
  +    private static NameDiscoverers nameDiscoverer;
  +    private static ClassLoaders loaders;
  +
  +    public static void setClassOverrideProperty(Class clazz, String propertyName) {
  +        getAlternatePropertyNameDiscoverer()
  +            .addClassToPropertyNameMapping(clazz.getName(), propertyName);
  +    }
       
  -    public static Object newInstance(Class spiClass, String defaultClass)
  -    {
  -        return newInstance(new SPInterface(spiClass), new DefaultClassHolder(defaultClass));
  +    public static void setClassDefault(Class clazz, String defaultName) {
  +        getMappedNames().map(clazz.getName(), defaultName);
  +    }
  +
  +    public static void setClassDefaults(Class clazz, String[] defaultNames) {
  +        getMappedNames().map(clazz.getName(), defaultNames);
  +    }
  +
  +    public static ResourceNameDiscover getNameDiscoverer() {
  +        if (nameDiscoverer == null) {
  +            nameDiscoverer = new NameDiscoverers();
  +            nameDiscoverer.addResourceNameDiscover(getAlternatePropertyNameDiscoverer());
  +            nameDiscoverer.addResourceNameDiscover(new DiscoverNamesInManagedProperties());
  +            nameDiscoverer.addResourceNameDiscover(new DiscoverServiceNames(getClassLoaders()));
  +            nameDiscoverer.addResourceNameDiscover(getMappedNames());
  +        }
  +        return nameDiscoverer;
       }
       
  -    public static Object newInstance(Class spiClass, Class defaultClass)
  -    {
  -        return newInstance(new SPInterface(spiClass), new DefaultClassHolder(defaultClass));
  +    public static ResourceClassIterator getResourceClassIterator(Class spi) {
  +        ResourceNameIterator it = getNameDiscoverer().findResourceNames(spi.getName());
  +        return new DiscoverClasses(loaders).findResourceClasses(it);
       }
  +
       
  -    public static Object newInstance(SPInterface spi, String defaultClass)
  +    private static ClassLoaders getClassLoaders() {
  +        if (loaders == null) {
  +            loaders = ClassLoaders.getAppLoaders(AxisProperties.class, null, true);
  +        }
  +        return loaders;
  +    }
  +
  +    private static DiscoverMappedNames getMappedNames() {
  +        if (mappedNames == null) {
  +            mappedNames = new DiscoverMappedNames();
  +        }
  +        return mappedNames;
  +    }
  +    
  +    private static DiscoverNamesInAlternateManagedProperties getAlternatePropertyNameDiscoverer() {
  +        if (altNameDiscoverer == null) {
  +            altNameDiscoverer = new DiscoverNamesInAlternateManagedProperties();
  +        }
  +        
  +        return altNameDiscoverer;
  +    }
  +
  +    /**
  +     * !WARNING!
  +     * SECURITY issue.
  +     * 
  +     * See bug 11874
  +     * 
  +     * The solution to both is to move doPrivilege UP within AXIS to a
  +     * class that is either private (cannot be reached by code outside
  +     * AXIS) or that represents a secure public interface...
  +     * 
  +     * This is going to require analysis and (probably) rearchitecting.
  +     * So, I'm taking taking the easy way out until we are at a point
  +     * where we can reasonably rearchitect for security.
  +     */
  +    
  +    public static Object newInstance(Class spiClass)
       {
  -        return newInstance(spi, new DefaultClassHolder(defaultClass));
  +        return newInstance(spiClass, null, null);
       }
  +
  +    public static Object newInstance(final Class spiClass,
  +                                     final Class constructorParamTypes[],
  +                                     final Object constructorParams[]) {
  +        return AccessController.doPrivileged(
  +            new PrivilegedAction() {
  +                public Object run() {
  +                    ResourceClassIterator services = getResourceClassIterator(spiClass);
  +            
  +                    Object obj = null;
  +                    while (obj == null  &&  services.hasNext()) {
  +                        Class service = services.nextResourceClass().loadClass();
  +            
  +                        /* service == null
  +                         * if class resource wasn't loadable
  +                         */
  +                        if (service != null) {
  +                            /* OK, class loaded.. attempt to instantiate it.
  +                             */
  +                            try {
  +                                ClassUtils.verifyAncestory(spiClass, service);
  +                                obj = ClassUtils.newInstance(service, constructorParamTypes, constructorParams);
  +                            } catch (InvocationTargetException e) {
  +                                if (e.getTargetException() instanceof java.lang.NoClassDefFoundError) {
  +                                    log.debug(Messages.getMessage("exception00"), e);
  +                                } else {
  +                                    log.warn(Messages.getMessage("exception00"), e);
  +                                }
  +                            } catch (Exception e) {
  +                                log.warn(Messages.getMessage("exception00"), e);
  +                            }
  +                        }
  +                    }
  +            
  +                    return obj;
  +                }
  +            });
  +    }
  +
       
  -    public static Object newInstance(SPInterface spi, Class defaultClass)
  +    public static Object newInstance(Class spiClass, Class defaultClass)
       {
  -        return newInstance(spi, new DefaultClassHolder(defaultClass));
  +        return newInstance(new SPInterface(spiClass), new DefaultClassHolder(defaultClass));
       }
           
       /**
  @@ -219,22 +327,6 @@
           return ManagedProperties.getProperties();
       }
   
  -
  -    public static final ResourceNameDiscover getAlternatePropertyNameDiscoverer() {
  -        if (altNameDiscoverer == null) {
  -            altNameDiscoverer = new DiscoverNamesInAlternateManagedProperties();
  -            altNameDiscoverer.addClassToPropertyNameMapping(
  -                    EngineConfigurationFactory.class.getName(),
  -                    EngineConfigurationFactory.SYSTEM_PROPERTY_NAME);
  -                    
  -            altNameDiscoverer.addClassToPropertyNameMapping(
  -                    SocketFactory.class.getName(),
  -                    "axis.socketFactory");
  -        }
  -        
  -        return altNameDiscoverer;
  -    }
  -
       /**
        * !WARNING!
        * SECURITY issue.
  @@ -249,8 +341,8 @@
        * So, I'm taking taking the easy way out until we are at a point
        * where we can reasonably rearchitect for security.
        */
  -    private static final Object newInstance(final SPInterface spi,
  -                                            final DefaultClassHolder defaultClass)
  +    private static Object newInstance(final SPInterface spi,
  +                                      final DefaultClassHolder defaultClass)
       {
           return AccessController.doPrivileged(
               new PrivilegedAction() {
  
  
  
  1.4       +1 -0      xml-axis/java/test/chains/TestChainFault.java
  
  Index: TestChainFault.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/chains/TestChainFault.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestChainFault.java	17 Sep 2002 20:38:09 -0000	1.3
  +++ TestChainFault.java	9 Oct 2002 00:43:05 -0000	1.4
  @@ -192,6 +192,7 @@
   
           } catch (Exception ex) {
               assertTrue("Unexpected exception", false);
  +            ex.printStackTrace();
           }
       }
   
  
  
  
  1.20      +13 -25    xml-axis/java/src/org/apache/axis/configuration/EngineConfigurationFactoryFinder.java
  
  Index: EngineConfigurationFactoryFinder.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/configuration/EngineConfigurationFactoryFinder.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- EngineConfigurationFactoryFinder.java	8 Oct 2002 22:23:59 -0000	1.19
  +++ EngineConfigurationFactoryFinder.java	9 Oct 2002 00:43:05 -0000	1.20
  @@ -65,13 +65,6 @@
   import org.apache.axis.components.logger.LogFactory;
   import org.apache.axis.utils.Messages;
   import org.apache.commons.discovery.ResourceClassIterator;
  -import org.apache.commons.discovery.ResourceNameIterator;
  -import org.apache.commons.discovery.resource.ClassLoaders;
  -import org.apache.commons.discovery.resource.classes.DiscoverClasses;
  -import org.apache.commons.discovery.resource.names.DiscoverConstNames;
  -import org.apache.commons.discovery.resource.names.DiscoverNamesInManagedProperties;
  -import org.apache.commons.discovery.resource.names.DiscoverServiceNames;
  -import org.apache.commons.discovery.resource.names.NameDiscoverers;
   import org.apache.commons.discovery.tools.ClassUtils;
   import org.apache.commons.logging.Log;
   
  @@ -103,6 +96,18 @@
       private static final String requiredMethod =
           "public static EngineConfigurationFactory newFactory(Object)";
   
  +    static {
  +        AxisProperties.setClassOverrideProperty(
  +                EngineConfigurationFactory.class,
  +                EngineConfigurationFactory.SYSTEM_PROPERTY_NAME);
  +
  +        AxisProperties.setClassDefaults(EngineConfigurationFactory.class,
  +                            new String[] {
  +                                "org.apache.axis.configuration.EngineConfigurationFactoryServlet",
  +                                "org.apache.axis.configuration.EngineConfigurationFactoryDefault",
  +                                });
  +    }
  +
       private EngineConfigurationFactoryFinder() {
       }
   
  @@ -148,24 +153,7 @@
           return (EngineConfigurationFactory)AccessController.doPrivileged(
                   new PrivilegedAction() {
                       public Object run() {
  -                        ClassLoaders loaders =
  -                            ClassLoaders.getAppLoaders(mySpi, myFactory, true);
  -                
  -                        NameDiscoverers nameDiscoverers = new NameDiscoverers();
  -                        nameDiscoverers.addResourceNameDiscover(AxisProperties.getAlternatePropertyNameDiscoverer());
  -                        nameDiscoverers.addResourceNameDiscover(new DiscoverNamesInManagedProperties());
  -                        nameDiscoverers.addResourceNameDiscover(new DiscoverServiceNames(loaders));
  -                        nameDiscoverers.addResourceNameDiscover(new DiscoverConstNames(
  -                            new String[] {
  -                                "org.apache.axis.configuration.EngineConfigurationFactoryServlet",
  -                                "org.apache.axis.configuration.EngineConfigurationFactoryDefault",
  -                                })
  -                            );
  -
  -                        ResourceNameIterator it = nameDiscoverers.findResourceNames(mySpi.getName());
  -
  -                        ResourceClassIterator services =
  -                            new DiscoverClasses(loaders).findResourceClasses(it);
  +                        ResourceClassIterator services = AxisProperties.getResourceClassIterator(mySpi);
   
                           EngineConfigurationFactory factory = null;
   
  
  
  
  1.9       +19 -12    xml-axis/java/src/org/apache/axis/components/net/SocketFactoryFactory.java
  
  Index: SocketFactoryFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/components/net/SocketFactoryFactory.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- SocketFactoryFactory.java	8 Oct 2002 22:23:59 -0000	1.8
  +++ SocketFactoryFactory.java	9 Oct 2002 00:43:05 -0000	1.9
  @@ -82,6 +82,21 @@
       private static Hashtable factories = new Hashtable();
   
       private static final Class classes[] = new Class[] { Hashtable.class };
  +
  +
  +    static {
  +        AxisProperties.setClassOverrideProperty(SocketFactory.class,
  +                                       "axis.socketFactory");
  +
  +        AxisProperties.setClassDefault(SocketFactory.class,
  +                                       "org.apache.axis.components.net.DefaultSocketFactory");
  +
  +        AxisProperties.setClassOverrideProperty(SecureSocketFactory.class,
  +                                       "axis.socketSecureFactory");
  +
  +        AxisProperties.setClassDefault(SecureSocketFactory.class,
  +                                       "org.apache.axis.components.net.DefaultSecureSocketFactory");
  +    }
       
       /**
        * Returns a copy of the environment's default socket factory.
  @@ -99,19 +114,11 @@
               Object objects[] = new Object[] { attributes };
       
               if (protocol.equalsIgnoreCase("http")) {
  -                theFactory = (SocketFactory)AxisProperties.newInstance(
  -                         new SPInterface(SocketFactory.class,
  -                                         "axis.socketFactory",
  -                                         classes,
  -                                         objects),
  -                         "org.apache.axis.components.net.DefaultSocketFactory");
  +                theFactory = (SocketFactory)
  +                    AxisProperties.newInstance(SocketFactory.class, classes, objects);
               } else if (protocol.equalsIgnoreCase("https")) {
  -                theFactory = (SocketFactory)AxisProperties.newInstance(
  -                         new SPInterface(SecureSocketFactory.class,
  -                                         "axis.socketSecureFactory",
  -                                         classes,
  -                                         objects),
  -                         "org.apache.axis.components.net.DefaultSecureSocketFactory");
  +                theFactory = (SecureSocketFactory)
  +                    AxisProperties.newInstance(SecureSocketFactory.class, classes, objects);
               }
               
               if (theFactory != null) {