axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdani...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/transport/http AxisServlet.java
Date Fri, 07 Dec 2001 19:51:58 GMT
gdaniels    01/12/07 11:51:58

  Modified:    java/src/org/apache/axis/server AxisServerFactory.java
                        AxisServer.java
               java/src/org/apache/axis/transport/http AxisServlet.java
  Added:       java/src/org/apache/axis/server
                        DefaultAxisServerFactory.java
  Log:
  Revamp the process by which we get servers, removing the JNDI
  dependency.
  
  There is now a static method AxisServer.getServer(Map environment),
  which the AxisServlet calls after loading the environment up with two entries,
  "provider"->a FileProvider pointing to the server-config.wsdd, and
  "servletContext"->our servlet context.
  
  AxisServerFactory is now an interface, which is implemented by DefaultAxisServerFactory.
  
  getServer will look for a system property names "axis.ServerFactory", and if
  it's there will treat it as a class name to load and cast to AxisServerFactory.  If it has
any problem doing that, it uses the DefaultAxisServerFactory.
  
  The default does the standard init - use the provider passed in "provider" if
  there is one, otherwise go through the default initialization procedure.
  
  Revision  Changes    Path
  1.3       +4 -106    xml-axis/java/src/org/apache/axis/server/AxisServerFactory.java
  
  Index: AxisServerFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/server/AxisServerFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AxisServerFactory.java	2001/12/03 18:17:09	1.2
  +++ AxisServerFactory.java	2001/12/07 19:51:58	1.3
  @@ -7,115 +7,13 @@
   
   import javax.naming.InitialContext;
   import javax.naming.NamingException;
  +import java.util.Map;
   
   /**
  - * Helper class for obtaining AxisServers, which hides the complexity
  - * of JNDI accesses, etc.
  - *
  - * !!! QUESTION : Does this class need to play any ClassLoader tricks?
  - * 
    * @author Glen Daniels (gdaniels@macromedia.com)
    */ 
   
  -public class AxisServerFactory {
  -    private static FileProvider defaultConfigProvider =
  -                           new FileProvider(Constants.SERVER_CONFIG_FILE);
  -
  -    /**
  -     * Obtain an AxisServer reference, using JNDI if possible, otherwise
  -     * creating one using the standard Axis configuration pattern.  If we
  -     * end up creating one and do have JNDI access, bind it to the passed
  -     * name so we find it next time.
  -     *
  -     * @param name the JNDI name we're interested in
  -     * @param configProvider a ConfigurationProvider which should be used
  -     *                       to configure any engine we end up creating, or
  -     *                       null to use the default configuration pattern.
  -     */
  -    static public AxisServer getServer(String name,
  -                                       ConfigurationProvider configProvider)
  -        throws AxisFault
  -    {
  -        AxisServer server = null;
  -        InitialContext context = null;
  -
  -        // First, and foremost, if a configProvider is passed in
  -        //  ALWAYS use that...
  -        if (configProvider != null) {
  -            return createNewServer(configProvider);
  -        }
  -
  -        // First check to see if JNDI works
  -        // !!! Might we need to set up context parameters here?
  -        try {
  -            context = new InitialContext();
  -        } catch (NamingException e) {
  -        }
  -        
  -        if (context != null) {
  -            // We've got JNDI, so try to find an AxisServer at the
  -            // specified name.
  -            try {
  -                server = (AxisServer)context.lookup(name);
  -            } catch (NamingException e) {
  -                // Didn't find it.
  -                server = createNewServer(configProvider);
  -                try {
  -                    context.bind(name, server);
  -                } catch (NamingException e1) {
  -                    // !!! Couldn't do it, what should we do here?
  -                }
  -            }
  -        } else {
  -            server = createNewServer(configProvider);
  -        }
  -
  -        return server;
  -    }
  -
  -    /**
  -     * Do the actual work of creating a new AxisServer, using the passed
  -     * configuration provider, or going through the default configuration
  -     * steps if null is passed.
  -     *
  -     * @return a shiny new AxisServer, ready for use.
  -     */
  -    static private AxisServer createNewServer(ConfigurationProvider provider)
  -    {
  -        // Just use the passed provider if there is one.
  -        if (provider != null) {
  -            return new AxisServer(provider);
  -        }
  -
  -        // Default configuration steps...
  -        //
  -        // 1. Check for a system property telling us which Configuration
  -        //    Provider to use.  If we find it, try creating one.
  -        String configClass = System.getProperty("axis.configProviderClass");
  -        if (configClass != null) {
  -            // Got one - so try to make it (which means it had better have
  -            // a default constructor - may make it possible later to pass in
  -            // some kind of environmental parameters...)
  -            try {
  -                Class cls = Class.forName(configClass);
  -                provider = (ConfigurationProvider)cls.newInstance();
  -            } catch (ClassNotFoundException e) {
  -                // Fall through???
  -            } catch (InstantiationException e) {
  -                // Fall through???
  -            } catch (IllegalAccessException e) {
  -                // Fall through???
  -            }
  -        }
  -
  -        // 2. If we couldn't make one above, use the default one.
  -        // !!! May want to add options here for getting another system
  -        //     property which is the config file name...
  -        if (provider == null) {
  -            provider = defaultConfigProvider;
  -        }
  -
  -        // 3. Create an AxisServer using the appropriate provider
  -        return new AxisServer(provider);
  -    }
  +public interface AxisServerFactory {    
  +    public AxisServer getServer(Map environment)
  +        throws AxisFault;
   }
  
  
  
  1.51      +32 -0     xml-axis/java/src/org/apache/axis/server/AxisServer.java
  
  Index: AxisServer.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/server/AxisServer.java,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- AxisServer.java	2001/12/05 00:27:18	1.50
  +++ AxisServer.java	2001/12/07 19:51:58	1.51
  @@ -68,6 +68,8 @@
   import org.apache.axis.utils.AxisClassLoader;
   import org.apache.axis.utils.JavaUtils;
   import org.apache.log4j.Category;
  +
  +import java.util.Map;
   /**
    *
    * @author Doug Davis (dug@us.ibm.com)
  @@ -77,6 +79,36 @@
   {
       static Category category =
               Category.getInstance(AxisServer.class.getName());
  +
  +    private static AxisServerFactory factory = null;
  +    
  +    public static AxisServer getServer(Map environment) throws AxisFault
  +    {
  +        if (factory == null) {
  +            String factoryClassName = System.getProperty("axis.ServerFactory");
  +            System.err.println("Server factory class = " + factoryClassName);
  +            if (factoryClassName != null) {
  +                try {
  +                    Class factoryClass = Class.forName(factoryClassName);
  +                    System.err.println("Got Class");
  +                    if (AxisServerFactory.class.isAssignableFrom(factoryClass))
  +                        factory = (AxisServerFactory)factoryClass.newInstance();
  +                } catch (Exception e) {
  +                    // If something goes wrong here, should we just fall
  +                    // through and use the default one?
  +                    e.printStackTrace(System.err);
  +                }
  +            }
  +            
  +            if (factory == null) {
  +                factory = new DefaultAxisServerFactory();
  +            }
  +        }
  +        
  +        System.err.println("factory is " + factory);
  +        
  +        return factory.getServer(environment);                
  +    }
   
       /**
        * the AxisClient to be used by outcalling Services
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/server/DefaultAxisServerFactory.java
  
  Index: DefaultAxisServerFactory.java
  ===================================================================
  package org.apache.axis.server;
  
  import org.apache.axis.ConfigurationProvider;
  import org.apache.axis.AxisFault;
  import org.apache.axis.Constants;
  import org.apache.axis.configuration.FileProvider;
  
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import java.util.Map;
  
  /**
   * Helper class for obtaining AxisServers, which hides the complexity
   * of JNDI accesses, etc.
   *
   * !!! QUESTION : Does this class need to play any ClassLoader tricks?
   * 
   * @author Glen Daniels (gdaniels@macromedia.com)
   */ 
  
  public class DefaultAxisServerFactory implements AxisServerFactory {
      private static FileProvider defaultConfigProvider =
                             new FileProvider(Constants.SERVER_CONFIG_FILE);
  
      /**
       * Get an AxisServer.  This factory looks for a "provider" in the
       * environment Map, and if one is found, uses that.  Otherwise it
       * uses the default initialization.
       * 
       */
      public AxisServer getServer(Map environment)
          throws AxisFault
      {
          ConfigurationProvider provider = null;
          try {
              provider = (ConfigurationProvider)environment.get("provider");
          } catch (ClassCastException e) {
              // Just in case, fall through here.
          }
          
          return createNewServer(provider);
      }
  
      /**
       * Do the actual work of creating a new AxisServer, using the passed
       * configuration provider, or going through the default configuration
       * steps if null is passed.
       *
       * @return a shiny new AxisServer, ready for use.
       */
      static private AxisServer createNewServer(ConfigurationProvider provider)
      {
          if (provider == null) {
              // Default configuration steps...
              //
              // 1. Check for a system property telling us which Configuration
              //    Provider to use.  If we find it, try creating one.
              String configClass = System.getProperty("axis.configProviderClass");
              if (configClass != null) {
                  // Got one - so try to make it (which means it had better have
                  // a default constructor - may make it possible later to pass in
                  // some kind of environmental parameters...)
                  try {
                      Class cls = Class.forName(configClass);
                      provider = (ConfigurationProvider)cls.newInstance();
                  } catch (ClassNotFoundException e) {
                      // Fall through???
                  } catch (InstantiationException e) {
                      // Fall through???
                  } catch (IllegalAccessException e) {
                      // Fall through???
                  }
              }
  
              // 2. If we couldn't make one above, use the default one.
              // !!! May want to add options here for getting another system
              //     property which is the config file name...
              if (provider == null) {
                  provider = defaultConfigProvider;
              }
          }
  
          // 3. Create an AxisServer using the appropriate provider
          return new AxisServer(provider);
      }
  }
  
  
  
  1.69      +12 -8     xml-axis/java/src/org/apache/axis/transport/http/AxisServlet.java
  
  Index: AxisServlet.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/transport/http/AxisServlet.java,v
  retrieving revision 1.68
  retrieving revision 1.69
  diff -u -r1.68 -r1.69
  --- AxisServlet.java	2001/12/06 18:10:19	1.68
  +++ AxisServlet.java	2001/12/07 19:51:58	1.69
  @@ -84,6 +84,8 @@
   import java.io.InputStream;
   import java.io.PrintWriter;
   import java.util.Enumeration;
  +import java.util.Map;
  +import java.util.HashMap;
   
   /**
    *
  @@ -140,11 +142,14 @@
                       new FileProvider(webInfPath,
                                        Constants.SERVER_CONFIG_FILE);
   
  -            // Obtain an AxisServer using the AxisServerFactory.  This will
  -            // first check JNDI to see if there's a server at the specified
  -            // name, which in this case is our WEB-INF path plus "/AxisServer".
  -            // (servlet 2.3 has a getServletContextName() API which might be
  -            // better used here)
  +            Map environment = new HashMap();
  +            environment.put("servletContext", getServletContext());
  +            environment.put("provider", provider);
  +
  +            // Obtain an AxisServer by using whatever AxisServerFactory is
  +            // registered.  The default one will just use the provider we
  +            // passed in, and presumably JNDI ones will use the ServletContext
  +            // to figure out a JNDI name to look up.
               //
               // The point of doing this rather than just creating the server
               // manually with the provider above is that we will then support
  @@ -152,9 +157,8 @@
               // container, and pre-registered in JNDI at deployment time.  It
               // also means we put the standard configuration pattern in one
               // place.
  -            getServletContext().setAttribute("AxisEngine",
  -                        AxisServerFactory.getServer(webInfPath + "/AxisServer",
  -                                                    provider));
  +            getServletContext().setAttribute("AxisEngine", 
  +                                             AxisServer.getServer(environment));
           }
           return (AxisServer)getServletContext().getAttribute("AxisEngine");
       }
  
  
  

Mime
View raw message