Skip to content

Commit

Permalink
Fixes piranhacloud#4185 - Update Apache Commons File Upload to latest…
Browse files Browse the repository at this point in the history
… version (piranhacloud#4201)
  • Loading branch information
mnriem authored Nov 11, 2024
1 parent 79ef513 commit 463aeda
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 99 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<version>24.11.0-SNAPSHOT</version>
</parent>

<artifactId>piranha-extension-apache-fileupload</artifactId>
<artifactId>piranha-extension-fileupload</artifactId>
<packaging>jar</packaging>

<name>Piranha - Extension - Apache Commons FileUpload</name>
<name>Piranha - Extension - File Upload</name>
<dependencies>
<!-- compile -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.apache.fileupload;
package cloud.piranha.extension.fileupload;

import cloud.piranha.core.api.WebApplication;
import cloud.piranha.core.api.WebApplicationExtension;
Expand All @@ -37,23 +37,22 @@
*
* @author Manfred Riem ([email protected])
*/
public class ApacheMultiPartExtension implements WebApplicationExtension {
public class FileUploadExtension implements WebApplicationExtension {

/**
* Stores the logger.
*/
private static final System.Logger LOGGER = System.getLogger(
ApacheMultiPartExtension.class.getName());
private static final System.Logger LOGGER = System.getLogger(FileUploadExtension.class.getName());

/**
* Constructor.
*/
public ApacheMultiPartExtension() {
public FileUploadExtension() {
}

@Override
public void configure(WebApplication webApplication) {
LOGGER.log(TRACE, "Configuring Apache Commons FileUpload extension");
webApplication.addInitializer(ApacheMultiPartInitializer.class.getName());
webApplication.addInitializer(FileUploadMultiPartInitializer.class.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.apache.fileupload;
package cloud.piranha.extension.fileupload;

import jakarta.servlet.http.Part;
import java.io.File;
Expand All @@ -45,7 +45,7 @@
*
* @author Manfred Riem ([email protected])
*/
public class ApacheMultiPart implements Part {
public class FileUploadMultiPart implements Part {

/**
* Stores the item.
Expand All @@ -57,7 +57,7 @@ public class ApacheMultiPart implements Part {
*
* @param item the file item.
*/
public ApacheMultiPart(FileItem item) {
public FileUploadMultiPart(FileItem item) {
this.item = item;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.apache.fileupload;
package cloud.piranha.extension.fileupload;

import cloud.piranha.core.api.WebApplication;
import jakarta.servlet.ServletContainerInitializer;
Expand All @@ -43,24 +43,24 @@
* </p>
*
* <ol>
* <li>Sets the MultiPartManager to an instance of ApacheMultiPartManager.</li>
* <li>Sets the MultiPartManager to an instance of FileUploadMultiPartManager.</li>
* <li>Adds the JakartaFileCleaner listener that cleans up the temporary files.</li>
* </ol>
*
* @author Manfred Riem ([email protected])
*/
public class ApacheMultiPartInitializer implements ServletContainerInitializer {
public class FileUploadMultiPartInitializer implements ServletContainerInitializer {

/**
* Stores the logger.
*/
private static final Logger LOGGER = System.getLogger(ApacheMultiPartInitializer.class.getName());
private static final Logger LOGGER = System.getLogger(FileUploadMultiPartInitializer.class.getName());

@Override
public void onStartup(Set<Class<?>> classes, ServletContext servletContext) throws ServletException {
LOGGER.log(TRACE, "Setting ApacheMultiPartManager");
WebApplication webApplication = (WebApplication) servletContext;
webApplication.getManager().setMultiPartManager(new ApacheMultiPartManager());
webApplication.getManager().setMultiPartManager(new FileUploadMultiPartManager());
webApplication.addListener("org.apache.commons.fileupload2.jakarta.servlet6.JakartaFileCleaner");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.apache.fileupload;
package cloud.piranha.extension.fileupload;

import cloud.piranha.core.api.MultiPartManager;
import cloud.piranha.core.api.WebApplication;
Expand All @@ -50,24 +50,24 @@
* The ApacheMultiPartManager.
*
* <p>
* The ApacheMultiPartManager implements the MultiPartManager API that delivers
* file upload functionality to a web application by delegating to Apache
* Commons File Upload.
* </p>
The FileUploadMultiPartManager implements the MultiPartManager API that delivers
file upload functionality to a web application by delegating to Apache
Commons File Upload.
</p>
*
* @author Manfred Riem ([email protected])
*/
public class ApacheMultiPartManager implements MultiPartManager {
public class FileUploadMultiPartManager implements MultiPartManager {

/**
* Stores the logger.
*/
private static final Logger LOGGER = System.getLogger(ApacheMultiPartManager.class.getName());
private static final Logger LOGGER = System.getLogger(FileUploadMultiPartManager.class.getName());

/**
* Constructor.
*/
public ApacheMultiPartManager() {
public FileUploadMultiPartManager() {
}

@SuppressWarnings("unchecked")
Expand All @@ -85,7 +85,7 @@ public Collection<Part> getParts(WebApplication webApplication, WebApplicationRe
try {
setupFileUpload(webApplication, request.getMultipartConfig())
.parseRequest((HttpServletRequest) request)
.forEach(item -> newParts.add(new ApacheMultiPart((FileItem) item)));
.forEach(item -> newParts.add(new FileUploadMultiPart((FileItem) item)));
} catch (FileUploadException fue) {
LOGGER.log(WARNING, "Error getting part", fue);
}
Expand Down Expand Up @@ -118,7 +118,7 @@ public Part getPart(WebApplication webApplication, WebApplicationRequest request
* @return the JakartServletFileUpload instance.
*/
private synchronized JakartaServletFileUpload setupFileUpload(WebApplication webApplication, MultipartConfigElement multipartConfig) {
JakartaServletFileUpload upload = (JakartaServletFileUpload) webApplication.getAttribute(ApacheMultiPartManager.class.getName());
JakartaServletFileUpload upload = (JakartaServletFileUpload) webApplication.getAttribute(FileUploadMultiPartManager.class.getName());
if (upload == null) {
File outputDirectory;
if (multipartConfig.getLocation() == null || multipartConfig.getLocation().isEmpty()) {
Expand All @@ -140,7 +140,7 @@ private synchronized JakartaServletFileUpload setupFileUpload(WebApplication web
.setFile(outputDirectory)
.get();
upload = new JakartaServletFileUpload(factory);
webApplication.setAttribute(ApacheMultiPartManager.class.getName(), upload);
webApplication.setAttribute(FileUploadMultiPartManager.class.getName(), upload);
}
return upload;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,16 @@
*/

/**
* This module delivers the file upload extension using Apache Commons FileUpload.
*
* <p>
* See https://github.com/apache/commons-fileupload for more information about
* its project.
* </p>
* This module delivers the file upload functionality using Apache Commons
* FileUpload. See https://github.com/apache/commons-fileupload for more
* information.
*
* @author Manfred Riem ([email protected])
*/
module cloud.piranha.extension.apache.fileupload {
module cloud.piranha.extension.fileupload {

exports cloud.piranha.extension.apache.fileupload;
opens cloud.piranha.extension.apache.fileupload;
exports cloud.piranha.extension.fileupload;
opens cloud.piranha.extension.fileupload;
requires cloud.piranha.core.api;
requires org.apache.commons.fileupload2.core;
requires org.apache.commons.fileupload2.jakarta.servlet6;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.apache.fileupload;
package cloud.piranha.extension.fileupload;

import cloud.piranha.core.impl.DefaultWebApplication;
import cloud.piranha.core.impl.DefaultWebApplicationRequest;
Expand All @@ -35,11 +35,11 @@
import org.junit.jupiter.api.Test;

/**
* The JUnit tests for the ApacheMultiPartManager class.
* The JUnit tests for the FileUploadMultiPartManager class.
*
* @author Manfred Riem ([email protected])
*/
class ApacheMultiPartManagerTest {
class FileUploadMultiPartManagerTest {

/**
* Test getPart method.
Expand All @@ -53,7 +53,7 @@ void testGetPart() throws Exception {
request.setMultipartConfig(new MultipartConfigElement(new File("target").getAbsolutePath()));
request.setContentType("multipart/form-data");
request.setMethod("POST");
ApacheMultiPartManager manager = new ApacheMultiPartManager();
FileUploadMultiPartManager manager = new FileUploadMultiPartManager();
assertNull(manager.getPart(application, request, "part_test"));
}
}
2 changes: 1 addition & 1 deletion extension/micro/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</dependency>
<dependency>
<groupId>cloud.piranha.extension</groupId>
<artifactId>piranha-extension-apache-fileupload</artifactId>
<artifactId>piranha-extension-fileupload</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
import cloud.piranha.core.api.WebApplication;
import cloud.piranha.core.api.WebApplicationExtension;
import cloud.piranha.core.api.WebApplicationExtensionContext;
import cloud.piranha.extension.apache.fileupload.ApacheMultiPartExtension;
import cloud.piranha.extension.datasource.DefaultDatasourceExtension;
import cloud.piranha.extension.eclipselink.EclipseLinkExtension;
import cloud.piranha.extension.exousia.AuthorizationPostInitializer;
import cloud.piranha.extension.fileupload.FileUploadExtension;
import cloud.piranha.extension.naming.cdi.NamingExtension;
import cloud.piranha.extension.policy.PolicyExtension;
import cloud.piranha.extension.scinitializer.ServletContainerInitializerExtension;
Expand Down Expand Up @@ -63,7 +63,7 @@ public void extend(WebApplicationExtensionContext context) {
context.add(TempDirExtension.class); // TEMPDIR
context.add(WelcomeFileExtension.class); // welcome-file
context.add(ServletSecurityManagerExtension.class); // Servlet security
context.add(ApacheMultiPartExtension.class); // Upload
context.add(FileUploadExtension.class); // Upload
context.add(WebXmlExtension.class); // web.xml
context.add(ServletAnnotationsExtension.class); // Servlet annotations
context.add(NamingExtension.class); // Naming (JNDI)
Expand Down
2 changes: 1 addition & 1 deletion extension/micro/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
opens cloud.piranha.extension.micro;
provides WebApplicationExtension with MicroExtension;
requires cloud.piranha.core.api;
requires cloud.piranha.extension.apache.fileupload;
requires cloud.piranha.extension.fileupload;
requires cloud.piranha.extension.datasource;
requires cloud.piranha.extension.eclipselink;
requires cloud.piranha.extension.exousia;
Expand Down
2 changes: 1 addition & 1 deletion extension/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<modules>
<module>annotationscan</module>
<module>annotationscan-classfile</module>
<module>apache-fileupload</module>
<module>bytesstreamhandler</module>
<module>compat-glassfish7x</module>
<module>compat-tomcat10x</module>
Expand All @@ -30,6 +29,7 @@
<module>eclipse-jstl</module>
<module>eclipselink</module>
<module>expressly</module>
<module>fileupload</module>
<module>hazelcast</module>
<module>herring</module>
<module>hibernate-validator</module>
Expand Down
2 changes: 1 addition & 1 deletion extension/servlet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</dependency>
<dependency>
<groupId>cloud.piranha.extension</groupId>
<artifactId>piranha-extension-apache-fileupload</artifactId>
<artifactId>piranha-extension-fileupload</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import cloud.piranha.core.api.WebApplicationExtensionContext;
import cloud.piranha.extension.annotationscan.AnnotationScanExtension;
import cloud.piranha.extension.annotationscan.classfile.ClassfileAnnotationScanExtension;
import cloud.piranha.extension.apache.fileupload.ApacheMultiPartExtension;
import cloud.piranha.extension.fileupload.FileUploadExtension;
import cloud.piranha.extension.herring.HerringExtension;
import cloud.piranha.extension.policy.PolicyExtension;
import cloud.piranha.extension.scinitializer.ServletContainerInitializerExtension;
Expand All @@ -58,7 +58,7 @@ public void extend(WebApplicationExtensionContext context) {
context.add(TempDirExtension.class); // TEMPDIR
context.add(WelcomeFileExtension.class); // welcome-file
context.add(ServletSecurityManagerExtension.class); // SecurityManager
context.add(ApacheMultiPartExtension.class); // Servlet Part API support
context.add(FileUploadExtension.class); // Servlet Part API support
context.add(WaspJspManagerExtension.class); // addJspFile
context.add(HerringExtension.class); // Herring (JNDI)
context.add(WebXmlExtension.class); // web.xml
Expand Down
4 changes: 2 additions & 2 deletions extension/servlet/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* </p>
* <ul>
* <li>Annotation Scanning</li>
* <li>Apache Commons File Upload (Multipart)</li>
* <li>File Upload</li>
* <li>Herring (JNDI)</li>
* <li>Java Policy</li>
* <li>ServletContainerInitializer</li>
Expand All @@ -54,7 +54,7 @@
requires cloud.piranha.core.api;
requires cloud.piranha.extension.annotationscan;
requires cloud.piranha.extension.annotationscan.classfile;
requires cloud.piranha.extension.apache.fileupload;
requires cloud.piranha.extension.fileupload;
requires cloud.piranha.extension.herring;
requires cloud.piranha.extension.tomcat10x;
requires cloud.piranha.extension.expressly;
Expand Down
2 changes: 1 addition & 1 deletion extension/webprofile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</dependency>
<dependency>
<groupId>cloud.piranha.extension</groupId>
<artifactId>piranha-extension-apache-fileupload</artifactId>
<artifactId>piranha-extension-fileupload</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
Expand Down
Loading

0 comments on commit 463aeda

Please sign in to comment.