enapps-enorman commented on code in PR #75:
URL: 
https://github.com/apache/sling-org-apache-sling-engine/pull/75#discussion_r3253348016


##########
src/main/java/org/apache/sling/engine/impl/parameters/RequestPartsIterator.java:
##########
@@ -20,61 +20,62 @@
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
-import java.util.List;
 
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
 import jakarta.servlet.http.Part;
-import org.apache.commons.fileupload.FileItemIterator;
-import org.apache.commons.fileupload.FileItemStream;
-import org.apache.commons.fileupload.FileUpload;
-import org.apache.commons.fileupload.FileUploadException;
-import org.apache.commons.fileupload.RequestContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Contains a Lazy iterator of Parts from the request stream loaded as the 
request is streamed using the Commons FileUpload API.
+ * Contains a Lazy iterator of Parts from the request stream loaded as the 
request is streamed
  */
 public class RequestPartsIterator implements Iterator<Part> {
-    private static final Logger LOG = 
LoggerFactory.getLogger(RequestPartsIterator.class);
+    private final Logger log = LoggerFactory.getLogger(getClass());
 
-    /** The CommonsFile Upload streaming API iterator */
-    private final FileItemIterator itemIterator;
+    /** The Parts iterator */
+    private Iterator<Part> itemIterator = null;
+
+    /** supplier to retrieve the parts when needed */
+    private final HttpServletRequest request;
 
     /**
-     * Create and initialse the iterator using the request. The request must 
be fresh. Headers can have been read but the stream
-     * must not have been parsed.
-     * @param servletRequest the request
-     * @throws IOException when there is a problem reading the request.
-     * @throws FileUploadException when there is a problem parsing the request.
+     * Create and initialize the iterator using the request.
+     *
+     * @param request the current request
      */
-    public RequestPartsIterator(final RequestContext context) throws 
FileUploadException, IOException {
-        FileUpload upload = new FileUpload();
-        upload.setFileCountMax(50);
-        itemIterator = upload.getItemIterator(context);
+    public RequestPartsIterator(final HttpServletRequest request) {
+        this.request = request;
     }
 
     @Override
     public boolean hasNext() {
-        try {
-            return itemIterator.hasNext();
-        } catch (final FileUploadException | IOException e) {
-            LOG.error("hasNext Item failed cause:" + e.getMessage(), e);
+        // Use a lazy data iterator creation the first time it is needed to 
ensure
+        // the container doesn't parse the uploaded files until necessary
+        if (itemIterator == null) {
+            Collection<Part> parts;
+            try {
+                parts = request.getParts();

Review Comment:
   I suppose it is up to the servlet container how the returned collection of 
parts object is implemented.  I'd need to do some more research to understand 
how jetty does it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to