File tree Expand file tree Collapse file tree
tomcat/util/http/fileupload Expand file tree Collapse file tree Original file line number Diff line number Diff line change 111111import org .apache .tomcat .util .http .ServerCookies ;
112112import org .apache .tomcat .util .http .fileupload .FileItem ;
113113import org .apache .tomcat .util .http .fileupload .FileUpload ;
114+ import org .apache .tomcat .util .http .fileupload .ProgressListenerFactory ;
114115import org .apache .tomcat .util .http .fileupload .disk .DiskFileItemFactory ;
115116import org .apache .tomcat .util .http .fileupload .impl .InvalidContentTypeException ;
116117import org .apache .tomcat .util .http .fileupload .impl .SizeException ;
@@ -2491,7 +2492,10 @@ private void parseParts() {
24912492 FileUpload upload = new FileUpload ();
24922493 // allow applications to register custom progress listeners
24932494 if (servletContext instanceof ApplicationContextFacade applicationContext ) {
2494- upload .setProgressListener (applicationContext .getProgressListenerFactory ().newProgressListener ());
2495+ ProgressListenerFactory progressListenerFactory = applicationContext .getProgressListenerFactory ();
2496+ if (progressListenerFactory != null ) {
2497+ upload .setProgressListener (progressListenerFactory .newProgressListener (this .getRequest ()));
2498+ }
24952499 }
24962500 upload .setFileItemFactory (factory );
24972501 upload .setFileSizeMax (mce .getMaxFileSize ());
Original file line number Diff line number Diff line change @@ -1184,7 +1184,7 @@ private ProgressListenerFactory newProgressListenerFactory() {
11841184 String progressListenerFactoryClassName = getInitParameter (ProgressListenerFactory .FACTORY_NAME );
11851185 if (progressListenerFactoryClassName == null || progressListenerFactoryClassName .isEmpty ()) {
11861186 log .warn (sm .getString ("applicationContext.no.upload.progressListenerFactory" , progressListenerFactoryClassName ));
1187- return ProgressListenerFactory . NULL_FACTORY ;
1187+ return null ;
11881188 }
11891189 try {
11901190 Class <?> progressListenerFactoryClass = Introspection .loadClass (context , progressListenerFactoryClassName );
@@ -1193,7 +1193,7 @@ private ProgressListenerFactory newProgressListenerFactory() {
11931193 } catch (InvocationTargetException | NoSuchMethodException | InstantiationException
11941194 | ClassCastException | IllegalAccessException e ) {
11951195 log .error (sm .getString ("applicationContext.invalid.progressListenerFactory" , progressListenerFactoryClassName ), e );
1196- return ProgressListenerFactory . NULL_FACTORY ;
1196+ return null ;
11971197 }
11981198 }
11991199
Original file line number Diff line number Diff line change 1717
1818package org .apache .tomcat .util .http .fileupload ;
1919
20+ import jakarta .servlet .http .HttpServletRequest ;
21+
2022/**
2123 * Factory for {@link ProgressListener}. Users can specify this via a System property. See FACTORY_NAME
2224 */
@@ -27,20 +29,10 @@ public interface ProgressListenerFactory {
2729 */
2830 String FACTORY_NAME = "tomcat.fileUploadProgressListenerFactory" ;
2931
30- /**
31- * Factory that creates no listeners. To avoid null checks in code.
32- */
33- ProgressListenerFactory NULL_FACTORY = new ProgressListenerFactory () {
34- @ Override
35- public ProgressListener newProgressListener () {
36- return null ;
37- }
38- };
39-
4032
4133 /**
4234 * @return returns a new {@link ProgressListener} for current request.
4335 */
44- ProgressListener newProgressListener ();
36+ ProgressListener newProgressListener (HttpServletRequest servletRequest );
4537
4638}
You can’t perform that action at this time.
0 commit comments