Author: markt Date: Fri Oct 14 12:55:04 2011 New Revision: 1183339 URL: http://svn.apache.org/viewvc?rev=1183339&view=rev Log: Revert to previous approach to generating InputSource objects for web.xml files Obtain last modified times from the SystemID of the InputSource
Modified: tomcat/trunk/java/org/apache/catalina/startup/Constants.java tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java Modified: tomcat/trunk/java/org/apache/catalina/startup/Constants.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/Constants.java?rev=1183339&r1=1183338&r2=1183339&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/startup/Constants.java (original) +++ tomcat/trunk/java/org/apache/catalina/startup/Constants.java Fri Oct 14 12:55:04 2011 @@ -1,193 +1,193 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package org.apache.catalina.startup; - - -/** - * String constants for the startup package. - * - * @author Craig R. McClanahan - * @author Jean-Francois Arcand - * @version $Id$ - */ - -public final class Constants { - - public static final String Package = "org.apache.catalina.startup"; - - public static final String ApplicationContextXml = "META-INF/context.xml"; - public static final String ApplicationWebXml = "/WEB-INF/web.xml"; - public static final String DefaultContextXml = "conf/context.xml"; - public static final String DefaultWebXml = "web.xml"; - public static final String HostContextXml = "context.xml.default"; - public static final String HostWebXml = "web.xml.default"; - - /** - * A dummy value used to suppress loading the default web.xml file. - * - * <p> - * It is useful when embedding Tomcat, when the default configuration is - * done programmatically, e.g. by calling - * <code>Tomcat.initWebappDefaults(context)</code>. - * - * @see Tomcat - */ - public static final String NoDefaultWebXml = "org/apache/catalina/startup/NO_DEFAULT_XML"; - - // J2EE - public static final String J2eeSchemaPublicId_14 = - "j2ee_1_4.xsd"; - public static final String J2eeSchemaResourcePath_14 = - "/javax/servlet/resources/j2ee_1_4.xsd"; - - public static final String JavaeeSchemaPublicId_5 = - "javaee_5.xsd"; - public static final String JavaeeSchemaResourcePath_5 = - "/javax/servlet/resources/javaee_5.xsd"; - - public static final String JavaeeSchemaPublicId_6 = - "javaee_6.xsd"; - public static final String JavaeeSchemaResourcePath_6 = - "/javax/servlet/resources/javaee_6.xsd"; - - - // W3C - public static final String W3cSchemaPublicId_10 = - "xml.xsd"; - public static final String W3cSchemaResourcePath_10 = - "/javax/servlet/resources/xml.xsd"; - - public static final String W3cSchemaDTDPublicId_10 = - "XMLSchema.dtd"; - public static final String W3cSchemaDTDResourcePath_10 = - "/javax/servlet/resources/XMLSchema.dtd"; - - public static final String W3cDatatypesDTDPublicId_10 = - "datatypes.dtd"; - public static final String W3cDatatypesDTDResourcePath_10 = - "/javax/servlet/resources/datatypes.dtd"; - - - // JSP - public static final String JspSchemaPublicId_20 = - "jsp_2_0.xsd"; - public static final String JspSchemaResourcePath_20 = - "/javax/servlet/jsp/resources/jsp_2_0.xsd"; - - public static final String JspSchemaPublicId_21 = - "jsp_2_1.xsd"; - public static final String JspSchemaResourcePath_21 = - "/javax/servlet/jsp/resources/jsp_2_1.xsd"; - - public static final String JspSchemaPublicId_22 = - "jsp_2_2.xsd"; - public static final String JspSchemaResourcePath_22 = - "/javax/servlet/jsp/resources/jsp_2_2.xsd"; - - - // TLD - public static final String TldDtdPublicId_11 = - "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"; - public static final String TldDtdResourcePath_11 = - "/javax/servlet/jsp/resources/web-jsptaglibrary_1_1.dtd"; - - public static final String TldDtdPublicId_12 = - "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"; - public static final String TldDtdResourcePath_12 = - "/javax/servlet/jsp/resources/web-jsptaglibrary_1_2.dtd"; - - public static final String TldSchemaPublicId_20 = - "web-jsptaglibrary_2_0.xsd"; - public static final String TldSchemaResourcePath_20 = - "/javax/servlet/jsp/resources/web-jsptaglibrary_2_0.xsd"; - - public static final String TldSchemaPublicId_21 = - "web-jsptaglibrary_2_1.xsd"; - public static final String TldSchemaResourcePath_21 = - "/javax/servlet/jsp/resources/web-jsptaglibrary_2_1.xsd"; - - - // web.xml - public static final String WebDtdPublicId_22 = - "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"; - public static final String WebDtdResourcePath_22 = - "/javax/servlet/resources/web-app_2_2.dtd"; - - public static final String WebDtdPublicId_23 = - "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"; - public static final String WebDtdResourcePath_23 = - "/javax/servlet/resources/web-app_2_3.dtd"; - - public static final String WebSchemaPublicId_24 = - "web-app_2_4.xsd"; - public static final String WebSchemaResourcePath_24 = - "/javax/servlet/resources/web-app_2_4.xsd"; - - public static final String WebSchemaPublicId_25 = - "web-app_2_5.xsd"; - public static final String WebSchemaResourcePath_25 = - "/javax/servlet/resources/web-app_2_5.xsd"; - - public static final String WebSchemaPublicId_30 = - "web-app_3_0.xsd"; - public static final String WebSchemaResourcePath_30 = - "/javax/servlet/resources/web-app_3_0.xsd"; - - public static final String WebCommonSchemaPublicId_30 = - "web-common_3_0.xsd"; - public static final String WebCommonSchemaResourcePath_30 = - "/javax/servlet/resources/web-common_3_0.xsd"; - - public static final String WebFragmentSchemaPublicId_30 = - "web-fragment_3_0.xsd"; - public static final String WebFragmentSchemaResourcePath_30 = - "/javax/servlet/resources/web-fragment_3_0.xsd"; - - // Web service - public static final String J2eeWebServiceSchemaPublicId_11 = - "j2ee_web_services_1_1.xsd"; - public static final String J2eeWebServiceSchemaResourcePath_11 = - "/javax/servlet/resources/j2ee_web_services_1_1.xsd"; - - public static final String J2eeWebServiceClientSchemaPublicId_11 = - "j2ee_web_services_client_1_1.xsd"; - public static final String J2eeWebServiceClientSchemaResourcePath_11 = - "/javax/servlet/resources/j2ee_web_services_client_1_1.xsd"; - - public static final String JavaeeWebServiceSchemaPublicId_12 = - "javaee_web_services_1_2.xsd"; - public static final String JavaeeWebServiceSchemaResourcePath_12 = - "/javax/servlet/resources/javaee_web_services_1_2.xsd"; - - public static final String JavaeeWebServiceClientSchemaPublicId_12 = - "javaee_web_services_client_1_2.xsd"; - public static final String JavaeeWebServiceClientSchemaResourcePath_12 = - "/javax/servlet/resources/javaee_web_services_client_1_2.xsd"; - - public static final String JavaeeWebServiceSchemaPublicId_13 = - "javaee_web_services_1_3.xsd"; - public static final String JavaeeWebServiceSchemaResourcePath_13 = - "/javax/servlet/resources/javaee_web_services_1_3.xsd"; - - public static final String JavaeeWebServiceClientSchemaPublicId_13 = - "javaee_web_services_client_1_3.xsd"; - public static final String JavaeeWebServiceClientSchemaResourcePath_13 = - "/javax/servlet/resources/javaee_web_services_client_1_3.xsd"; - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package org.apache.catalina.startup; + + +/** + * String constants for the startup package. + * + * @author Craig R. McClanahan + * @author Jean-Francois Arcand + * @version $Id$ + */ + +public final class Constants { + + public static final String Package = "org.apache.catalina.startup"; + + public static final String ApplicationContextXml = "META-INF/context.xml"; + public static final String ApplicationWebXml = "/WEB-INF/web.xml"; + public static final String DefaultContextXml = "conf/context.xml"; + public static final String DefaultWebXml = "conf/web.xml"; + public static final String HostContextXml = "context.xml.default"; + public static final String HostWebXml = "web.xml.default"; + + /** + * A dummy value used to suppress loading the default web.xml file. + * + * <p> + * It is useful when embedding Tomcat, when the default configuration is + * done programmatically, e.g. by calling + * <code>Tomcat.initWebappDefaults(context)</code>. + * + * @see Tomcat + */ + public static final String NoDefaultWebXml = "org/apache/catalina/startup/NO_DEFAULT_XML"; + + // J2EE + public static final String J2eeSchemaPublicId_14 = + "j2ee_1_4.xsd"; + public static final String J2eeSchemaResourcePath_14 = + "/javax/servlet/resources/j2ee_1_4.xsd"; + + public static final String JavaeeSchemaPublicId_5 = + "javaee_5.xsd"; + public static final String JavaeeSchemaResourcePath_5 = + "/javax/servlet/resources/javaee_5.xsd"; + + public static final String JavaeeSchemaPublicId_6 = + "javaee_6.xsd"; + public static final String JavaeeSchemaResourcePath_6 = + "/javax/servlet/resources/javaee_6.xsd"; + + + // W3C + public static final String W3cSchemaPublicId_10 = + "xml.xsd"; + public static final String W3cSchemaResourcePath_10 = + "/javax/servlet/resources/xml.xsd"; + + public static final String W3cSchemaDTDPublicId_10 = + "XMLSchema.dtd"; + public static final String W3cSchemaDTDResourcePath_10 = + "/javax/servlet/resources/XMLSchema.dtd"; + + public static final String W3cDatatypesDTDPublicId_10 = + "datatypes.dtd"; + public static final String W3cDatatypesDTDResourcePath_10 = + "/javax/servlet/resources/datatypes.dtd"; + + + // JSP + public static final String JspSchemaPublicId_20 = + "jsp_2_0.xsd"; + public static final String JspSchemaResourcePath_20 = + "/javax/servlet/jsp/resources/jsp_2_0.xsd"; + + public static final String JspSchemaPublicId_21 = + "jsp_2_1.xsd"; + public static final String JspSchemaResourcePath_21 = + "/javax/servlet/jsp/resources/jsp_2_1.xsd"; + + public static final String JspSchemaPublicId_22 = + "jsp_2_2.xsd"; + public static final String JspSchemaResourcePath_22 = + "/javax/servlet/jsp/resources/jsp_2_2.xsd"; + + + // TLD + public static final String TldDtdPublicId_11 = + "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"; + public static final String TldDtdResourcePath_11 = + "/javax/servlet/jsp/resources/web-jsptaglibrary_1_1.dtd"; + + public static final String TldDtdPublicId_12 = + "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"; + public static final String TldDtdResourcePath_12 = + "/javax/servlet/jsp/resources/web-jsptaglibrary_1_2.dtd"; + + public static final String TldSchemaPublicId_20 = + "web-jsptaglibrary_2_0.xsd"; + public static final String TldSchemaResourcePath_20 = + "/javax/servlet/jsp/resources/web-jsptaglibrary_2_0.xsd"; + + public static final String TldSchemaPublicId_21 = + "web-jsptaglibrary_2_1.xsd"; + public static final String TldSchemaResourcePath_21 = + "/javax/servlet/jsp/resources/web-jsptaglibrary_2_1.xsd"; + + + // web.xml + public static final String WebDtdPublicId_22 = + "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"; + public static final String WebDtdResourcePath_22 = + "/javax/servlet/resources/web-app_2_2.dtd"; + + public static final String WebDtdPublicId_23 = + "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"; + public static final String WebDtdResourcePath_23 = + "/javax/servlet/resources/web-app_2_3.dtd"; + + public static final String WebSchemaPublicId_24 = + "web-app_2_4.xsd"; + public static final String WebSchemaResourcePath_24 = + "/javax/servlet/resources/web-app_2_4.xsd"; + + public static final String WebSchemaPublicId_25 = + "web-app_2_5.xsd"; + public static final String WebSchemaResourcePath_25 = + "/javax/servlet/resources/web-app_2_5.xsd"; + + public static final String WebSchemaPublicId_30 = + "web-app_3_0.xsd"; + public static final String WebSchemaResourcePath_30 = + "/javax/servlet/resources/web-app_3_0.xsd"; + + public static final String WebCommonSchemaPublicId_30 = + "web-common_3_0.xsd"; + public static final String WebCommonSchemaResourcePath_30 = + "/javax/servlet/resources/web-common_3_0.xsd"; + + public static final String WebFragmentSchemaPublicId_30 = + "web-fragment_3_0.xsd"; + public static final String WebFragmentSchemaResourcePath_30 = + "/javax/servlet/resources/web-fragment_3_0.xsd"; + + // Web service + public static final String J2eeWebServiceSchemaPublicId_11 = + "j2ee_web_services_1_1.xsd"; + public static final String J2eeWebServiceSchemaResourcePath_11 = + "/javax/servlet/resources/j2ee_web_services_1_1.xsd"; + + public static final String J2eeWebServiceClientSchemaPublicId_11 = + "j2ee_web_services_client_1_1.xsd"; + public static final String J2eeWebServiceClientSchemaResourcePath_11 = + "/javax/servlet/resources/j2ee_web_services_client_1_1.xsd"; + + public static final String JavaeeWebServiceSchemaPublicId_12 = + "javaee_web_services_1_2.xsd"; + public static final String JavaeeWebServiceSchemaResourcePath_12 = + "/javax/servlet/resources/javaee_web_services_1_2.xsd"; + + public static final String JavaeeWebServiceClientSchemaPublicId_12 = + "javaee_web_services_client_1_2.xsd"; + public static final String JavaeeWebServiceClientSchemaResourcePath_12 = + "/javax/servlet/resources/javaee_web_services_client_1_2.xsd"; + + public static final String JavaeeWebServiceSchemaPublicId_13 = + "javaee_web_services_1_3.xsd"; + public static final String JavaeeWebServiceSchemaResourcePath_13 = + "/javax/servlet/resources/javaee_web_services_1_3.xsd"; + + public static final String JavaeeWebServiceClientSchemaPublicId_13 = + "javaee_web_services_client_1_3.xsd"; + public static final String JavaeeWebServiceClientSchemaResourcePath_13 = + "/javax/servlet/resources/javaee_web_services_client_1_3.xsd"; + +} Modified: tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java?rev=1183339&r1=1183338&r2=1183339&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java (original) +++ tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java Fri Oct 14 12:55:04 2011 @@ -29,6 +29,7 @@ import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.JarURLConnection; import java.net.MalformedURLException; +import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; @@ -1367,24 +1368,32 @@ public class ContextConfig DefaultWebXmlCacheEntry entry = hostWebXmlCache.get(host); - File globalWebXml = getGlobalWebXml(); - File hostWebXml = getHostWebXml(); + InputSource globalWebXml = getGlobalWebXmlSource(); + InputSource hostWebXml = getHostWebXmlSource(); long globalTimeStamp = 0; long hostTimeStamp = 0; if (globalWebXml != null) { - globalTimeStamp = globalWebXml.lastModified(); + try { + File f = new File(new URI(globalWebXml.getSystemId())); + globalTimeStamp = f.lastModified(); + } catch (URISyntaxException e) { + globalTimeStamp = -1; + } } if (hostWebXml != null) { - hostTimeStamp = hostWebXml.lastModified(); + try { + File f = new File(new URI(hostWebXml.getSystemId())); + hostTimeStamp = f.lastModified(); + } catch (URISyntaxException e) { + hostTimeStamp = -1; + } } if (entry != null && entry.getGlobalTimeStamp() == globalTimeStamp && entry.getHostTimeStamp() == hostTimeStamp) { - addWatchedResource(globalWebXml); - addWatchedResource(hostWebXml); return entry.getWebXml(); } @@ -1394,8 +1403,6 @@ public class ContextConfig entry = hostWebXmlCache.get(host); if (entry != null && entry.getGlobalTimeStamp() == globalTimeStamp && entry.getHostTimeStamp() == hostTimeStamp) { - addWatchedResource(globalWebXml); - addWatchedResource(hostWebXml); return entry.getWebXml(); } @@ -1410,48 +1417,31 @@ public class ContextConfig webXmlDefaultFragment.setAlwaysAddWelcomeFiles(false); // Parse global web.xml if present - if (globalWebXml == null || !globalWebXml.isFile()) { + if (globalWebXml == null) { // This is unusual enough to log log.info(sm.getString("contextConfig.defaultMissing")); - globalTimeStamp = 0; } else { - parseWebXml(getWebXmlSource(globalWebXml.getName(), - globalWebXml.getParent()), - webXmlDefaultFragment, - false); - globalTimeStamp = globalWebXml.lastModified(); + parseWebXml(globalWebXml, webXmlDefaultFragment, false); } // Parse host level web.xml if present // Additive apart from welcome pages webXmlDefaultFragment.setReplaceWelcomeFiles(true); - if (hostWebXml == null || !hostWebXml.isFile()) { - hostTimeStamp = 0; - } else { - parseWebXml(getWebXmlSource(hostWebXml.getName(), - hostWebXml.getParent()), - webXmlDefaultFragment, - false); - hostTimeStamp = hostWebXml.lastModified(); - } - - entry = new DefaultWebXmlCacheEntry(webXmlDefaultFragment, - globalTimeStamp, hostTimeStamp); + parseWebXml(hostWebXml, webXmlDefaultFragment, false); - hostWebXmlCache.put(host, entry); + // Don't update the cache if an error occurs + if (globalTimeStamp != -1 && hostTimeStamp != -1) { + entry = new DefaultWebXmlCacheEntry(webXmlDefaultFragment, + globalTimeStamp, hostTimeStamp); + hostWebXmlCache.put(host, entry); + } - addWatchedResource(globalWebXml); - addWatchedResource(hostWebXml); return webXmlDefaultFragment; } } - private void addWatchedResource(File f) { - if (f != null) { - context.addWatchedResource(f.getAbsolutePath()); - } - } + private void convertJsps(WebXml webXml) { Map<String,String> jspInitParams; ServletDef jspServlet = webXml.getServlets().get("jsp"); @@ -1650,9 +1640,10 @@ public class ContextConfig /** - * Identify the default web.xml to be used. + * Identify the default web.xml to be used and obtain an input source for + * it. */ - protected File getGlobalWebXml() { + protected InputSource getGlobalWebXmlSource() { // Is a default web.xml specified for the Context? if (defaultWebXml == null && context instanceof StandardContext) { defaultWebXml = ((StandardContext) context).getDefaultWebXml(); @@ -1664,27 +1655,15 @@ public class ContextConfig if (Constants.NoDefaultWebXml.equals(defaultWebXml)) { return null; } - - // In an embedded environment, configBase might not be set - File configBase = getConfigBase(); - if (configBase == null) - return null; - - String basePath = null; - try { - basePath = configBase.getCanonicalPath(); - } catch (IOException e) { - log.error(sm.getString("contextConfig.baseError"), e); - return null; - } - - return new File(basePath, defaultWebXml); + return getWebXmlSource(defaultWebXml, getBaseDir()); } + /** - * Identify the host web.xml to be used. + * Identify the host web.xml to be used and obtain an input source for + * it. */ - protected File getHostWebXml() { + protected InputSource getHostWebXmlSource() { String resourceName = getHostConfigPath(Constants.HostWebXml); // In an embedded environment, configBase might not be set @@ -1696,11 +1675,11 @@ public class ContextConfig try { basePath = configBase.getCanonicalPath(); } catch (IOException e) { - log.error(sm.getString("contextConfig.baseError"), e); + log.error(sm.getString("contectConfig.baseError"), e); return null; } - return new File(basePath, resourceName); + return getWebXmlSource(resourceName, basePath); } /** @@ -1776,11 +1755,12 @@ public class ContextConfig if(stream != null) { source = new InputSource(getClass().getClassLoader().getResource( - filename).toString()); + filename).toURI().toString()); } } else { - source = new InputSource("file://" + file.getAbsolutePath()); + source = new InputSource(file.getAbsoluteFile().toURI().toString()); stream = new FileInputStream(file); + context.addWatchedResource(file.getAbsolutePath()); } if (stream != null && source != null) { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org