From 9c05f8527b7cc50f8be88b09feea2b81590606ce Mon Sep 17 00:00:00 2001 From: mbfreder Date: Fri, 28 Apr 2023 14:22:26 -0700 Subject: [PATCH 1/2] refactor: temporarily removing fileupload support until release version is available (https://issues.apache.org/jira/browse/FILEUPLOAD-309) --- aws-serverless-java-container-core/pom.xml | 6 +-- .../servlet/AwsHttpServletRequest.java | 39 +------------------ .../AwsProxyHttpServletRequestFormTest.java | 6 ++- .../testutils/AwsProxyRequestBuilder.java | 7 +--- .../proxy/jersey/JerseyParamEncodingTest.java | 1 + .../proxy/spring/SpringAwsProxyTest.java | 2 + 6 files changed, 13 insertions(+), 48 deletions(-) diff --git a/aws-serverless-java-container-core/pom.xml b/aws-serverless-java-container-core/pom.xml index 9d8b5a138..26bafa9a3 100644 --- a/aws-serverless-java-container-core/pom.xml +++ b/aws-serverless-java-container-core/pom.xml @@ -67,9 +67,9 @@ - org.apache.commons - commons-fileupload2 - 2.0-SNAPSHOT + commons-io + commons-io + 2.11.0 diff --git a/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsHttpServletRequest.java b/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsHttpServletRequest.java index 99b2782c5..44fd84a96 100644 --- a/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsHttpServletRequest.java +++ b/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsHttpServletRequest.java @@ -22,11 +22,6 @@ import com.amazonaws.serverless.proxy.model.MultiValuedTreeMap; import com.amazonaws.services.lambda.runtime.Context; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import org.apache.commons.fileupload2.FileItem; -import org.apache.commons.fileupload2.FileUploadException; -import org.apache.commons.fileupload2.disk.DiskFileItemFactory; -import org.apache.commons.fileupload2.jaksrvlt.JakSrvltFileUpload; -import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.io.input.NullInputStream; import org.slf4j.Logger; @@ -508,39 +503,7 @@ protected Map> getFormUrlEncodedParametersMap() { @SuppressFBWarnings({"FILE_UPLOAD_FILENAME", "WEAK_FILENAMEUTILS"}) protected Map getMultipartFormParametersMap() { - if (multipartFormParameters != null) { - return multipartFormParameters; - } - if (!JakSrvltFileUpload.isMultipartContent(this)) { // isMultipartContent also checks the content type - multipartFormParameters = new HashMap<>(); - return multipartFormParameters; - } - Timer.start("SERVLET_REQUEST_GET_MULTIPART_PARAMS"); - multipartFormParameters = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - - JakSrvltFileUpload upload = new JakSrvltFileUpload(new DiskFileItemFactory()); - - try { - List items = upload.parseRequest(this); - for (FileItem item : items) { - String fileName = FilenameUtils.getName(item.getName()); - AwsProxyRequestPart newPart = new AwsProxyRequestPart(item.get()); - newPart.setName(item.getFieldName()); - newPart.setSubmittedFileName(fileName); - newPart.setContentType(item.getContentType()); - newPart.setSize(item.getSize()); - item.getHeaders().getHeaderNames().forEachRemaining(h -> { - newPart.addHeader(h, item.getHeaders().getHeader(h)); - }); - - multipartFormParameters.put(item.getFieldName(), newPart); - } - } catch (FileUploadException e) { - Timer.stop("SERVLET_REQUEST_GET_MULTIPART_PARAMS"); - log.error("Could not read multipart upload file", e); - } - Timer.stop("SERVLET_REQUEST_GET_MULTIPART_PARAMS"); - return multipartFormParameters; + throw new UnsupportedOperationException(); } protected String[] getQueryParamValues(MultiValuedTreeMap qs, String key, boolean isCaseSensitive) { diff --git a/aws-serverless-java-container-core/src/test/java/com/amazonaws/serverless/proxy/internal/servlet/AwsProxyHttpServletRequestFormTest.java b/aws-serverless-java-container-core/src/test/java/com/amazonaws/serverless/proxy/internal/servlet/AwsProxyHttpServletRequestFormTest.java index 79bfa6cd3..efe32ba2a 100644 --- a/aws-serverless-java-container-core/src/test/java/com/amazonaws/serverless/proxy/internal/servlet/AwsProxyHttpServletRequestFormTest.java +++ b/aws-serverless-java-container-core/src/test/java/com/amazonaws/serverless/proxy/internal/servlet/AwsProxyHttpServletRequestFormTest.java @@ -7,7 +7,8 @@ import org.apache.commons.io.IOUtils; import org.apache.hc.core5.http.ContentType; import org.apache.hc.core5.http.HttpEntity; -import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;; +import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import jakarta.servlet.ServletException; @@ -51,6 +52,7 @@ public class AwsProxyHttpServletRequestFormTest { .build(); private static final String ENCODED_FORM_ENTITY = PART_KEY_1 + "=" + ENCODED_VALUE + "&" + PART_KEY_2 + "=" + PART_VALUE_2; + @Disabled("Disabled until new release of commons-fileupload based on Jakarta APIs") @Test void postForm_getParam_getEncodedFullValue() { try { @@ -67,6 +69,7 @@ void postForm_getParam_getEncodedFullValue() { } } + @Disabled("Disabled until new release of commons-fileupload based on Jakarta APIs") @Test void postForm_getParts_parsing() { try { @@ -86,6 +89,7 @@ void postForm_getParts_parsing() { } } + @Disabled("Disabled until new release of commons-fileupload based on Jakarta APIs") @Test void multipart_getParts_binary() { try { diff --git a/aws-serverless-java-container-core/src/test/java/com/amazonaws/serverless/proxy/internal/testutils/AwsProxyRequestBuilder.java b/aws-serverless-java-container-core/src/test/java/com/amazonaws/serverless/proxy/internal/testutils/AwsProxyRequestBuilder.java index 9df66a891..725fada8f 100644 --- a/aws-serverless-java-container-core/src/test/java/com/amazonaws/serverless/proxy/internal/testutils/AwsProxyRequestBuilder.java +++ b/aws-serverless-java-container-core/src/test/java/com/amazonaws/serverless/proxy/internal/testutils/AwsProxyRequestBuilder.java @@ -155,12 +155,7 @@ public AwsProxyRequestBuilder form(String key, String value) { } public AwsProxyRequestBuilder formFilePart(String fieldName, String fileName, byte[] content) throws IOException { - if (multipartBuilder == null) { - multipartBuilder = MultipartEntityBuilder.create(); - } - multipartBuilder.addPart(fieldName, new ByteArrayBody(content, fileName)); - buildMultipartBody(); - return this; + throw new UnsupportedOperationException(); } public AwsProxyRequestBuilder formTextFieldPart(String fieldName, String fieldValue) diff --git a/aws-serverless-java-container-jersey/src/test/java/com/amazonaws/serverless/proxy/jersey/JerseyParamEncodingTest.java b/aws-serverless-java-container-jersey/src/test/java/com/amazonaws/serverless/proxy/jersey/JerseyParamEncodingTest.java index 9dc1ab32a..6c575da6c 100644 --- a/aws-serverless-java-container-jersey/src/test/java/com/amazonaws/serverless/proxy/jersey/JerseyParamEncodingTest.java +++ b/aws-serverless-java-container-jersey/src/test/java/com/amazonaws/serverless/proxy/jersey/JerseyParamEncodingTest.java @@ -263,6 +263,7 @@ void queryParam_listOfString_expectCorrectLength(String reqType) { validateSingleValueModel(resp, "3"); } + @Disabled("Disabled until new release of commons-fileupload based on Jakarta APIs") @MethodSource("data") @ParameterizedTest void multipart_getFileSize_expectCorrectLength(String reqType) diff --git a/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/SpringAwsProxyTest.java b/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/SpringAwsProxyTest.java index 1101efc8c..f78d43812 100644 --- a/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/SpringAwsProxyTest.java +++ b/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/SpringAwsProxyTest.java @@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.codec.binary.Base64; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import org.springframework.web.servlet.DispatcherServlet; @@ -468,6 +469,7 @@ void contextPath_generateLink_returnsCorrectPath(String reqType) { SpringLambdaContainerHandler.getContainerConfig().setUseStageAsServletContext(false); } + @Disabled("Disabled until new release of commons-fileupload based on Jakarta APIs") @MethodSource("data") @ParameterizedTest void multipart_getFileName_returnsCorrectFileName(String reqType) From ac04f4c0044bcdc8810663730bdf1d196fbd45ea Mon Sep 17 00:00:00 2001 From: Dennis Kieselhorst Date: Fri, 19 May 2023 13:57:43 +0200 Subject: [PATCH 2/2] chore(deps): Update Commons IO dependency to 2.12.0 --- aws-serverless-java-container-core/pom.xml | 2 +- aws-serverless-java-container-struts/pom.xml | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/aws-serverless-java-container-core/pom.xml b/aws-serverless-java-container-core/pom.xml index 26bafa9a3..0da33fdd1 100644 --- a/aws-serverless-java-container-core/pom.xml +++ b/aws-serverless-java-container-core/pom.xml @@ -69,7 +69,7 @@ commons-io commons-io - 2.11.0 + 2.12.0 diff --git a/aws-serverless-java-container-struts/pom.xml b/aws-serverless-java-container-struts/pom.xml index ee1784d78..d38edb3c9 100644 --- a/aws-serverless-java-container-struts/pom.xml +++ b/aws-serverless-java-container-struts/pom.xml @@ -94,11 +94,6 @@ - - commons-io - commons-io - 2.11.0 - org.apache.commons commons-text