[ACS-5424] replace usage of apache fileupload dependency

This commit is contained in:
kcichonczyk
2023-06-20 13:14:39 +02:00
parent e48c68c86c
commit 6e25451c13
10 changed files with 69 additions and 94 deletions

View File

@@ -1,57 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.alfresco</groupId>
<artifactId>binary-transformed-to-jakarta</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload-jakarta</artifactId>
<packaging>jar</packaging>
<version>1.5</version>
<licenses>
<license>
<name>Apache 2</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.5</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.transformer</groupId>
<artifactId>transformer-maven-plugin</artifactId>
<executions>
<execution>
<id>transform-jar</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<artifact>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</artifact>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -32,6 +32,5 @@
<modules> <modules>
<module>apache-chemistry</module> <module>apache-chemistry</module>
<module>commons-fileupload-jakarta</module>
</modules> </modules>
</project> </project>

View File

@@ -20,7 +20,7 @@ function clone_and_install {
mvn -f $project_path -B clean install -DskipTests -Dmaven.javadoc.skip=true mvn -f $project_path -B clean install -DskipTests -Dmaven.javadoc.skip=true
} }
clone_and_install surf-webscripts clone_and_install surf-webscripts "feature/acs-5424_apache_fileupload_replace"
clone_and_install alfresco-greenmail clone_and_install alfresco-greenmail
clone_and_install alfresco-tas-utility clone_and_install alfresco-tas-utility
clone_and_install alfresco-tas-email clone_and_install alfresco-tas-email

View File

@@ -423,11 +423,6 @@
<artifactId>commons-digester</artifactId> <artifactId>commons-digester</artifactId>
<version>2.1</version> <version>2.1</version>
</dependency> </dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload-jakarta</artifactId>
<version>1.5</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>

View File

@@ -32,7 +32,6 @@ import jakarta.servlet.http.HttpServletRequest;
import org.alfresco.service.cmr.transfer.TransferException; import org.alfresco.service.cmr.transfer.TransferException;
import org.alfresco.service.cmr.transfer.TransferReceiver; import org.alfresco.service.cmr.transfer.TransferReceiver;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.Status;

View File

