tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r657995 - /tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java
Date Mon, 19 May 2008 21:47:19 GMT
Author: markt
Date: Mon May 19 14:47:19 2008
New Revision: 657995

URL: http://svn.apache.org/viewvc?rev=657995&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=42747.
Actually fixes a number of related bugs:
 - For a new WAR, use META-INF/context.xml for first initiation rather than copying it then
using it on next start
 - For a new dir, use META-INF/context.xml for first initiation
 - For a new dir, copy any META-INF/context.xml to $CATALINA_BASE/[engine]/[host]/contextPath.xml

Modified:
    tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java

Modified: tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java?rev=657995&r1=657994&r2=657995&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java Mon May 19 14:47:19 2008
@@ -21,6 +21,7 @@
 
 import java.io.BufferedOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -814,7 +815,26 @@
             (dir.getAbsolutePath(), new Long(dir.lastModified()));
 
         try {
-            Context context = (Context) Class.forName(contextClass).newInstance();
+            Context context = null;
+            if (deployXML && xml.exists()) {
+                synchronized (digester) {
+                    try {
+                        context = (Context) digester.parse(xml);
+                        if (context == null) {
+                            log.error(sm.getString("hostConfig.deployDescriptor.error",
+                                    file));
+                            return;
+                        }
+                    } finally {
+                        digester.reset();
+                    }
+                }
+                context.setConfigFile(xml.getAbsolutePath());
+                deployedApp.redeployResources.put
+                    (xml.getAbsolutePath(), new Long(xml.lastModified()));
+            } else {
+                context = (Context) Class.forName(contextClass).newInstance();
+            }
             if (context instanceof Lifecycle) {
                 Class<?> clazz = Class.forName(host.getConfigClass());
                 LifecycleListener listener =
@@ -823,11 +843,6 @@
             }
             context.setPath(contextPath);
             context.setDocBase(file);
-            if (xml.exists()) {
-                context.setConfigFile(xml.getAbsolutePath());
-                deployedApp.redeployResources.put
-                    (xml.getAbsolutePath(), new Long(xml.lastModified()));
-            }
             host.addChild(context);
             // If we're unpacking WARs, the docBase will be mutated after
             // starting the context
@@ -911,7 +926,78 @@
         if( log.isDebugEnabled() ) 
             log.debug(sm.getString("hostConfig.deployDir", file));
         try {
-            Context context = (Context) Class.forName(contextClass).newInstance();
+            // Checking for a /META-INF/context.xml
+            InputStream istream = null;
+            BufferedOutputStream ostream = null;
+            File xml = new File
+                (configBase, file + ".xml");
+            if (deployXML && !xml.exists()) {
+                try {
+                    File applicationContextXml =
+                        new File(dir, Constants.ApplicationContextXml);
+                    if (applicationContextXml.exists()) {
+                        istream = new FileInputStream(applicationContextXml);
+                        
+                        configBase.mkdirs();
+                        
+                        ostream =
+                            new BufferedOutputStream
+                            (new FileOutputStream(xml), 1024);
+                        byte buffer[] = new byte[1024];
+                        while (true) {
+                            int n = istream.read(buffer);
+                            if (n < 0) {
+                                break;
+                            }
+                            ostream.write(buffer, 0, n);
+                        }
+                        ostream.flush();
+                        ostream.close();
+                        ostream = null;
+                        istream.close();
+                        istream = null;
+                    }
+                } catch (Exception e) {
+                    // Ignore and continue
+                    if (ostream != null) {
+                        try {
+                            ostream.close();
+                        } catch (Throwable t) {
+                            // Ignore
+                        }
+                        ostream = null;
+                    }
+                    if (istream != null) {
+                        try {
+                            istream.close();
+                        } catch (Throwable t) {
+                            // Ignore
+                        }
+                        istream = null;
+                    }
+                }
+            }
+            
+            Context context = null;
+            if (deployXML && xml.exists()) {
+                synchronized (digester) {
+                    try {
+                        context = (Context) digester.parse(xml);
+                        if (context == null) {
+                            log.error(sm.getString("hostConfig.deployDescriptor.error",
+                                    file));
+                            return;
+                        }
+                    } finally {
+                        digester.reset();
+                    }
+                }
+                context.setConfigFile(xml.getAbsolutePath());
+                deployedApp.redeployResources.put
+                    (xml.getAbsolutePath(), new Long(xml.lastModified()));
+            } else {
+                context = (Context) Class.forName(contextClass).newInstance();
+            }
             if (context instanceof Lifecycle) {
                 Class<?> clazz = Class.forName(host.getConfigClass());
                 LifecycleListener listener =
@@ -920,17 +1006,9 @@
             }
             context.setPath(contextPath);
             context.setDocBase(file);
-            File configFile = new File(dir, Constants.ApplicationContextXml);
-            if (deployXML) {
-                context.setConfigFile(configFile.getAbsolutePath());
-            }
             host.addChild(context);
             deployedApp.redeployResources.put(dir.getAbsolutePath(),
                     new Long(dir.lastModified()));
-            if (deployXML) {
-                deployedApp.redeployResources.put(configFile.getAbsolutePath(),
-                        new Long(configFile.lastModified()));
-            }
             addWatchedResources(deployedApp, dir.getAbsolutePath(), context);
         } catch (Throwable t) {
             log.error(sm.getString("hostConfig.deployDir.error", file), t);



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message