File fileupload2upgrade.patch of Package struts

Index: struts-1.2.9-src/src/share/org/apache/struts/upload/CommonsMultipartRequestHandler.java
===================================================================
--- struts-1.2.9-src.orig/src/share/org/apache/struts/upload/CommonsMultipartRequestHandler.java
+++ struts-1.2.9-src/src/share/org/apache/struts/upload/CommonsMultipartRequestHandler.java
@@ -25,15 +25,16 @@ import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.io.IOException;
 import java.io.Serializable;
+import java.nio.file.Paths;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
-import org.apache.commons.fileupload.FileItem;
-import org.apache.commons.fileupload.DiskFileUpload;
-import org.apache.commons.fileupload.FileUploadException;
+import org.apache.commons.fileupload2.core.FileItem;
+import org.apache.commons.fileupload2.core.DiskFileItemFactory;
+import org.apache.commons.fileupload2.javax.JavaxServletFileUpload;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.struts.action.ActionServlet;
@@ -163,50 +164,43 @@ public class CommonsMultipartRequestHand
      *
      * @throws ServletException if an unrecoverable error occurs.
      */
-    public void handleRequest(HttpServletRequest request)
-            throws ServletException {
 
+    public void handleRequest(HttpServletRequest request) throws ServletException {
+    
         // Get the app config for the current request.
-        ModuleConfig ac = (ModuleConfig) request.getAttribute(
-                Globals.MODULE_KEY);
-
-        // Create and configure a DIskFileUpload instance.
-        DiskFileUpload upload = new DiskFileUpload();
+        ModuleConfig ac = (ModuleConfig) request.getAttribute(Globals.MODULE_KEY);
+    
+        // Create the DiskFileItemFactory with custom settings.
+        DiskFileItemFactory factory = DiskFileItemFactory.builder()
+                .setBufferSize((int) getSizeThreshold(ac))
+                .setPath(Paths.get(getRepositoryPath(ac)))
+                .get();
+
+        // Create the JavaxServletFileUpload instance.
+        JavaxServletFileUpload upload = new JavaxServletFileUpload(factory);
+    
         // The following line is to support an "EncodingFilter"
-        // see http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23255
-        upload.setHeaderEncoding(request.getCharacterEncoding());
-        // Set the maximum size before a FileUploadException will be thrown.
-        upload.setSizeMax(getSizeMax(ac));
-        // Set the maximum size that will be stored in memory.
-        upload.setSizeThreshold((int) getSizeThreshold(ac));
-        // Set the the location for saving data on disk.
-        upload.setRepositoryPath(getRepositoryPath(ac));
-
+        upload.setHeaderCharset(java.nio.charset.Charset.forName(request.getCharacterEncoding()));
+    
+        // Set the maximum size before an exception will be thrown.
+        upload.setFileSizeMax(getSizeMax(ac));
+    
         // Create the hash tables to be populated.
-        elementsText = new Hashtable();
-        elementsFile = new Hashtable();
-        elementsAll = new Hashtable();
-
+        elementsText = new Hashtable<>();
+        elementsFile = new Hashtable<>();
+        elementsAll = new Hashtable<>();
+    
         // Parse the request into file items.
-        List items = null;
+        List<FileItem> items;
         try {
             items = upload.parseRequest(request);
-        } catch (DiskFileUpload.SizeLimitExceededException e) {
-            // Special handling for uploads that are too big.
-            request.setAttribute(
-                    MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED,
-                    Boolean.TRUE);
-            return;
-        } catch (FileUploadException e) {
+        } catch (IOException e) {
             log.error("Failed to parse multipart request", e);
             throw new ServletException(e);
         }
-
+    
         // Partition the items into form fields and files.
-        Iterator iter = items.iterator();
-        while (iter.hasNext()) {
-            FileItem item = (FileItem) iter.next();
-
+        for (FileItem item : items) {
             if (item.isFormField()) {
                 addTextParameter(request, item);
             } else {
@@ -215,7 +209,6 @@ public class CommonsMultipartRequestHand
         }
     }
 
-
     /**
      * Returns a hash table containing the text (that is, non-file) request
      * parameters.
@@ -409,7 +402,7 @@ public class CommonsMultipartRequestHand
 
         if (encoding != null) {
             try {
-                value = item.getString(encoding);
+                value = item.getString(java.nio.charset.Charset.forName(encoding));
                 haveValue = true;
             } catch (Exception e) {
                 // Handled below, since haveValue is false.
@@ -417,9 +410,14 @@ public class CommonsMultipartRequestHand
         }
         if (!haveValue) {
             try {
-                 value = item.getString("ISO-8859-1");
-            } catch (java.io.UnsupportedEncodingException uee) {
-                 value = item.getString();
+                 value = item.getString(java.nio.charset.Charset.forName("ISO-8859-1"));
+            } catch (IOException uee) {
+                 try {
+                     value = item.getString();
+                 }
+                 catch (IOException e) {
+                     value = "";
+                 }
             }
             haveValue = true;
         }
@@ -592,7 +590,11 @@ public class CommonsMultipartRequestHand
          * files or any temporary file data stored somewhere
          */
         public void destroy() {
-            fileItem.delete();
+            try {
+                fileItem.delete();
+            } catch (IOException e) {
+                    //
+            }
         }
 
 
Index: struts-1.2.9-src/build.xml
===================================================================
--- struts-1.2.9-src.orig/build.xml
+++ struts-1.2.9-src/build.xml
@@ -34,7 +34,7 @@
                                       Commons Digester package.
                                       [Version 1.5 or later]
 
-        commons-fileupload.jar        The path to the JAR file of the Jakarta
+        commons-fileupload2-core.jar        The path to the JAR file of the Jakarta
                                       Commons FileUpload package.
                                       [Version 1.0 or later]
 
@@ -213,7 +213,9 @@
     <path id="compile.classpath">
       <pathelement location="${commons-beanutils.jar}"/>
       <pathelement location="${commons-digester.jar}"/>
-      <pathelement location="${commons-fileupload.jar}"/>
+      <pathelement location="${commons-fileupload2-core.jar}"/>
+      <pathelement location="${commons-fileupload2-javax.jar}"/>
+      <pathelement location="${commons-io.jar}"/>
       <pathelement location="${commons-logging.jar}"/>
       <pathelement location="${commons-validator.jar}"/>
       <pathelement location="${jakarta-oro.jar}"/>
@@ -287,9 +289,9 @@
             usetimestamp="true" ignoreerrors="true"
             src="http://www.ibiblio.org/maven/commons-digester/jars/commons-digester-1.6.jar"/>
 
-        <get dest="${libdir}/commons-fileupload.jar"
+        <get dest="${libdir}/commons-fileupload2-core.jar"
             usetimestamp="true" ignoreerrors="true"
-            src="http://www.ibiblio.org/maven/commons-fileupload/jars/commons-fileupload-1.0.jar"/>
+            src="http://www.ibiblio.org/maven/commons-fileupload2-core.jars/commons-fileupload-1.0.jar"/>
 
         <get dest="${libdir}/commons-logging.jar"
             usetimestamp="true" ignoreerrors="true"
@@ -329,7 +331,9 @@
 
         <property name="commons-beanutils.jar"  value="${libdir}/commons-beanutils.jar"/>
         <property name="commons-digester.jar"   value="${libdir}/commons-digester.jar"/>
-        <property name="commons-fileupload.jar" value="${libdir}/commons-fileupload.jar"/>
+        <property name="commons-fileupload2-core.jar"   value="${libdir}/commons-fileupload2-core.jar"/>
+        <property name="commons-fileupload2-javax.jar"   value="${libdir}/commons-fileupload2-javax.jar"/>
+        <property name="commons-io.jar"   value="${libdir}/commons-io.jar"/>
         <property name="commons-logging.jar"    value="${libdir}/commons-logging.jar"/>
         <property name="commons-validator.jar"  value="${libdir}/commons-validator.jar"/>
         <property name="jakarta-oro.jar"        value="${libdir}/jakarta-oro.jar"/>
@@ -365,8 +369,12 @@
             tofile="${build.home}/library/commons-beanutils.jar"/>
         <copy file="${commons-digester.jar}"
             tofile="${build.home}/library/commons-digester.jar"/>
-        <copy file="${commons-fileupload.jar}"
-            tofile="${build.home}/library/commons-fileupload.jar"/>
+        <copy file="${commons-fileupload2-core.jar}"
+            tofile="${build.home}/library/commons-fileupload2-core.jar"/>
+        <copy file="${commons-fileupload2-javax.jar}"
+            tofile="${build.home}/library/commons-fileupload2-javax.jar"/>
+        <copy file="${commons-io.jar}"
+            tofile="${build.home}/library/commons-io.jar"/>
         <copy file="${commons-logging.jar}"
             tofile="${build.home}/library/commons-logging.jar"/>
         <copy file="${commons-validator.jar}"
Index: struts-1.2.9-src/build-webapp.xml
===================================================================
--- struts-1.2.9-src.orig/build-webapp.xml
+++ struts-1.2.9-src/build-webapp.xml
@@ -171,7 +171,9 @@
 <path id="classpath">
   <pathelement location="${commons-beanutils.jar}"/>
   <pathelement location="${commons-digester.jar}"/>
-  <pathelement location="${commons-fileupload.jar}"/>
+  <pathelement location="${commons-fileupload2-core.jar}"/>
+  <pathelement location="${commons-fileupload2-javax.jar}"/>
+  <pathelement location="${commons-io.jar}"/>
   <pathelement location="${commons-logging.jar}"/>
   <pathelement location="${commons-validator.jar}"/>
   <pathelement location="${servlet.jar}"/>
openSUSE Build Service is sponsored by