Skip to content

Commit

Permalink
FILEUPLOAD-342 Remove methods which use javax|jakarta classes from Fi…
Browse files Browse the repository at this point in the history
…leUploadBase

It should be neutral.
  • Loading branch information
martin-g committed Aug 20, 2021
1 parent 8fa525d commit 79d91fd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 48 deletions.
11 changes: 7 additions & 4 deletions src/main/java/org/apache/commons/fileupload2/DiskFileUpload.java
Expand Up @@ -20,15 +20,17 @@
import java.util.List;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.fileupload2.servlet.ServletRequestContext;

/**
* <p>High level API for processing file uploads.</p>
*
* <p>This class handles multiple files per single HTML widget, sent using
* {@code multipart/mixed} encoding type, as specified by
* <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>. Use {@link
* #parseRequest(HttpServletRequest)} to acquire a list of {@link
* org.apache.commons.fileupload2.FileItem}s associated with a given HTML
* widget.</p>
* org.apache.commons.fileupload2.servlet.ServletFileUpload#parseRequest(HttpServletRequest)}
* to acquire a list of {@link org.apache.commons.fileupload2.FileItem}s
* associated with a given HTML widget.</p>
*
* <p>Individual parts will be stored in temporary disk storage or in memory,
* depending on their size, and will be available as {@link
Expand Down Expand Up @@ -194,7 +196,8 @@ public List<FileItem> parseRequest(final HttpServletRequest req,
setSizeThreshold(sizeThreshold);
setSizeMax(sizeMax);
setRepositoryPath(path);
return parseRequest(req);
ServletRequestContext context = new ServletRequestContext(req);
return parseRequest(context);
}

}
40 changes: 0 additions & 40 deletions src/main/java/org/apache/commons/fileupload2/FileUploadBase.java
Expand Up @@ -28,13 +28,9 @@
import java.util.Map;
import java.util.Objects;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.fileupload2.impl.FileItemIteratorImpl;
import org.apache.commons.fileupload2.pub.FileUploadIOException;
import org.apache.commons.fileupload2.pub.IOFileUploadException;
import org.apache.commons.fileupload2.servlet.ServletFileUpload;
import org.apache.commons.fileupload2.servlet.ServletRequestContext;
import org.apache.commons.fileupload2.util.FileItemHeadersImpl;
import org.apache.commons.fileupload2.util.Streams;

Expand Down Expand Up @@ -78,22 +74,6 @@ public static final boolean isMultipartContent(final RequestContext ctx) {
return contentType.toLowerCase(Locale.ENGLISH).startsWith(MULTIPART);
}

/**
* Utility method that determines whether the request contains multipart
* content.
*
* @param req The servlet request to be evaluated. Must be non-null.
*
* @return {@code true} if the request is multipart;
* {@code false} otherwise.
*
* @deprecated 1.1 Use the method on {@code ServletFileUpload} instead.
*/
@Deprecated
public static boolean isMultipartContent(final HttpServletRequest req) {
return ServletFileUpload.isMultipartContent(req);
}

// ----------------------------------------------------- Manifest constants

/**
Expand Down Expand Up @@ -262,26 +242,6 @@ public void setHeaderEncoding(final String encoding) {

// --------------------------------------------------------- Public methods

/**
* Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
* compliant {@code multipart/form-data} stream.
*
* @param req The servlet request to be parsed.
*
* @return A list of {@code FileItem} instances parsed from the
* request, in the order that they were transmitted.
*
* @throws FileUploadException if there are problems reading/parsing
* the request or storing files.
*
* @deprecated 1.1 Use {@link ServletFileUpload#parseRequest(HttpServletRequest)} instead.
*/
@Deprecated
public List<FileItem> parseRequest(final HttpServletRequest req)
throws FileUploadException {
return parseRequest(new ServletRequestContext(req));
}

/**
* Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
* compliant {@code multipart/form-data} stream.
Expand Down
Expand Up @@ -106,7 +106,6 @@ public ServletFileUpload(final FileItemFactory fileItemFactory) {
* @throws FileUploadException if there are problems reading/parsing
* the request or storing files.
*/
@Override
public List<FileItem> parseRequest(final HttpServletRequest request)
throws FileUploadException {
return parseRequest(new ServletRequestContext(request));
Expand Down
Expand Up @@ -25,6 +25,7 @@

import org.apache.commons.fileupload2.disk.DiskFileItem;
import org.apache.commons.fileupload2.pub.InvalidContentTypeException;
import org.apache.commons.fileupload2.servlet.ServletRequestContext;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -52,7 +53,8 @@ public void testWithInvalidRequest() {
final HttpServletRequest req = HttpServletRequestFactory.createInvalidHttpServletRequest();

try {
upload.parseRequest(req);
ServletRequestContext context = new ServletRequestContext(req);
upload.parseRequest(context);
fail("testWithInvalidRequest: expected exception was not thrown");
} catch (final FileUploadException expected) {
// this exception is expected
Expand All @@ -64,7 +66,8 @@ public void testWithNullContentType() {
final HttpServletRequest req = HttpServletRequestFactory.createHttpServletRequestWithNullContentType();

try {
upload.parseRequest(req);
ServletRequestContext context = new ServletRequestContext(req);
upload.parseRequest(context);
fail("testWithNullContentType: expected exception was not thrown");
} catch (final InvalidContentTypeException expected) {
// this exception is expected
Expand All @@ -90,7 +93,8 @@ public void testMoveFile() throws Exception {
"-----1234--\r\n";
final byte[] contentBytes = content.getBytes(StandardCharsets.US_ASCII);
final HttpServletRequest request = new MockHttpServletRequest(contentBytes, Constants.CONTENT_TYPE);
final List<FileItem> items = myUpload.parseRequest(request);
ServletRequestContext context = new ServletRequestContext(request);
final List<FileItem> items = myUpload.parseRequest(context);
assertNotNull(items);
assertFalse(items.isEmpty());
final DiskFileItem dfi = (DiskFileItem) items.get(0);
Expand Down

0 comments on commit 79d91fd

Please sign in to comment.