luehe       2004/04/12 15:05:15

  Modified:    catalina/src/share/org/apache/catalina Deployer.java
               catalina/src/share/org/apache/catalina/core
                        StandardHost.java StandardHostDeployer.java
  Log:
  Fixed Bugzilla 28272 ("Deploy manager command should use context.xml
  from war file"):
  
  Added support for embedded META-INF/context.xml, as mentioned in
  manager-howto.html. If present, META-INF/context.xml is used only if
  neither "path" nor "config" params have been specified for the "deploy"
  action.
  
  Revision  Changes    Path
  1.4       +38 -1     
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/Deployer.java
  
  Index: Deployer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/Deployer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Deployer.java     27 Feb 2004 14:58:38 -0000      1.3
  +++ Deployer.java     12 Apr 2004 22:05:15 -0000      1.4
  @@ -125,6 +125,36 @@
   
   
       /**
  +     * Installs a new web application from the web application archive at the
  +     * specified URL, which must contain a META-INF/context.xml context
  +     * configuration file (consisting of a <code>&lt;Context&gt;</code>
  +     * element).
  +     *
  +     * <p>The web application is installed at the path specified inside the 
  +     * embedded META-INF/context.xml. The docBase (if any) specified inside the
  +     * embedded META-INF/context.xml is overridden with the web application's
  +     * location.
  +     *
  +     * <p>If the installation succeeds, a ContainerEvent of type
  +     * <code>INSTALL_EVENT</code> is sent to all registered listeners,
  +     * with the newly created <code>Context</code> as its argument.
  +     *
  +     * @param war URL pointing to web application location (WAR-packaged or
  +     *        unpacked directory)
  +     *
  +     * @exception IllegalArgumentException if <code>war</code> is null, or if
  +     *            the deployment host does not support any context.xml
  +     *            configuration files
  +     * @exception IllegalStateException if the context path specified in the
  +     *            context configuration file is already in use by an existing
  +     *            web application
  +     * @exception IOException if an input/output error was encountered
  +     *            during installation
  +     */
  +    public void install(URL war) throws IOException;
  +
  +
  +    /**
        * Return the Context for the deployed application that is associated
        * with the specified context path (if any); otherwise return
        * <code>null</code>.
  @@ -213,5 +243,12 @@
        */
       public void stop(String contextPath) throws IOException;
   
  +
  +    /**
  +     * Returns true if context.xml config files are supported.
  +     *
  +     * @return true of context.xml config files are supported, false otherwise
  +     */
  +    public boolean isDeployXML();
   
   }
  
  
  
  1.30      +35 -1     
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardHost.java
  
  Index: StandardHost.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardHost.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- StandardHost.java 27 Feb 2004 14:58:42 -0000      1.29
  +++ StandardHost.java 12 Apr 2004 22:05:15 -0000      1.30
  @@ -866,6 +866,40 @@
   
   
       /**
  +     * Installs a new web application from the web application archive at the
  +     * specified URL, which must contain a META-INF/context.xml context
  +     * configuration file (consisting of a <code>&lt;Context&gt;</code>
  +     * element).
  +     *
  +     * <p>The web application is installed at the path specified inside the 
  +     * embedded META-INF/context.xml. The docBase (if any) specified inside the
  +     * embedded META-INF/context.xml is overridden with the web application's
  +     * location.
  +     *
  +     * <p>If the installation succeeds, a ContainerEvent of type
  +     * <code>INSTALL_EVENT</code> is sent to all registered listeners,
  +     * with the newly created <code>Context</code> as its argument.
  +     *
  +     * @param war URL pointing to web application location (WAR-packaged or
  +     *        unpacked directory)
  +     *
  +     * @exception IllegalArgumentException if <code>war</code> is null, or if
  +     *            this StandardHost does not support any context.xml
  +     *            configuration files
  +     * @exception IllegalStateException if the context path specified in the
  +     *            context configuration file is already in use by an existing
  +     *            web application
  +     * @exception IOException if an input/output error was encountered
  +     *            during installation
  +     */
  +    public synchronized void install(URL war) throws IOException {
  +
  +        getDeployer().install(war);
  +
  +    }
  +
  +
  +    /**
        * Return the Context for the deployed application that is associated
        * with the specified context path (if any); otherwise return
        * <code>null</code>.
  
  
  
  1.23      +106 -1    
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardHostDeployer.java
  
  Index: StandardHostDeployer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardHostDeployer.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- StandardHostDeployer.java 22 Mar 2004 11:50:11 -0000      1.22
  +++ StandardHostDeployer.java 12 Apr 2004 22:05:15 -0000      1.23
  @@ -508,6 +508,101 @@
   
   
       /**
  +     * Installs a new web application from the web application archive at the
  +     * specified URL, which must contain a META-INF/context.xml context
  +     * configuration file (consisting of a <code>&lt;Context&gt;</code>
  +     * element).
  +     *
  +     * <p>The web application is installed at the path specified inside the 
  +     * embedded META-INF/context.xml. The docBase (if any) specified inside the
  +     * embedded META-INF/context.xml is overridden with the web application's
  +     * location.
  +     *
  +     * <p>If the installation succeeds, a ContainerEvent of type
  +     * <code>INSTALL_EVENT</code> is sent to all registered listeners,
  +     * with the newly created <code>Context</code> as its argument.
  +     *
  +     * @param war URL pointing to web application location (WAR-packaged or
  +     *        unpacked directory)
  +     *
  +     * @exception IllegalArgumentException if <code>war</code> is null, or if
  +     *            the deployment host does not support any context.xml
  +     *            configuration files
  +     * @exception IllegalStateException if the context path specified in the
  +     *            context configuration file is already in use by an existing
  +     *            web application
  +     * @exception IOException if an input/output error was encountered
  +     *            during installation
  +     */
  +    public synchronized void install(URL war) throws IOException {
  +
  +        if (war == null) {
  +            throw new IllegalArgumentException
  +                (sm.getString("standardHost.warRequired"));
  +        }
  +
  +        if (!host.isDeployXML()) {
  +            throw new IllegalArgumentException
  +                (sm.getString("standardHost.configNotAllowed"));
  +        }
  +
  +        // Calculate the document base for the new web application (if needed)
  +        String docBase = null; // Optional override for value in config file
  +        boolean isWAR = false;
  +        String url = war.toString();
  +        log.info(sm.getString("standardHost.installingWAR", url));
  +        // Calculate the WAR file absolute pathname
  +        if (url.startsWith("jar:")) {
  +            url = url.substring("jar:".length(), url.length() - 2);
  +            isWAR = true;
  +        }
  +        if (url.startsWith("file://")) {
  +            docBase = url.substring("file://".length());
  +        } else if (url.startsWith("file:")) {
  +            docBase = url.substring("file:".length());
  +        } else {
  +            throw new IllegalArgumentException
  +                (sm.getString("standardHost.warURL", url));
  +        }
  +
  +        // Expand war file if host wants wars unpacked
  +        if (isWAR && host.isUnpackWARs()) {
  +            docBase = ExpandWar.expand(host, war);
  +        }
  +
  +        // Install the new web application
  +        this.overrideDocBase = docBase;
  +
  +        InputStream stream = null;
  +        try {
  +            URL contextXml = new URL(war.toString() + "META-INF/context.xml");
  +            log.info(sm.getString("standardHost.installingXML", contextXml));
  +            stream = contextXml.openStream();
  +            Digester digester = createDigester();
  +            digester.setClassLoader(this.getClass().getClassLoader());
  +            digester.clear();
  +            digester.push(this);
  +            digester.parse(stream);
  +            stream.close();
  +            stream = null;
  +        } catch (Exception e) {
  +            host.log(sm.getString("standardHost.installError", docBase), e);
  +            throw new IOException(e.toString());
  +        } finally {
  +            if (stream != null) {
  +                try {
  +                    stream.close();
  +                } catch (Throwable t) {
  +                    ;
  +                }
  +            }
  +            this.overrideDocBase = null;
  +        }
  +
  +    }
  +
  +
  +    /**
        * Return the Context for the deployed application that is associated
        * with the specified context path (if any); otherwise return
        * <code>null</code>.
  @@ -818,6 +913,16 @@
   
           return (host.getParentClassLoader());
   
  +    }
  +
  +
  +    /**
  +     * Returns true if context.xml config files are supported.
  +     *
  +     * @return true of context.xml config files are supported, false otherwise
  +     */
  +    public boolean isDeployXML() {
  +        return (host.isDeployXML());
       }
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to