Author: violetagg
Date: Mon Jul 8 12:12:04 2013
New Revision: 1500682
URL: http://svn.apache.org/r1500682
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=55210
Merged revision 1500590 from tomcat/trunk:
When searching for ServletContainerInitializer, ignore comments in the
provider-configuration file.
Support multiple ServletContainerInitializer in the provider-configuration file.
Patch is provided by Nick Williams.
Modified:
tomcat/tc7.0.x/trunk/ (props changed)
tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/ContextConfig.java
tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
Merged /tomcat/trunk:r1500590
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/ContextConfig.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/ContextConfig.java?rev=1500682&r1=1500681&r2=1500682&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/ContextConfig.java
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/ContextConfig.java
Mon Jul 8 12:12:04 2013
@@ -1546,7 +1546,7 @@ public class ContextConfig implements Li
URL url = fragment.getURL();
Jar jar = null;
InputStream is = null;
- ServletContainerInitializer sci = null;
+ List<ServletContainerInitializer> detectedScis = null;
try {
if ("jar".equals(url.getProtocol())) {
jar = JarFactory.newInstance(url);
@@ -1559,7 +1559,7 @@ public class ContextConfig implements Li
}
}
if (is != null) {
- sci = getServletContainerInitializer(is);
+ detectedScis = getServletContainerInitializers(is);
}
} catch (IOException ioe) {
log.error(sm.getString(
@@ -1580,42 +1580,44 @@ public class ContextConfig implements Li
}
}
- if (sci == null) {
+ if (detectedScis == null) {
continue;
}
- initializerClassMap.put(sci, new HashSet<Class<?>>());
+ for (ServletContainerInitializer sci : detectedScis) {
+ initializerClassMap.put(sci, new HashSet<Class<?>>());
- HandlesTypes ht = null;
- try {
- ht = sci.getClass().getAnnotation(HandlesTypes.class);
- } catch (Exception e) {
- if (log.isDebugEnabled()) {
- log.info(sm.getString("contextConfig.sci.debug", url), e);
- } else {
- log.info(sm.getString("contextConfig.sci.info", url));
+ HandlesTypes ht = null;
+ try {
+ ht = sci.getClass().getAnnotation(HandlesTypes.class);
+ } catch (Exception e) {
+ if (log.isDebugEnabled()) {
+ log.info(sm.getString("contextConfig.sci.debug", url),
+ e);
+ } else {
+ log.info(sm.getString("contextConfig.sci.info", url));
+ }
}
- }
- if (ht != null) {
- Class<?>[] types = ht.value();
- if (types != null) {
- for (Class<?> type : types) {
- if (type.isAnnotation()) {
- handlesTypesAnnotations = true;
- } else {
- handlesTypesNonAnnotations = true;
- }
- Set<ServletContainerInitializer> scis =
- typeInitializerMap.get(type);
- if (scis == null) {
- scis = new HashSet<ServletContainerInitializer>();
- typeInitializerMap.put(type, scis);
+ if (ht != null) {
+ Class<?>[] types = ht.value();
+ if (types != null) {
+ for (Class<?> type : types) {
+ if (type.isAnnotation()) {
+ handlesTypesAnnotations = true;
+ } else {
+ handlesTypesNonAnnotations = true;
+ }
+ Set<ServletContainerInitializer> scis =
typeInitializerMap
+ .get(type);
+ if (scis == null) {
+ scis = new
HashSet<ServletContainerInitializer>();
+ typeInitializerMap.put(type, scis);
+ }
+ scis.add(sci);
}
- scis.add(sci);
}
}
}
-
}
}
@@ -1627,19 +1629,28 @@ public class ContextConfig implements Li
* @return The class name
* @throws IOException
*/
- protected ServletContainerInitializer getServletContainerInitializer(
+ protected List<ServletContainerInitializer>
getServletContainerInitializers(
InputStream is) throws IOException {
- String className = null;
+ List<ServletContainerInitializer> initializers = new
ArrayList<ServletContainerInitializer>();
if (is != null) {
String line = null;
try {
- BufferedReader br =
- new BufferedReader(new InputStreamReader(is, "UTF-8"));
- line = br.readLine();
- if (line != null && line.trim().length() > 0) {
- className = line.trim();
+ BufferedReader br = new BufferedReader(new InputStreamReader(
+ is, "UTF-8"));
+ while ((line = br.readLine()) != null) {
+ line = line.trim();
+ if (line.length() > 0) {
+ int i = line.indexOf('#');
+ if (i > -1) {
+ if (i == 0) {
+ continue;
+ }
+ line = line.substring(0, i).trim();
+ }
+ initializers.add(getServletContainerInitializer(line));
+ }
}
} catch (UnsupportedEncodingException e) {
// Should never happen with UTF-8
@@ -1647,11 +1658,16 @@ public class ContextConfig implements Li
}
}
+ return initializers;
+ }
+
+ protected ServletContainerInitializer getServletContainerInitializer(
+ String className) throws IOException {
ServletContainerInitializer sci = null;
try {
- Class<?> clazz = Class.forName(className,true,
- context.getLoader().getClassLoader());
- sci = (ServletContainerInitializer) clazz.newInstance();
+ Class<?> clazz = Class.forName(className, true, context.getLoader()
+ .getClassLoader());
+ sci = (ServletContainerInitializer) clazz.newInstance();
} catch (ClassNotFoundException e) {
log.error(sm.getString("contextConfig.invalidSci", className), e);
throw new IOException(e);
Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1500682&r1=1500681&r2=1500682&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Mon Jul 8 12:12:04 2013
@@ -62,6 +62,13 @@
<bug>55186</bug>: Ensure local name is recycled between requests so IP
virtual hosting works correctly. (markt)
</fix>
+ <fix>
+ <bug>55210</bug>: Correct the processing of the provider-configuration
+ file for <code>javax.servlet.ServletContainerInitializer</code> in the
+ resource directory <code>META-INF/services</code> when this file
+ contains comments and multiple SCIs. Patch provided by Nick Williams.
+ (violetagg)
+ </fix>
</changelog>
</subsection>
<subsection name="Jasper">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]