|
17 | 17 | package org.apache.catalina.core; |
18 | 18 |
|
19 | 19 | import java.io.InputStream; |
| 20 | +import java.lang.reflect.Constructor; |
20 | 21 | import java.lang.reflect.InvocationTargetException; |
21 | 22 | import java.net.MalformedURLException; |
22 | 23 | import java.net.URL; |
|
67 | 68 | import org.apache.catalina.WebResourceRoot; |
68 | 69 | import org.apache.catalina.Wrapper; |
69 | 70 | import org.apache.catalina.connector.Connector; |
| 71 | +import org.apache.catalina.connector.Request; |
70 | 72 | import org.apache.catalina.mapper.MappingData; |
71 | 73 | import org.apache.catalina.util.Introspection; |
72 | 74 | import org.apache.catalina.util.ServerInfo; |
73 | 75 | import org.apache.catalina.util.URLEncoder; |
| 76 | +import org.apache.juli.logging.Log; |
| 77 | +import org.apache.juli.logging.LogFactory; |
74 | 78 | import org.apache.tomcat.util.ExceptionUtils; |
75 | 79 | import org.apache.tomcat.util.buf.CharChunk; |
76 | 80 | import org.apache.tomcat.util.buf.MessageBytes; |
77 | 81 | import org.apache.tomcat.util.buf.UDecoder; |
78 | 82 | import org.apache.tomcat.util.descriptor.web.FilterDef; |
79 | 83 | import org.apache.tomcat.util.http.RequestUtil; |
| 84 | +import org.apache.tomcat.util.http.fileupload.ProgressListenerFactory; |
80 | 85 | import org.apache.tomcat.util.res.StringManager; |
81 | 86 |
|
82 | 87 |
|
|
89 | 94 | */ |
90 | 95 | public class ApplicationContext implements ServletContext { |
91 | 96 |
|
| 97 | + private static final Log log = LogFactory.getLog(Request.class); |
| 98 | + |
92 | 99 | // ----------------------------------------------------------- Constructors |
93 | 100 |
|
94 | 101 | /** |
@@ -146,6 +153,11 @@ public ApplicationContext(StandardContext context) { |
146 | 153 | private final Map<String,String> parameters = new ConcurrentHashMap<>(); |
147 | 154 |
|
148 | 155 |
|
| 156 | + /** |
| 157 | + * The ProgressListenerFactory used to create {@link org.apache.tomcat.util.http.fileupload.ProgressListener} |
| 158 | + */ |
| 159 | + private ProgressListenerFactory progressListenerFactory; |
| 160 | + |
149 | 161 | /** |
150 | 162 | * The string manager for this package. |
151 | 163 | */ |
@@ -1161,6 +1173,30 @@ protected StandardContext getContext() { |
1161 | 1173 | return this.context; |
1162 | 1174 | } |
1163 | 1175 |
|
| 1176 | + public ProgressListenerFactory getProgressListenerFactory() { |
| 1177 | + if (progressListenerFactory == null) { |
| 1178 | + progressListenerFactory = newProgressListenerFactory(); |
| 1179 | + } |
| 1180 | + return progressListenerFactory; |
| 1181 | + } |
| 1182 | + |
| 1183 | + private ProgressListenerFactory newProgressListenerFactory() { |
| 1184 | + String progressListenerFactoryClassName = getInitParameter(ProgressListenerFactory.FACTORY_NAME); |
| 1185 | + if (progressListenerFactoryClassName == null || progressListenerFactoryClassName.isEmpty()) { |
| 1186 | + log.warn(sm.getString("applicationContext.no.upload.progressListenerFactory", progressListenerFactoryClassName)); |
| 1187 | + return ProgressListenerFactory.NULL_FACTORY; |
| 1188 | + } |
| 1189 | + try { |
| 1190 | + Class<?> progressListenerFactoryClass = Introspection.loadClass(context, progressListenerFactoryClassName); |
| 1191 | + Constructor<?> ctor = progressListenerFactoryClass.getConstructor(); |
| 1192 | + return (ProgressListenerFactory) ctor.newInstance(); |
| 1193 | + } catch (InvocationTargetException | NoSuchMethodException | InstantiationException |
| 1194 | + | ClassCastException | IllegalAccessException e) { |
| 1195 | + log.error(sm.getString("applicationContext.invalid.progressListenerFactory", progressListenerFactoryClassName), e); |
| 1196 | + return ProgressListenerFactory.NULL_FACTORY; |
| 1197 | + } |
| 1198 | + } |
| 1199 | + |
1164 | 1200 | /** |
1165 | 1201 | * Clear all application-created attributes. |
1166 | 1202 | */ |
|
0 commit comments