@@ -0,0 +1,42 @@
/*
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2023 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.repo.web.scripts.transfer;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.http.MediaType;
public class CommandProcessorUtils
{
public static boolean isMultipartContent(HttpServletRequest servletRequest)
{
if(!servletRequest.getMethod().equalsIgnoreCase("post"))
{
return false;
}
String contentType = servletRequest.getContentType();
return contentType != null && contentType.toLowerCase().startsWith(MediaType.MULTIPART_FORM_DATA_VALUE);
}
}

View File

@@ -30,17 +30,19 @@ import jakarta.servlet.http.HttpServletRequest;
import org.alfresco.service.cmr.transfer.TransferException; import org.alfresco.service.cmr.transfer.TransferException;
import org.alfresco.service.cmr.transfer.TransferReceiver; import org.alfresco.service.cmr.transfer.TransferReceiver;
import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest; import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse; import org.springframework.extensions.webscripts.WebScriptResponse;
import org.springframework.extensions.webscripts.WrappingWebScriptRequest; import org.springframework.extensions.webscripts.WrappingWebScriptRequest;
import org.springframework.extensions.webscripts.servlet.FormData;
import org.springframework.extensions.webscripts.servlet.WebScriptServletRequest; import org.springframework.extensions.webscripts.servlet.WebScriptServletRequest;
import org.springframework.extensions.webscripts.servlet.FormData.FormField;
import java.util.Arrays;
import java.util.Iterator;
import static org.alfresco.repo.web.scripts.transfer.CommandProcessorUtils.isMultipartContent;
/** /**
* This command processor is used to receive one or more content files for a given transfer. * This command processor is used to receive one or more content files for a given transfer.
@@ -105,7 +107,7 @@ public class PostContentCommandProcessor implements CommandProcessor
//Read the transfer id from the request //Read the transfer id from the request
String transferId = servletRequest.getParameter("transferId"); String transferId = servletRequest.getParameter("transferId");
if ((transferId == null) || !ServletFileUpload.isMultipartContent(servletRequest)) if ((transferId == null) || !isMultipartContent(servletRequest))
{ {
resp.setStatus(Status.STATUS_BAD_REQUEST); resp.setStatus(Status.STATUS_BAD_REQUEST);
return Status.STATUS_BAD_REQUEST; return Status.STATUS_BAD_REQUEST;
@@ -114,16 +116,15 @@ public class PostContentCommandProcessor implements CommandProcessor
try try
{ {
ServletFileUpload upload = new ServletFileUpload(); FormData formData = new FormData(servletRequest);
FileItemIterator iter = upload.getItemIterator(servletRequest); Iterator<FormData.FormField> iter = Arrays.stream(formData.getFields()).iterator();
while (iter.hasNext()) while (iter.hasNext())
{ {
FileItemStream item = iter.next(); FormData.FormField formField = iter.next();
String name = item.getFieldName(); if (formField.getIsFile())
if (!item.isFormField())
{ {
logger.debug("got content Mime Part : " + name); logger.debug("got content Mime Part : " + formField.getName());
receiver.saveContent(transferId, item.getName(), item.openStream()); receiver.saveContent(transferId, formField.getFilename(), formField.getInputStream());
} }
} }

View File

@@ -27,24 +27,26 @@
package org.alfresco.repo.web.scripts.transfer; package org.alfresco.repo.web.scripts.transfer;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Arrays;
import java.util.Iterator;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import org.alfresco.repo.transfer.TransferCommons; import org.alfresco.repo.transfer.TransferCommons;
import org.alfresco.service.cmr.transfer.TransferException; import org.alfresco.service.cmr.transfer.TransferException;
import org.alfresco.service.cmr.transfer.TransferReceiver; import org.alfresco.service.cmr.transfer.TransferReceiver;
import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest; import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse; import org.springframework.extensions.webscripts.WebScriptResponse;
import org.springframework.extensions.webscripts.WrappingWebScriptRequest; import org.springframework.extensions.webscripts.WrappingWebScriptRequest;
import org.springframework.extensions.webscripts.servlet.FormData;
import org.springframework.extensions.webscripts.servlet.WebScriptServletRequest; import org.springframework.extensions.webscripts.servlet.WebScriptServletRequest;
import org.springframework.extensions.webscripts.servlet.FormData.FormField; import org.springframework.extensions.webscripts.servlet.FormData.FormField;
import static org.alfresco.repo.web.scripts.transfer.CommandProcessorUtils.isMultipartContent;
/** /**
* This command processor is used to receive the snapshot for a given transfer. * This command processor is used to receive the snapshot for a given transfer.
* *
@@ -100,7 +102,7 @@ public class PostSnapshotCommandProcessor implements CommandProcessor
//Read the transfer id from the request //Read the transfer id from the request
String transferId = servletRequest.getParameter("transferId"); String transferId = servletRequest.getParameter("transferId");
if ((transferId == null) || !ServletFileUpload.isMultipartContent(servletRequest)) if ((transferId == null) || !isMultipartContent(servletRequest))
{ {
logger.debug("bad request, not multipart"); logger.debug("bad request, not multipart");
resp.setStatus(Status.STATUS_BAD_REQUEST); resp.setStatus(Status.STATUS_BAD_REQUEST);
@@ -111,15 +113,15 @@ public class PostSnapshotCommandProcessor implements CommandProcessor
{ {
logger.debug("about to upload manifest file"); logger.debug("about to upload manifest file");
ServletFileUpload upload = new ServletFileUpload(); FormData formData = new FormData(servletRequest);
FileItemIterator iter = upload.getItemIterator(servletRequest); Iterator<FormField> iter = Arrays.stream(formData.getFields()).iterator();
while (iter.hasNext()) while (iter.hasNext())
{ {
FileItemStream item = iter.next(); FormField formField = iter.next();
if (!item.isFormField() && TransferCommons.PART_NAME_MANIFEST.equals(item.getFieldName())) if (formField.getIsFile() && TransferCommons.PART_NAME_MANIFEST.equals(formField.getName()))
{ {
logger.debug("got manifest file"); logger.debug("got manifest file");
receiver.saveSnapshot(transferId, item.openStream()); receiver.saveSnapshot(transferId, formField.getInputStream());
} }
} }

View File

@@ -30,10 +30,8 @@ import java.io.StringWriter;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import org.alfresco.repo.transfer.TransferServiceImpl;
import org.alfresco.service.cmr.transfer.TransferException; import org.alfresco.service.cmr.transfer.TransferException;
import org.alfresco.service.cmr.transfer.TransferReceiver; import org.alfresco.service.cmr.transfer.TransferReceiver;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.Status;

View File

@@ -83,10 +83,6 @@
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId> <artifactId>commons-dbcp2</artifactId>
</dependency> </dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload-jakarta</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId> <artifactId>commons-compress</artifactId>