This is an automated email from the ASF dual-hosted git repository.
solomax pushed a commit to branch fileupload2
in repository https://gitbox.apache.org/repos/asf/wicket.git
The following commit(s) were added to refs/heads/fileupload2 by this push:
new 7338e48279 [WICKET-6915] module-info is created
7338e48279 is described below
commit 7338e482795827caa58baadd55a56bf1b76aebff
Author: Maxim Solodovnik <[email protected]>
AuthorDate: Sat Mar 25 16:50:31 2023 +0700
[WICKET-6915] module-info is created
---
pom.xml | 6 +
wicket-commons-fileupload/pom.xml | 19 +-
.../src/main/java/module-info.java | 27 +
.../wicket/commons/fileupload2/FileItem.java | 2 +-
.../commons/fileupload2/disk/DiskFileItem.java | 2 +-
.../commons/fileupload2/disk/package-info.java | 4 +-
.../wicket/commons/fileupload2/package-info.java | 6 +-
.../fileupload2/portlet/PortletFileUpload.java | 148 ------
.../fileupload2/portlet/PortletRequestContext.java | 132 -----
.../commons/fileupload2/portlet/package-info.java | 45 --
.../fileupload2/servlet/FileCleanerCleanup.java | 89 ----
.../fileupload2/servlet/ServletFileUpload.java | 153 ------
.../fileupload2/servlet/ServletRequestContext.java | 130 -----
.../commons/fileupload2/servlet/package-info.java | 45 --
.../wicket/commons/fileupload2/FileUploadTest.java | 403 ---------------
.../fileupload2/HttpServletRequestFactory.java | 56 --
.../fileupload2/MockHttpServletRequest.java | 570 ---------------------
.../commons/fileupload2/ProgressListenerTest.java | 133 -----
.../wicket/commons/fileupload2/SizesTest.java | 292 -----------
.../wicket/commons/fileupload2/StreamingTest.java | 288 -----------
.../apache/wicket/commons/fileupload2/Util.java | 66 ---
.../jaksrvlt/JakSrvltFileUploadTest.java | 2 -
.../portlet/MockPortletActionRequest.java | 272 ----------
.../fileupload2/portlet/PortletFileUploadTest.java | 87 ----
.../fileupload2/servlet/ServletFileUploadTest.java | 106 ----
wicket-core/pom.xml | 16 +-
wicket-util/pom.xml | 1 -
27 files changed, 49 insertions(+), 3051 deletions(-)
diff --git a/pom.xml b/pom.xml
index 3ca1396903..318a813671 100644
--- a/pom.xml
+++ b/pom.xml
@@ -359,6 +359,12 @@
<version>10.0.0-M1-SNAPSHOT</version>
<type>jar</type>
</dependency>
+ <dependency>
+ <groupId>org.apache.wicket</groupId>
+
<artifactId>wicket-commons-fileupload</artifactId>
+ <version>10.0.0-M1-SNAPSHOT</version>
+ <type>jar</type>
+ </dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-core</artifactId>
diff --git a/wicket-commons-fileupload/pom.xml
b/wicket-commons-fileupload/pom.xml
index b8497f0976..feaec2468c 100644
--- a/wicket-commons-fileupload/pom.xml
+++ b/wicket-commons-fileupload/pom.xml
@@ -237,6 +237,7 @@
<moditect-maven-plugin.version>1.0.0.RC2</moditect-maven-plugin.version>
<moditect.skip>true</moditect.skip>
<enforcer.skip>true</enforcer.skip>
+ <checkstyle.skip>true</checkstyle.skip>
<!-- Commons Release Plugin -->
<commons.bc.version>1.3.3</commons.bc.version>
@@ -245,8 +246,6 @@
<commons.distSvnStagingUrl>scm:svn:https://dist.apache.org/repos/dist/dev/commons/${commons.componentid}</commons.distSvnStagingUrl>
<commons.releaseManagerName>Rob Tompkins</commons.releaseManagerName>
<commons.releaseManagerKey>B6E73D84EA4FCC47166087253FAAD2CD5ECBB314</commons.releaseManagerKey>
-
-
<automatic-module-name>org.apache.wicket.commons.fileupload</automatic-module-name>
</properties>
<dependencies>
@@ -282,22 +281,6 @@
<build>
<plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <version>${maven-jar-plugin.version}</version>
- <configuration>
- <archive>
- <manifest>
-
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
-
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
- </manifest>
- <manifestEntries>
-
<Automatic-Module-Name>${automatic-module-name}</Automatic-Module-Name>
- </manifestEntries>
- </archive>
- </configuration>
- </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
diff --git a/wicket-commons-fileupload/src/main/java/module-info.java
b/wicket-commons-fileupload/src/main/java/module-info.java
new file mode 100644
index 0000000000..ff8e457e38
--- /dev/null
+++ b/wicket-commons-fileupload/src/main/java/module-info.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ module org.apache.wicket.commons.fileupload {
+ requires org.apache.commons.io;
+ requires jakarta.servlet;
+
+ exports org.apache.wicket.commons.fileupload2;
+ exports org.apache.wicket.commons.fileupload2.pub;
+ exports org.apache.wicket.commons.fileupload2.util;
+ exports org.apache.wicket.commons.fileupload2.disk;
+ exports org.apache.wicket.commons.fileupload2.jaksrvlt;
+}
diff --git
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/FileItem.java
b/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/FileItem.java
index 5409399d04..e78c6231a1 100644
---
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/FileItem.java
+++
b/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/FileItem.java
@@ -29,7 +29,7 @@ import java.io.UnsupportedEncodingException;
*
* <p> After retrieving an instance of this class from a {@link
* org.apache.wicket.commons.fileupload2.FileUpload FileUpload} instance (see
- * {@link org.apache.wicket.commons.fileupload2.servlet.ServletFileUpload
+ * {@link org.apache.wicket.commons.fileupload2.jaksrvlt.JakSrvltFileUpload
* #parseRequest(javax.servlet.http.HttpServletRequest)}), you may
* either request all contents of the file at once using {@link #get()} or
* request an {@link java.io.InputStream InputStream} with
diff --git
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/disk/DiskFileItem.java
b/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/disk/DiskFileItem.java
index d8da4d3e9c..c4e302484e 100644
---
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/disk/DiskFileItem.java
+++
b/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/disk/DiskFileItem.java
@@ -45,7 +45,7 @@ import org.apache.wicket.commons.fileupload2.util.Streams;
*
* <p> After retrieving an instance of this class from a {@link
* DiskFileItemFactory} instance (see
- * {@link org.apache.wicket.commons.fileupload2.servlet.ServletFileUpload
+ * {@link org.apache.wicket.commons.fileupload2.jaksrvlt.JakSrvltFileUpload
* #parseRequest(javax.servlet.http.HttpServletRequest)}), you may
* either request all contents of file at once using {@link #get()} or
* request an {@link java.io.InputStream InputStream} with
diff --git
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/disk/package-info.java
b/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/disk/package-info.java
index b37424308a..0276bc1881 100644
---
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/disk/package-info.java
+++
b/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/disk/package-info.java
@@ -29,9 +29,7 @@
* would be created, configured, and then passed to a
* {@link org.apache.wicket.commons.fileupload2.FileUpload FileUpload}
* implementation such as
- * {@link org.apache.wicket.commons.fileupload2.servlet.ServletFileUpload
ServletFileUpload}
- * or
- * {@link org.apache.wicket.commons.fileupload2.portlet.PortletFileUpload
PortletFileUpload}.
+ * {@link
org.apache.wicket.commons.fileupload2.jaksrvlt.JakSrvltFileUpload
ServletFileUpload}
* </p>
* <p>
* The following code fragment demonstrates this usage.
diff --git
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/package-info.java
b/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/package-info.java
index 7ff4f65d79..f960f63e46 100644
---
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/package-info.java
+++
b/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/package-info.java
@@ -27,10 +27,8 @@
* these classes are not typically used directly. Instead, normal usage
* involves one of the provided extensions of
* {@link org.apache.wicket.commons.fileupload2.FileUpload FileUpload} such as
- * {@link org.apache.wicket.commons.fileupload2.servlet.ServletFileUpload
ServletFileUpload}
- * or
- * {@link org.apache.wicket.commons.fileupload2.portlet.PortletFileUpload
PortletFileUpload},
- * together with a factory for
+ * {@link org.apache.wicket.commons.fileupload2.jaksrvlt.JakSrvltFileUpload
ServletFileUpload}
+ * together with a factory for
* {@link org.apache.wicket.commons.fileupload2.FileItem FileItem} instances,
* such as
* {@link org.apache.wicket.commons.fileupload2.disk.DiskFileItemFactory
DiskFileItemFactory}.
diff --git
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/portlet/PortletFileUpload.java
b/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/portlet/PortletFileUpload.java
deleted file mode 100644
index 0b77b353dc..0000000000
---
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/portlet/PortletFileUpload.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.commons.fileupload2.portlet;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-
-import javax.portlet.ActionRequest;
-
-import org.apache.wicket.commons.fileupload2.FileItem;
-import org.apache.wicket.commons.fileupload2.FileItemFactory;
-import org.apache.wicket.commons.fileupload2.FileItemIterator;
-import org.apache.wicket.commons.fileupload2.FileUpload;
-import org.apache.wicket.commons.fileupload2.FileUploadBase;
-import org.apache.wicket.commons.fileupload2.FileUploadException;
-
-/**
- * <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 org.apache.wicket.commons.fileupload2.servlet.ServletFileUpload
- * #parseRequest(javax.servlet.http.HttpServletRequest)} to acquire a list
- * of {@link org.apache.wicket.commons.fileupload2.FileItem FileItems}
associated
- * with a given HTML widget.</p>
- *
- * <p>How the data for individual parts is stored is determined by the factory
- * used to create them; a given part may be in memory, on disk, or somewhere
- * else.</p>
- *
- * @since 1.1
- */
-public class PortletFileUpload extends FileUpload {
-
- // ---------------------------------------------------------- Class methods
-
- /**
- * Utility method that determines whether the request contains multipart
- * content.
- *
- * @param request The portlet request to be evaluated. Must be non-null.
- *
- * @return {@code true} if the request is multipart;
- * {@code false} otherwise.
- */
- public static final boolean isMultipartContent(final ActionRequest
request) {
- return FileUploadBase.isMultipartContent(
- new PortletRequestContext(request));
- }
-
- // ----------------------------------------------------------- Constructors
-
- /**
- * Constructs an uninitialized instance of this class. A factory must be
- * configured, using {@code setFileItemFactory()}, before attempting
- * to parse requests.
- *
- * @see FileUpload#FileUpload(FileItemFactory)
- */
- public PortletFileUpload() {
- }
-
- /**
- * Constructs an instance of this class which uses the supplied factory to
- * create {@code FileItem} instances.
- *
- * @see FileUpload#FileUpload()
- * @param fileItemFactory The factory to use for creating file items.
- */
- public PortletFileUpload(final FileItemFactory fileItemFactory) {
- super(fileItemFactory);
- }
-
- // --------------------------------------------------------- Public methods
-
- /**
- * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
- * compliant {@code multipart/form-data} stream.
- *
- * @param request The portlet 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.
- */
- public List<FileItem> parseRequest(final ActionRequest request)
- throws FileUploadException {
- return parseRequest(new PortletRequestContext(request));
- }
-
- /**
- * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
- * compliant {@code multipart/form-data} stream.
- *
- * @param request The portlet request to be parsed.
- *
- * @return A map of {@code FileItem} instances parsed from the request.
- *
- * @throws FileUploadException if there are problems reading/parsing
- * the request or storing files.
- *
- * @since 1.3
- */
- public Map<String, List<FileItem>> parseParameterMap(final ActionRequest
request)
- throws FileUploadException {
- return parseParameterMap(new PortletRequestContext(request));
- }
-
- /**
- * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
- * compliant {@code multipart/form-data} stream.
- *
- * @param request The portlet request to be parsed.
- *
- * @return An iterator to instances of {@code FileItemStream}
- * parsed from the request, in the order that they were
- * transmitted.
- *
- * @throws FileUploadException if there are problems reading/parsing
- * the request or storing files.
- * @throws IOException An I/O error occurred. This may be a network
- * error while communicating with the client or a problem while
- * storing the uploaded content.
- */
- public FileItemIterator getItemIterator(final ActionRequest request)
- throws FileUploadException, IOException {
- return super.getItemIterator(new PortletRequestContext(request));
- }
-
-}
diff --git
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/portlet/PortletRequestContext.java
b/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/portlet/PortletRequestContext.java
deleted file mode 100644
index 5bdc817862..0000000000
---
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/portlet/PortletRequestContext.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.commons.fileupload2.portlet;
-
-import static java.lang.String.format;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.portlet.ActionRequest;
-
-import org.apache.wicket.commons.fileupload2.FileUploadBase;
-import org.apache.wicket.commons.fileupload2.UploadContext;
-
-/**
- * <p>Provides access to the request information needed for a request made to
- * a portlet.</p>
- *
- * @since 1.1
- */
-public class PortletRequestContext implements UploadContext {
-
- // ----------------------------------------------------- Instance Variables
-
- /**
- * The request for which the context is being provided.
- */
- private final ActionRequest request;
-
-
- // ----------------------------------------------------------- Constructors
-
- /**
- * Construct a context for this request.
- *
- * @param request The request to which this context applies.
- */
- public PortletRequestContext(final ActionRequest request) {
- this.request = request;
- }
-
-
- // --------------------------------------------------------- Public Methods
-
- /**
- * Retrieve the character encoding for the request.
- *
- * @return The character encoding for the request.
- */
- @Override
- public String getCharacterEncoding() {
- return request.getCharacterEncoding();
- }
-
- /**
- * Retrieve the content type of the request.
- *
- * @return The content type of the request.
- */
- @Override
- public String getContentType() {
- return request.getContentType();
- }
-
- /**
- * Retrieve the content length of the request.
- *
- * @return The content length of the request.
- * @deprecated 1.3 Use {@link #contentLength()} instead
- */
- @Override
- @Deprecated
- public int getContentLength() {
- return request.getContentLength();
- }
-
- /**
- * Retrieve the content length of the request.
- *
- * @return The content length of the request.
- * @since 1.3
- */
- @Override
- public long contentLength() {
- long size;
- try {
- size =
Long.parseLong(request.getProperty(FileUploadBase.CONTENT_LENGTH));
- } catch (final NumberFormatException e) {
- size = request.getContentLength();
- }
- return size;
- }
-
- /**
- * Retrieve the input stream for the request.
- *
- * @return The input stream for the request.
- *
- * @throws IOException if a problem occurs.
- */
- @Override
- public InputStream getInputStream() throws IOException {
- return request.getPortletInputStream();
- }
-
- /**
- * Returns a string representation of this object.
- *
- * @return a string representation of this object.
- */
- @Override
- public String toString() {
- return format("ContentLength=%s, ContentType=%s",
- this.contentLength(),
- this.getContentType());
- }
-
-}
diff --git
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/portlet/package-info.java
b/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/portlet/package-info.java
deleted file mode 100644
index d2a73a5b92..0000000000
---
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/portlet/package-info.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * <p>
- * An implementation of
- * {@link org.apache.wicket.commons.fileupload2.FileUpload FileUpload}
- * for use in portlets conforming to JSR 168. This implementation requires
- * only access to the portlet's current {@code ActionRequest} instance,
- * and a suitable
- * {@link org.apache.wicket.commons.fileupload2.FileItemFactory
FileItemFactory}
- * implementation, such as
- * {@link org.apache.wicket.commons.fileupload2.disk.DiskFileItemFactory
DiskFileItemFactory}.
- * </p>
- * <p>
- * The following code fragment demonstrates typical usage.
- * </p>
- * <pre>
- * DiskFileItemFactory factory = new DiskFileItemFactory();
- * // Configure the factory here, if desired.
- * PortletFileUpload upload = new PortletFileUpload(factory);
- * // Configure the uploader here, if desired.
- * List fileItems = upload.parseRequest(request);
- * </pre>
- * <p>
- * Please see the FileUpload
- * <a href="https://commons.apache.org/fileupload/using.html"
target="_top">User Guide</a>
- * for further details and examples of how to use this package.
- * </p>
- */
-package org.apache.wicket.commons.fileupload2.portlet;
diff --git
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/servlet/FileCleanerCleanup.java
b/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/servlet/FileCleanerCleanup.java
deleted file mode 100644
index 231891f0e5..0000000000
---
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/servlet/FileCleanerCleanup.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.commons.fileupload2.servlet;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextListener;
-import javax.servlet.ServletContextEvent;
-
-import org.apache.commons.io.FileCleaningTracker;
-
-/**
- * A servlet context listener, which ensures that the
- * {@link FileCleaningTracker}'s reaper thread is terminated,
- * when the web application is destroyed.
- */
-public class FileCleanerCleanup implements ServletContextListener {
-
- /**
- * Attribute name, which is used for storing an instance of
- * {@link FileCleaningTracker} in the web application.
- */
- public static final String FILE_CLEANING_TRACKER_ATTRIBUTE
- = FileCleanerCleanup.class.getName() + ".FileCleaningTracker";
-
- /**
- * Returns the instance of {@link FileCleaningTracker}, which is
- * associated with the given {@link ServletContext}.
- *
- * @param pServletContext The servlet context to query
- * @return The contexts tracker
- */
- public static FileCleaningTracker
- getFileCleaningTracker(final ServletContext pServletContext) {
- return (FileCleaningTracker)
- pServletContext.getAttribute(FILE_CLEANING_TRACKER_ATTRIBUTE);
- }
-
- /**
- * Sets the instance of {@link FileCleaningTracker}, which is
- * associated with the given {@link ServletContext}.
- *
- * @param pServletContext The servlet context to modify
- * @param pTracker The tracker to set
- */
- public static void setFileCleaningTracker(final ServletContext
pServletContext,
- final FileCleaningTracker pTracker) {
- pServletContext.setAttribute(FILE_CLEANING_TRACKER_ATTRIBUTE,
pTracker);
- }
-
- /**
- * Called when the web application is initialized. Does
- * nothing.
- *
- * @param sce The servlet context, used for calling
- * {@link #setFileCleaningTracker(ServletContext, FileCleaningTracker)}.
- */
- @Override
- public void contextInitialized(final ServletContextEvent sce) {
- setFileCleaningTracker(sce.getServletContext(),
- new FileCleaningTracker());
- }
-
- /**
- * Called when the web application is being destroyed.
- * Calls {@link FileCleaningTracker#exitWhenFinished()}.
- *
- * @param sce The servlet context, used for calling
- * {@link #getFileCleaningTracker(ServletContext)}.
- */
- @Override
- public void contextDestroyed(final ServletContextEvent sce) {
- getFileCleaningTracker(sce.getServletContext()).exitWhenFinished();
- }
-
-}
diff --git
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/servlet/ServletFileUpload.java
b/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/servlet/ServletFileUpload.java
deleted file mode 100644
index 33e8a75207..0000000000
---
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/servlet/ServletFileUpload.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.commons.fileupload2.servlet;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.wicket.commons.fileupload2.FileItem;
-import org.apache.wicket.commons.fileupload2.FileItemFactory;
-import org.apache.wicket.commons.fileupload2.FileItemIterator;
-import org.apache.wicket.commons.fileupload2.FileUpload;
-import org.apache.wicket.commons.fileupload2.FileUploadBase;
-import org.apache.wicket.commons.fileupload2.FileUploadException;
-
-/**
- * <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.wicket.commons.fileupload2.FileItem}s associated with a given
HTML
- * widget.</p>
- *
- * <p>How the data for individual parts is stored is determined by the factory
- * used to create them; a given part may be in memory, on disk, or somewhere
- * else.</p>
- */
-public class ServletFileUpload extends FileUpload {
-
- /**
- * Constant for HTTP POST method.
- */
- private static final String POST_METHOD = "POST";
-
- // ---------------------------------------------------------- Class methods
-
- /**
- * Utility method that determines whether the request contains multipart
- * content.
- *
- * @param request The servlet request to be evaluated. Must be non-null.
- *
- * @return {@code true} if the request is multipart;
- * {@code false} otherwise.
- */
- public static final boolean isMultipartContent(
- final HttpServletRequest request) {
- if (!POST_METHOD.equalsIgnoreCase(request.getMethod())) {
- return false;
- }
- return FileUploadBase.isMultipartContent(new
ServletRequestContext(request));
- }
-
- // ----------------------------------------------------------- Constructors
-
- /**
- * Constructs an uninitialized instance of this class. A factory must be
- * configured, using {@code setFileItemFactory()}, before attempting
- * to parse requests.
- *
- * @see FileUpload#FileUpload(FileItemFactory)
- */
- public ServletFileUpload() {
- }
-
- /**
- * Constructs an instance of this class which uses the supplied factory to
- * create {@code FileItem} instances.
- *
- * @see FileUpload#FileUpload()
- * @param fileItemFactory The factory to use for creating file items.
- */
- public ServletFileUpload(final FileItemFactory fileItemFactory) {
- super(fileItemFactory);
- }
-
- // --------------------------------------------------------- Public methods
-
- /**
- * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
- * compliant {@code multipart/form-data} stream.
- *
- * @param request 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.
- */
- public List<FileItem> parseRequest(final HttpServletRequest request)
- throws FileUploadException {
- return parseRequest(new ServletRequestContext(request));
- }
-
- /**
- * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
- * compliant {@code multipart/form-data} stream.
- *
- * @param request The servlet request to be parsed.
- *
- * @return A map of {@code FileItem} instances parsed from the request.
- *
- * @throws FileUploadException if there are problems reading/parsing
- * the request or storing files.
- *
- * @since 1.3
- */
- public Map<String, List<FileItem>> parseParameterMap(final
HttpServletRequest request)
- throws FileUploadException {
- return parseParameterMap(new ServletRequestContext(request));
- }
-
- /**
- * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
- * compliant {@code multipart/form-data} stream.
- *
- * @param request The servlet request to be parsed.
- *
- * @return An iterator to instances of {@code FileItemStream}
- * parsed from the request, in the order that they were
- * transmitted.
- *
- * @throws FileUploadException if there are problems reading/parsing
- * the request or storing files.
- * @throws IOException An I/O error occurred. This may be a network
- * error while communicating with the client or a problem while
- * storing the uploaded content.
- */
- public FileItemIterator getItemIterator(final HttpServletRequest request)
- throws FileUploadException, IOException {
- return super.getItemIterator(new ServletRequestContext(request));
- }
-
-}
diff --git
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/servlet/ServletRequestContext.java
b/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/servlet/ServletRequestContext.java
deleted file mode 100644
index b8a1ffd297..0000000000
---
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/servlet/ServletRequestContext.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.commons.fileupload2.servlet;
-
-import static java.lang.String.format;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.wicket.commons.fileupload2.FileUploadBase;
-import org.apache.wicket.commons.fileupload2.UploadContext;
-
-/**
- * <p>Provides access to the request information needed for a request made to
- * an HTTP servlet.</p>
- *
- * @since 1.1
- */
-public class ServletRequestContext implements UploadContext {
-
- // ----------------------------------------------------- Instance Variables
-
- /**
- * The request for which the context is being provided.
- */
- private final HttpServletRequest request;
-
- // ----------------------------------------------------------- Constructors
-
- /**
- * Construct a context for this request.
- *
- * @param request The request to which this context applies.
- */
- public ServletRequestContext(final HttpServletRequest request) {
- this.request = request;
- }
-
- // --------------------------------------------------------- Public Methods
-
- /**
- * Retrieve the character encoding for the request.
- *
- * @return The character encoding for the request.
- */
- @Override
- public String getCharacterEncoding() {
- return request.getCharacterEncoding();
- }
-
- /**
- * Retrieve the content type of the request.
- *
- * @return The content type of the request.
- */
- @Override
- public String getContentType() {
- return request.getContentType();
- }
-
- /**
- * Retrieve the content length of the request.
- *
- * @return The content length of the request.
- * @deprecated 1.3 Use {@link #contentLength()} instead
- */
- @Override
- @Deprecated
- public int getContentLength() {
- return request.getContentLength();
- }
-
- /**
- * Retrieve the content length of the request.
- *
- * @return The content length of the request.
- * @since 1.3
- */
- @Override
- public long contentLength() {
- long size;
- try {
- size =
Long.parseLong(request.getHeader(FileUploadBase.CONTENT_LENGTH));
- } catch (final NumberFormatException e) {
- size = request.getContentLength();
- }
- return size;
- }
-
- /**
- * Retrieve the input stream for the request.
- *
- * @return The input stream for the request.
- *
- * @throws IOException if a problem occurs.
- */
- @Override
- public InputStream getInputStream() throws IOException {
- return request.getInputStream();
- }
-
- /**
- * Returns a string representation of this object.
- *
- * @return a string representation of this object.
- */
- @Override
- public String toString() {
- return format("ContentLength=%s, ContentType=%s",
- this.contentLength(),
- this.getContentType());
- }
-
-}
diff --git
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/servlet/package-info.java
b/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/servlet/package-info.java
deleted file mode 100644
index 168edc91a2..0000000000
---
a/wicket-commons-fileupload/src/main/java/org/apache/wicket/commons/fileupload2/servlet/package-info.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * <p>
- * An implementation of
- * {@link org.apache.wicket.commons.fileupload2.FileUpload FileUpload}
- * for use in servlets conforming to JSR 53. This implementation requires
- * only access to the servlet's current {@code HttpServletRequest}
- * instance, and a suitable
- * {@link org.apache.wicket.commons.fileupload2.FileItemFactory
FileItemFactory}
- * implementation, such as
- * {@link org.apache.wicket.commons.fileupload2.disk.DiskFileItemFactory
DiskFileItemFactory}.
- * </p>
- * <p>
- * The following code fragment demonstrates typical usage.
- * </p>
- * <pre>
- * DiskFileItemFactory factory = new DiskFileItemFactory();
- * // Configure the factory here, if desired.
- * ServletFileUpload upload = new ServletFileUpload(factory);
- * // Configure the uploader here, if desired.
- * List fileItems = upload.parseRequest(request);
- * </pre>
- * <p>
- * Please see the FileUpload
- * <a href="https://commons.apache.org/fileupload/using.html"
target="_top">User Guide</a>
- * for further details and examples of how to use this package.
- * </p>
- */
-package org.apache.wicket.commons.fileupload2.servlet;
diff --git
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/FileUploadTest.java
b/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/FileUploadTest.java
deleted file mode 100644
index c42a085bf6..0000000000
---
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/FileUploadTest.java
+++ /dev/null
@@ -1,403 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.commons.fileupload2;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.StandardCharsets;
-import java.util.List;
-import java.util.stream.Stream;
-
-import org.apache.wicket.commons.fileupload2.FileItem;
-import org.apache.wicket.commons.fileupload2.FileUpload;
-import org.apache.wicket.commons.fileupload2.FileUploadException;
-import org.apache.wicket.commons.fileupload2.portlet.PortletFileUploadTest;
-import org.apache.wicket.commons.fileupload2.servlet.ServletFileUploadTest;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.MethodSource;
-
-/**
- * Common tests for implementations of {@link FileUpload}. This is a
parameterized test.
- * Tests must be valid and common to all implementations of FileUpload added
as parameter
- * in this class.
- *
- * @see ServletFileUploadTest
- * @see PortletFileUploadTest
- * @since 1.4
- */
-public class FileUploadTest {
-
- /**
- * @return {@link FileUpload} classes under test.
- */
- public static Stream<FileUpload> data() {
- return Util.fileUploadImplementations().stream();
- }
-
- // --- Test methods common to all implementations of a FileUpload
-
- @ParameterizedTest
- @MethodSource("data")
- public void testFileUpload(final FileUpload upload)
- throws IOException, FileUploadException {
- final List<FileItem> fileItems = Util.parseUpload(upload,
- "-----1234\r\n" +
- "Content-Disposition: "
- + "form-data; name=\"file\";
filename=\"foo.tab\"\r\n" +
- "Content-Type:
text/whatever\r\n" +
- "\r\n" +
- "This is the content of the
file\n" +
- "\r\n" +
- "-----1234\r\n" +
- "Content-Disposition:
form-data; name=\"field\"\r\n" +
- "\r\n" +
- "fieldValue\r\n" +
- "-----1234\r\n" +
- "Content-Disposition:
form-data; name=\"multi\"\r\n" +
- "\r\n" +
- "value1\r\n" +
- "-----1234\r\n" +
- "Content-Disposition:
form-data; name=\"multi\"\r\n" +
- "\r\n" +
- "value2\r\n" +
- "-----1234--\r\n");
- assertEquals(4, fileItems.size());
-
- final FileItem file = fileItems.get(0);
- assertEquals("file", file.getFieldName());
- assertFalse(file.isFormField());
- assertEquals("This is the content of the file\n", file.getString());
- assertEquals("text/whatever", file.getContentType());
- assertEquals("foo.tab", file.getName());
-
- final FileItem field = fileItems.get(1);
- assertEquals("field", field.getFieldName());
- assertTrue(field.isFormField());
- assertEquals("fieldValue", field.getString());
-
- final FileItem multi0 = fileItems.get(2);
- assertEquals("multi", multi0.getFieldName());
- assertTrue(multi0.isFormField());
- assertEquals("value1", multi0.getString());
-
- final FileItem multi1 = fileItems.get(3);
- assertEquals("multi", multi1.getFieldName());
- assertTrue(multi1.isFormField());
- assertEquals("value2", multi1.getString());
- }
-
- @ParameterizedTest
- @MethodSource("data")
- public void testFilenameCaseSensitivity(final FileUpload upload)
- throws IOException, FileUploadException {
- final List<FileItem> fileItems = Util.parseUpload(upload,
- "-----1234\r\n" +
- "Content-Disposition:
form-data; "
- + "name=\"FiLe\";
filename=\"FOO.tab\"\r\n" +
- "Content-Type:
text/whatever\r\n" +
- "\r\n" +
- "This is the content of the
file\n" +
- "\r\n" +
- "-----1234--\r\n");
- assertEquals(1, fileItems.size());
-
- final FileItem file = fileItems.get(0);
- assertEquals("FiLe", file.getFieldName());
- assertEquals("FOO.tab", file.getName());
- }
-
- /**
- * This is what the browser does if you submit the form without choosing a
file.
- */
- @ParameterizedTest
- @MethodSource("data")
- public void testEmptyFile(final FileUpload upload)
- throws UnsupportedEncodingException, FileUploadException {
- final List<FileItem> fileItems = Util.parseUpload (upload,
- "-----1234\r\n" +
- "Content-Disposition:
form-data; name=\"file\"; filename=\"\"\r\n" +
- "\r\n" +
- "\r\n" +
- "-----1234--\r\n");
- assertEquals(1, fileItems.size());
-
- final FileItem file = fileItems.get(0);
- assertFalse(file.isFormField());
- assertEquals("", file.getString());
- assertEquals("", file.getName());
- }
-
- /**
- * Internet Explorer 5 for the Mac has a bug where the carriage
- * return is missing on any boundary line immediately preceding
- * an input with type=image. (type=submit does not have the bug.)
- */
- @ParameterizedTest
- @MethodSource("data")
- public void testIE5MacBug(final FileUpload upload)
- throws UnsupportedEncodingException, FileUploadException {
- final List<FileItem> fileItems = Util.parseUpload(upload,
- "-----1234\r\n" +
- "Content-Disposition:
form-data; name=\"field1\"\r\n" +
- "\r\n" +
- "fieldValue\r\n" +
- "-----1234\n" + // NOTE \r
missing
- "Content-Disposition:
form-data; name=\"submitName.x\"\r\n" +
- "\r\n" +
- "42\r\n" +
- "-----1234\n" + // NOTE \r
missing
- "Content-Disposition:
form-data; name=\"submitName.y\"\r\n" +
- "\r\n" +
- "21\r\n" +
- "-----1234\r\n" +
- "Content-Disposition:
form-data; name=\"field2\"\r\n" +
- "\r\n" +
- "fieldValue2\r\n" +
- "-----1234--\r\n");
-
- assertEquals(4, fileItems.size());
-
- final FileItem field1 = fileItems.get(0);
- assertEquals("field1", field1.getFieldName());
- assertTrue(field1.isFormField());
- assertEquals("fieldValue", field1.getString());
-
- final FileItem submitX = fileItems.get(1);
- assertEquals("submitName.x", submitX.getFieldName());
- assertTrue(submitX.isFormField());
- assertEquals("42", submitX.getString());
-
- final FileItem submitY = fileItems.get(2);
- assertEquals("submitName.y", submitY.getFieldName());
- assertTrue(submitY.isFormField());
- assertEquals("21", submitY.getString());
-
- final FileItem field2 = fileItems.get(3);
- assertEquals("field2", field2.getFieldName());
- assertTrue(field2.isFormField());
- assertEquals("fieldValue2", field2.getString());
- }
-
- /**
- * Test for <a
href="https://issues.apache.org/jira/browse/FILEUPLOAD-62">FILEUPLOAD-62</a>
- */
- @ParameterizedTest
- @MethodSource("data")
- public void testFILEUPLOAD62(final FileUpload upload) throws Exception {
- final String contentType = "multipart/form-data; boundary=AaB03x";
- final String request =
- "--AaB03x\r\n" +
- "content-disposition: form-data; name=\"field1\"\r\n" +
- "\r\n" +
- "Joe Blow\r\n" +
- "--AaB03x\r\n" +
- "content-disposition: form-data; name=\"pics\"\r\n" +
- "Content-type: multipart/mixed; boundary=BbC04y\r\n" +
- "\r\n" +
- "--BbC04y\r\n" +
- "Content-disposition: attachment; filename=\"file1.txt\"\r\n" +
- "Content-Type: text/plain\r\n" +
- "\r\n" +
- "... contents of file1.txt ...\r\n" +
- "--BbC04y\r\n" +
- "Content-disposition: attachment; filename=\"file2.gif\"\r\n" +
- "Content-type: image/gif\r\n" +
- "Content-Transfer-Encoding: binary\r\n" +
- "\r\n" +
- "...contents of file2.gif...\r\n" +
- "--BbC04y--\r\n" +
- "--AaB03x--";
- final List<FileItem> fileItems = Util.parseUpload(upload,
request.getBytes(StandardCharsets.US_ASCII),
- contentType);
- assertEquals(3, fileItems.size());
- final FileItem item0 = fileItems.get(0);
- assertEquals("field1", item0.getFieldName());
- assertNull(item0.getName());
- assertEquals("Joe Blow", new String(item0.get()));
- final FileItem item1 = fileItems.get(1);
- assertEquals("pics", item1.getFieldName());
- assertEquals("file1.txt", item1.getName());
- assertEquals("... contents of file1.txt ...", new String(item1.get()));
- final FileItem item2 = fileItems.get(2);
- assertEquals("pics", item2.getFieldName());
- assertEquals("file2.gif", item2.getName());
- assertEquals("...contents of file2.gif...", new String(item2.get()));
- }
-
- /**
- * Test for <a
href="https://issues.apache.org/jira/browse/FILEUPLOAD-111">FILEUPLOAD-111</a>
- */
- @ParameterizedTest
- @MethodSource("data")
- public void testFoldedHeaders(final FileUpload upload)
- throws IOException, FileUploadException {
- final List<FileItem> fileItems = Util.parseUpload(upload,
"-----1234\r\n" +
- "Content-Disposition: form-data; name=\"file\";
filename=\"foo.tab\"\r\n" +
- "Content-Type: text/whatever\r\n" +
- "\r\n" +
- "This is the content of the file\n" +
- "\r\n" +
- "-----1234\r\n" +
- "Content-Disposition: form-data; \r\n" +
- "\tname=\"field\"\r\n" +
- "\r\n" +
- "fieldValue\r\n" +
- "-----1234\r\n" +
- "Content-Disposition: form-data;\r\n" +
- " name=\"multi\"\r\n" +
- "\r\n" +
- "value1\r\n" +
- "-----1234\r\n" +
- "Content-Disposition: form-data; name=\"multi\"\r\n" +
- "\r\n" +
- "value2\r\n" +
- "-----1234--\r\n");
- assertEquals(4, fileItems.size());
-
- final FileItem file = fileItems.get(0);
- assertEquals("file", file.getFieldName());
- assertFalse(file.isFormField());
- assertEquals("This is the content of the file\n", file.getString());
- assertEquals("text/whatever", file.getContentType());
- assertEquals("foo.tab", file.getName());
-
- final FileItem field = fileItems.get(1);
- assertEquals("field", field.getFieldName());
- assertTrue(field.isFormField());
- assertEquals("fieldValue", field.getString());
-
- final FileItem multi0 = fileItems.get(2);
- assertEquals("multi", multi0.getFieldName());
- assertTrue(multi0.isFormField());
- assertEquals("value1", multi0.getString());
-
- final FileItem multi1 = fileItems.get(3);
- assertEquals("multi", multi1.getFieldName());
- assertTrue(multi1.isFormField());
- assertEquals("value2", multi1.getString());
- }
-
- /**
- * Test case for <a
href="https://issues.apache.org/jira/browse/FILEUPLOAD-130">
- */
- @ParameterizedTest
- @MethodSource("data")
- public void testFileUpload130(final FileUpload upload)
- throws Exception {
- final String[] headerNames = {
- "SomeHeader", "OtherHeader", "YetAnotherHeader", "WhatAHeader"
- };
- final String[] headerValues = {
- "present", "Is there", "Here", "Is That"
- };
- final List<FileItem> fileItems = Util.parseUpload(upload,
- "-----1234\r\n" +
- "Content-Disposition:
form-data; name=\"file\"; "
- + "filename=\"foo.tab\"\r\n" +
- "Content-Type:
text/whatever\r\n" +
- headerNames[0] + ": " +
headerValues[0] + "\r\n" +
- "\r\n" +
- "This is the content of the
file\n" +
- "\r\n" +
- "-----1234\r\n" +
- "Content-Disposition:
form-data; \r\n" +
- "\tname=\"field\"\r\n" +
- headerNames[1] + ": " +
headerValues[1] + "\r\n" +
- "\r\n" +
- "fieldValue\r\n" +
- "-----1234\r\n" +
- "Content-Disposition:
form-data;\r\n" +
- " name=\"multi\"\r\n" +
- headerNames[2] + ": " +
headerValues[2] + "\r\n" +
- "\r\n" +
- "value1\r\n" +
- "-----1234\r\n" +
- "Content-Disposition:
form-data; name=\"multi\"\r\n" +
- headerNames[3] + ": " +
headerValues[3] + "\r\n" +
- "\r\n" +
- "value2\r\n" +
- "-----1234--\r\n");
- assertEquals(4, fileItems.size());
-
- final FileItem file = fileItems.get(0);
- assertHeaders(headerNames, headerValues, file, 0);
-
- final FileItem field = fileItems.get(1);
- assertHeaders(headerNames, headerValues, field, 1);
-
- final FileItem multi0 = fileItems.get(2);
- assertHeaders(headerNames, headerValues, multi0, 2);
-
- final FileItem multi1 = fileItems.get(3);
- assertHeaders(headerNames, headerValues, multi1, 3);
- }
-
- /**
- * Test for <a
href="https://issues.apache.org/jira/browse/FILEUPLOAD-239">FILEUPLOAD-239</a>
- */
- @ParameterizedTest
- @MethodSource("data")
- public void testContentTypeAttachment(final FileUpload upload)
- throws IOException, FileUploadException {
- final List<FileItem> fileItems = Util.parseUpload(upload,
- "-----1234\r\n" +
- "content-disposition: form-data; name=\"field1\"\r\n" +
- "\r\n" +
- "Joe Blow\r\n" +
- "-----1234\r\n" +
- "content-disposition: form-data; name=\"pics\"\r\n" +
- "Content-type: multipart/mixed, boundary=---9876\r\n" +
- "\r\n" +
- "-----9876\r\n" +
- "Content-disposition: attachment; filename=\"file1.txt\"\r\n" +
- "Content-Type: text/plain\r\n" +
- "\r\n" +
- "... contents of file1.txt ...\r\n" +
- "-----9876--\r\n" +
- "-----1234--\r\n");
- assertEquals(2, fileItems.size());
-
- final FileItem field = fileItems.get(0);
- assertEquals("field1", field.getFieldName());
- assertTrue(field.isFormField());
- assertEquals("Joe Blow", field.getString());
-
- final FileItem file = fileItems.get(1);
- assertEquals("pics", file.getFieldName());
- assertFalse(file.isFormField());
- assertEquals("... contents of file1.txt ...", file.getString());
- assertEquals("text/plain", file.getContentType());
- assertEquals("file1.txt", file.getName());
- }
-
- private void assertHeaders(final String[] pHeaderNames, final String[]
pHeaderValues,
- final FileItem pItem, final int pIndex) {
- for (int i = 0; i < pHeaderNames.length; i++) {
- final String value = pItem.getHeaders().getHeader(pHeaderNames[i]);
- if (i == pIndex) {
- assertEquals(pHeaderValues[i], value);
- } else {
- assertNull(value);
- }
- }
- }
-}
diff --git
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/HttpServletRequestFactory.java
b/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/HttpServletRequestFactory.java
deleted file mode 100644
index 84328b87c3..0000000000
---
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/HttpServletRequestFactory.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.commons.fileupload2;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.wicket.commons.fileupload2.FileUploadBase;
-
-final class HttpServletRequestFactory {
-
- public static HttpServletRequest
createHttpServletRequestWithNullContentType() {
- final byte[] requestData = "foobar".getBytes();
- return new MockHttpServletRequest(
- requestData,
- null);
- }
-
- public static HttpServletRequest createValidHttpServletRequest(
- final String[] strFileNames) {
- // todo - provide a real implementation
-
- final StringBuilder sbRequestData = new StringBuilder();
-
- for (final String strFileName : strFileNames) {
- sbRequestData.append(strFileName);
- }
-
- final byte[] requestData = sbRequestData.toString().getBytes();
-
- return new MockHttpServletRequest(
- requestData,
- FileUploadBase.MULTIPART_FORM_DATA);
- }
-
- static public HttpServletRequest createInvalidHttpServletRequest() {
- final byte[] requestData = "foobar".getBytes();
- return new MockHttpServletRequest(
- requestData,
- FileUploadBase.MULTIPART_FORM_DATA);
- }
-
-}
diff --git
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/MockHttpServletRequest.java
b/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/MockHttpServletRequest.java
deleted file mode 100644
index afe16da497..0000000000
---
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/MockHttpServletRequest.java
+++ /dev/null
@@ -1,570 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.commons.fileupload2;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.security.Principal;
-import java.util.Enumeration;
-import java.util.Locale;
-import java.util.Map;
-
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletInputStream;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
-import org.apache.wicket.commons.fileupload2.FileUploadBase;
-
-public class MockHttpServletRequest implements HttpServletRequest {
-
- private final InputStream mmRequestData;
-
- private long length;
-
- private final String mStrContentType;
-
- private int readLimit = -1;
-
- private final Map<String, String> mHeaders = new java.util.HashMap<>();
-
- /**
- * Creates a new instance with the given request data
- * and content type.
- */
- public MockHttpServletRequest(
- final byte[] requestData,
- final String strContentType) {
- this(new ByteArrayInputStream(requestData),
- requestData.length, strContentType);
- }
-
- /**
- * Creates a new instance with the given request data
- * and content type.
- */
- public MockHttpServletRequest(
- final InputStream requestData,
- final long requestLength,
- final String strContentType) {
- mmRequestData = requestData;
- length = requestLength;
- mStrContentType = strContentType;
- mHeaders.put(FileUploadBase.CONTENT_TYPE, strContentType);
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getAuthType()
- */
- @Override
- public String getAuthType() {
- return null;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getCookies()
- */
- @Override
- public Cookie[] getCookies() {
- return null;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getDateHeader(String)
- */
- @Override
- public long getDateHeader(final String arg0) {
- return 0;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getHeader(String)
- */
- @Override
- public String getHeader(final String headerName) {
- return mHeaders.get(headerName);
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getHeaders(String)
- */
- @Override
- public Enumeration<String> getHeaders(final String arg0) {
- // todo - implement
- return null;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getHeaderNames()
- */
- @Override
- public Enumeration<String> getHeaderNames() {
- // todo - implement
- return null;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getIntHeader(String)
- */
- @Override
- public int getIntHeader(final String arg0) {
- return 0;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getMethod()
- */
- @Override
- public String getMethod() {
- return null;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getPathInfo()
- */
- @Override
- public String getPathInfo() {
- return null;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getPathTranslated()
- */
- @Override
- public String getPathTranslated() {
- return null;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getContextPath()
- */
- @Override
- public String getContextPath() {
- return null;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getQueryString()
- */
- @Override
- public String getQueryString() {
- return null;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getRemoteUser()
- */
- @Override
- public String getRemoteUser() {
- return null;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#isUserInRole(String)
- */
- @Override
- public boolean isUserInRole(final String arg0) {
- return false;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getUserPrincipal()
- */
- @Override
- public Principal getUserPrincipal() {
- return null;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getRequestedSessionId()
- */
- @Override
- public String getRequestedSessionId() {
- return null;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getRequestURI()
- */
- @Override
- public String getRequestURI() {
- return null;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getRequestURL()
- */
- @Override
- public StringBuffer getRequestURL() {
- return null;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getServletPath()
- */
- @Override
- public String getServletPath() {
- return null;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getSession(boolean)
- */
- @Override
- public HttpSession getSession(final boolean arg0) {
- return null;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getSession()
- */
- @Override
- public HttpSession getSession() {
- return null;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdValid()
- */
- @Override
- public boolean isRequestedSessionIdValid() {
- return false;
- }
-
- /**
- * @see
javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromCookie()
- */
- @Override
- public boolean isRequestedSessionIdFromCookie() {
- return false;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromURL()
- */
- @Override
- public boolean isRequestedSessionIdFromURL() {
- return false;
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromUrl()
- * @deprecated
- */
- @Override
- @Deprecated
- public boolean isRequestedSessionIdFromUrl() {
- return false;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getAttribute(String)
- */
- @Override
- public Object getAttribute(final String arg0) {
- return null;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getAttributeNames()
- */
- @Override
- public Enumeration<String> getAttributeNames() {
- return null;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getCharacterEncoding()
- */
- @Override
- public String getCharacterEncoding() {
- return null;
- }
-
- /**
- * @see javax.servlet.ServletRequest#setCharacterEncoding(String)
- */
- @Override
- public void setCharacterEncoding(final String arg0)
- throws UnsupportedEncodingException {
- }
-
- /**
- * @see javax.servlet.ServletRequest#getContentLength()
- */
- @Override
- public int getContentLength() {
- int iLength;
-
- if (null == mmRequestData) {
- iLength = -1;
- } else {
- if (length > Integer.MAX_VALUE) {
- throw new RuntimeException("Value '" + length + "' is too
large to be converted to int");
- }
- iLength = (int) length;
- }
- return iLength;
- }
-
- /**
- * For testing attack scenarios in SizesTest.
- */
- public void setContentLength(final long length) {
- this.length = length;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getContentType()
- */
- @Override
- public String getContentType() {
- return mStrContentType;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getInputStream()
- */
- @Override
- public ServletInputStream getInputStream() throws IOException {
- return new MyServletInputStream(mmRequestData, readLimit);
- }
-
- /**
- * Sets the read limit. This can be used to limit the number of bytes to
read ahead.
- *
- * @param readLimit the read limit to use
- */
- public void setReadLimit(final int readLimit) {
- this.readLimit = readLimit;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getParameter(String)
- */
- @Override
- public String getParameter(final String arg0) {
- return null;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getParameterNames()
- */
- @Override
- public Enumeration<String> getParameterNames() {
- return null;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getParameterValues(String)
- */
- @Override
- public String[] getParameterValues(final String arg0) {
- return null;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getParameterMap()
- */
- @Override
- public Map<String, String[]> getParameterMap() {
- return null;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getProtocol()
- */
- @Override
- public String getProtocol() {
- return null;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getScheme()
- */
- @Override
- public String getScheme() {
- return null;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getServerName()
- */
- @Override
- public String getServerName() {
- return null;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getLocalName()
- */
- @Override
- @SuppressWarnings("javadoc") // This is a Servlet 2.4 method
- public String getLocalName() {
- return null;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getServerPort()
- */
- @Override
- public int getServerPort() {
- return 0;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getLocalPort()
- */
- @Override
- @SuppressWarnings("javadoc") // This is a Servlet 2.4 method
- public int getLocalPort() {
- return 0;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getRemotePort()
- */
- @Override
- @SuppressWarnings("javadoc") // This is a Servlet 2.4 method
- public int getRemotePort() {
- return 0;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getReader()
- */
- @Override
- public BufferedReader getReader() throws IOException {
- return null;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getRemoteAddr()
- */
- @Override
- public String getRemoteAddr() {
- return null;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getLocalAddr()
- */
- @Override
- @SuppressWarnings("javadoc") // This is a Servlet 2.4 method
- public String getLocalAddr() {
- return null;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getRemoteHost()
- */
- @Override
- public String getRemoteHost() {
- return null;
- }
-
- /**
- * @see javax.servlet.ServletRequest#setAttribute(String, Object)
- */
- @Override
- public void setAttribute(final String arg0, final Object arg1) {
- }
-
- /**
- * @see javax.servlet.ServletRequest#removeAttribute(String)
- */
- @Override
- public void removeAttribute(final String arg0) {
- }
-
- /**
- * @see javax.servlet.ServletRequest#getLocale()
- */
- @Override
- public Locale getLocale() {
- return null;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getLocales()
- */
- @Override
- public Enumeration<Locale> getLocales() {
- return null;
- }
-
- /**
- * @see javax.servlet.ServletRequest#isSecure()
- */
- @Override
- public boolean isSecure() {
- return false;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getRequestDispatcher(String)
- */
- @Override
- public RequestDispatcher getRequestDispatcher(final String arg0) {
- return null;
- }
-
- /**
- * @see javax.servlet.ServletRequest#getRealPath(String)
- * @deprecated
- */
- @Override
- @Deprecated
- public String getRealPath(final String arg0) {
- return null;
- }
-
- private static class MyServletInputStream
- extends javax.servlet.ServletInputStream {
-
- private final InputStream in;
- private final int readLimit;
-
- /**
- * Creates a new instance, which returns the given
- * streams data.
- */
- public MyServletInputStream(final InputStream pStream, final int
readLimit) {
- in = pStream;
- this.readLimit = readLimit;
- }
-
- @Override
- public int read() throws IOException {
- return in.read();
- }
-
- @Override
- public int read(final byte[] b, final int off, final int len) throws
IOException {
- if (readLimit > 0) {
- return in.read(b, off, Math.min(readLimit, len));
- }
- return in.read(b, off, len);
- }
-
- }
-
-}
diff --git
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/ProgressListenerTest.java
b/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/ProgressListenerTest.java
deleted file mode 100644
index 553aefb4aa..0000000000
---
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/ProgressListenerTest.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.commons.fileupload2;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-
-import org.apache.wicket.commons.fileupload2.FileItemIterator;
-import org.apache.wicket.commons.fileupload2.FileItemStream;
-import org.apache.wicket.commons.fileupload2.FileUploadException;
-import org.apache.wicket.commons.fileupload2.ProgressListener;
-import org.apache.wicket.commons.fileupload2.servlet.ServletFileUpload;
-import org.junit.jupiter.api.Test;
-
-/**
- * Tests the {@link ProgressListener}.
- */
-public class ProgressListenerTest {
-
- private static class ProgressListenerImpl implements ProgressListener {
-
- private final long expectedContentLength;
-
- private final int expectedItems;
-
- private Long bytesRead;
-
- private Integer items;
-
- ProgressListenerImpl(final long pContentLength, final int pItems) {
- expectedContentLength = pContentLength;
- expectedItems = pItems;
- }
-
- @Override
- public void update(final long pBytesRead, final long pContentLength,
final int pItems) {
- assertTrue(pBytesRead >= 0 && pBytesRead <=
expectedContentLength);
- assertTrue(pContentLength == -1 || pContentLength ==
expectedContentLength);
- assertTrue(pItems >= 0 && pItems <= expectedItems);
-
- assertTrue(bytesRead == null || pBytesRead >=
bytesRead.longValue());
- bytesRead = Long.valueOf(pBytesRead);
- assertTrue(items == null || pItems >= items.intValue());
- items = Integer.valueOf(pItems);
- }
-
- void checkFinished() {
- assertEquals(expectedContentLength, bytesRead.longValue());
- assertEquals(expectedItems, items.intValue());
- }
-
- }
-
- /**
- * Parse a very long file upload by using a progress listener.
- */
- @Test
- public void testProgressListener() throws Exception {
- final int NUM_ITEMS = 512;
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- for (int i = 0; i < NUM_ITEMS; i++) {
- final String header = "-----1234\r\n"
- + "Content-Disposition: form-data; name=\"field" + (i + 1) +
"\"\r\n"
- + "\r\n";
- baos.write(header.getBytes(StandardCharsets.US_ASCII));
- for (int j = 0; j < 16384 + i; j++) {
- baos.write((byte) j);
- }
- baos.write("\r\n".getBytes(StandardCharsets.US_ASCII));
- }
- baos.write("-----1234--\r\n".getBytes(StandardCharsets.US_ASCII));
- final byte[] contents = baos.toByteArray();
-
- MockHttpServletRequest request = new MockHttpServletRequest(contents,
Constants.CONTENT_TYPE);
- runTest(NUM_ITEMS, contents.length, request);
- request = new MockHttpServletRequest(contents, Constants.CONTENT_TYPE)
{
- @Override
- public int getContentLength() {
- return -1;
- }
- };
- runTest(NUM_ITEMS, contents.length, request);
- }
-
- private void runTest(final int NUM_ITEMS, final long pContentLength, final
MockHttpServletRequest request) throws FileUploadException, IOException {
- final ServletFileUpload upload = new ServletFileUpload();
- final ProgressListenerImpl listener = new
ProgressListenerImpl(pContentLength, NUM_ITEMS);
- upload.setProgressListener(listener);
- final FileItemIterator iter = upload.getItemIterator(request);
- for (int i = 0; i < NUM_ITEMS; i++) {
- final FileItemStream stream = iter.next();
- final InputStream istream = stream.openStream();
- for (int j = 0; j < 16384 + i; j++) {
- /**
- * This used to be
- * assertEquals((byte) j, (byte) istream.read());
- * but this seems to trigger a bug in JRockit, so
- * we express the same like this:
- */
- final byte b1 = (byte) j;
- final byte b2 = (byte) istream.read();
- if (b1 != b2) {
- fail("Expected " + b1 + ", got " + b2);
- }
- }
- assertEquals(-1, istream.read());
- istream.close();
- }
- assertTrue(!iter.hasNext());
- listener.checkFinished();
- }
-
-}
diff --git
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/SizesTest.java
b/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/SizesTest.java
deleted file mode 100644
index e9b3ddab01..0000000000
---
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/SizesTest.java
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.commons.fileupload2;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.wicket.commons.fileupload2.FileItem;
-import org.apache.wicket.commons.fileupload2.FileItemIterator;
-import org.apache.wicket.commons.fileupload2.FileItemStream;
-import org.apache.wicket.commons.fileupload2.FileUploadException;
-import org.apache.wicket.commons.fileupload2.disk.DiskFileItemFactory;
-import
org.apache.wicket.commons.fileupload2.pub.FileSizeLimitExceededException;
-import org.apache.wicket.commons.fileupload2.pub.FileUploadIOException;
-import org.apache.wicket.commons.fileupload2.pub.SizeLimitExceededException;
-import org.apache.wicket.commons.fileupload2.servlet.ServletFileUpload;
-import org.apache.wicket.commons.fileupload2.util.Streams;
-import org.junit.jupiter.api.Test;
-
-/**
- * Unit test for items with varying sizes.
- */
-public class SizesTest {
-
- /**
- * Runs a test with varying file sizes.
- */
- @Test
- public void testFileUpload()
- throws IOException, FileUploadException {
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- int add = 16;
- int num = 0;
- for (int i = 0; i < 16384; i += add) {
- if (++add == 32) {
- add = 16;
- }
- final String header = "-----1234\r\n"
- + "Content-Disposition: form-data; name=\"field" + (num++) +
"\"\r\n"
- + "\r\n";
- baos.write(header.getBytes(StandardCharsets.US_ASCII));
- for (int j = 0; j < i; j++) {
- baos.write((byte) j);
- }
- baos.write("\r\n".getBytes(StandardCharsets.US_ASCII));
- }
- baos.write("-----1234--\r\n".getBytes(StandardCharsets.US_ASCII));
-
- final List<FileItem> fileItems =
- Util.parseUpload(new ServletFileUpload(new
DiskFileItemFactory()), baos.toByteArray());
- final Iterator<FileItem> fileIter = fileItems.iterator();
- add = 16;
- num = 0;
- for (int i = 0; i < 16384; i += add) {
- if (++add == 32) {
- add = 16;
- }
- final FileItem item = fileIter.next();
- assertEquals("field" + (num++), item.getFieldName());
- final byte[] bytes = item.get();
- assertEquals(i, bytes.length);
- for (int j = 0; j < i; j++) {
- assertEquals((byte) j, bytes[j]);
- }
- }
- assertTrue(!fileIter.hasNext());
- }
-
- /** Checks, whether limiting the file size works.
- */
- @Test
- public void testFileSizeLimit()
- throws IOException, FileUploadException {
- final String request =
- "-----1234\r\n" +
- "Content-Disposition: form-data; name=\"file\";
filename=\"foo.tab\"\r\n" +
- "Content-Type: text/whatever\r\n" +
- "\r\n" +
- "This is the content of the file\n" +
- "\r\n" +
- "-----1234--\r\n";
-
- ServletFileUpload upload = new ServletFileUpload(new
DiskFileItemFactory());
- upload.setFileSizeMax(-1);
- HttpServletRequest req = new MockHttpServletRequest(
- request.getBytes(StandardCharsets.US_ASCII),
Constants.CONTENT_TYPE);
- List<FileItem> fileItems = upload.parseRequest(req);
- assertEquals(1, fileItems.size());
- FileItem item = fileItems.get(0);
- assertEquals("This is the content of the file\n", new
String(item.get()));
-
- upload = new ServletFileUpload(new DiskFileItemFactory());
- upload.setFileSizeMax(40);
- req = new
MockHttpServletRequest(request.getBytes(StandardCharsets.US_ASCII),
Constants.CONTENT_TYPE);
- fileItems = upload.parseRequest(req);
- assertEquals(1, fileItems.size());
- item = fileItems.get(0);
- assertEquals("This is the content of the file\n", new
String(item.get()));
-
- upload = new ServletFileUpload(new DiskFileItemFactory());
- upload.setFileSizeMax(30);
- req = new
MockHttpServletRequest(request.getBytes(StandardCharsets.US_ASCII),
Constants.CONTENT_TYPE);
- try {
- upload.parseRequest(req);
- fail("Expected exception.");
- } catch (final FileSizeLimitExceededException e) {
- assertEquals(30, e.getPermittedSize());
- }
- }
-
- /** Checks, whether a faked Content-Length header is detected.
- */
- @Test
- public void testFileSizeLimitWithFakedContentLength()
- throws IOException, FileUploadException {
- final String request =
- "-----1234\r\n" +
- "Content-Disposition: form-data; name=\"file\";
filename=\"foo.tab\"\r\n" +
- "Content-Type: text/whatever\r\n" +
- "Content-Length: 10\r\n" +
- "\r\n" +
- "This is the content of the file\n" +
- "\r\n" +
- "-----1234--\r\n";
-
- ServletFileUpload upload = new ServletFileUpload(new
DiskFileItemFactory());
- upload.setFileSizeMax(-1);
- HttpServletRequest req = new MockHttpServletRequest(
- request.getBytes(StandardCharsets.US_ASCII),
Constants.CONTENT_TYPE);
- List<FileItem> fileItems = upload.parseRequest(req);
- assertEquals(1, fileItems.size());
- FileItem item = fileItems.get(0);
- assertEquals("This is the content of the file\n", new
String(item.get()));
-
- upload = new ServletFileUpload(new DiskFileItemFactory());
- upload.setFileSizeMax(40);
- req = new
MockHttpServletRequest(request.getBytes(StandardCharsets.US_ASCII),
Constants.CONTENT_TYPE);
- fileItems = upload.parseRequest(req);
- assertEquals(1, fileItems.size());
- item = fileItems.get(0);
- assertEquals("This is the content of the file\n", new
String(item.get()));
-
- // provided Content-Length is larger than the FileSizeMax -> handled
by ctor
- upload = new ServletFileUpload(new DiskFileItemFactory());
- upload.setFileSizeMax(5);
- req = new
MockHttpServletRequest(request.getBytes(StandardCharsets.US_ASCII),
Constants.CONTENT_TYPE);
- try {
- upload.parseRequest(req);
- fail("Expected exception.");
- } catch (final FileSizeLimitExceededException e) {
- assertEquals(5, e.getPermittedSize());
- }
-
- // provided Content-Length is wrong, actual content is larger ->
handled by LimitedInputStream
- upload = new ServletFileUpload(new DiskFileItemFactory());
- upload.setFileSizeMax(15);
- req = new
MockHttpServletRequest(request.getBytes(StandardCharsets.US_ASCII),
Constants.CONTENT_TYPE);
- try {
- upload.parseRequest(req);
- fail("Expected exception.");
- } catch (final FileSizeLimitExceededException e) {
- assertEquals(15, e.getPermittedSize());
- }
- }
-
- /** Checks, whether the maxSize works.
- */
- @Test
- public void testMaxSizeLimit()
- throws IOException, FileUploadException {
- final String request =
- "-----1234\r\n" +
- "Content-Disposition: form-data; name=\"file1\";
filename=\"foo1.tab\"\r\n" +
- "Content-Type: text/whatever\r\n" +
- "Content-Length: 10\r\n" +
- "\r\n" +
- "This is the content of the file\n" +
- "\r\n" +
- "-----1234\r\n" +
- "Content-Disposition: form-data; name=\"file2\";
filename=\"foo2.tab\"\r\n" +
- "Content-Type: text/whatever\r\n" +
- "\r\n" +
- "This is the content of the file\n" +
- "\r\n" +
- "-----1234--\r\n";
-
- final ServletFileUpload upload = new ServletFileUpload(new
DiskFileItemFactory());
- upload.setFileSizeMax(-1);
- upload.setSizeMax(200);
-
- final MockHttpServletRequest req = new MockHttpServletRequest(
- request.getBytes(StandardCharsets.US_ASCII),
Constants.CONTENT_TYPE);
- try {
- upload.parseRequest(req);
- fail("Expected exception.");
- } catch (final SizeLimitExceededException e) {
- assertEquals(200, e.getPermittedSize());
- }
- }
-
- @Test
- public void testMaxSizeLimitUnknownContentLength()
- throws IOException, FileUploadException {
- final String request =
- "-----1234\r\n" +
- "Content-Disposition: form-data; name=\"file1\";
filename=\"foo1.tab\"\r\n" +
- "Content-Type: text/whatever\r\n" +
- "Content-Length: 10\r\n" +
- "\r\n" +
- "This is the content of the file\n" +
- "\r\n" +
- "-----1234\r\n" +
- "Content-Disposition: form-data; name=\"file2\";
filename=\"foo2.tab\"\r\n" +
- "Content-Type: text/whatever\r\n" +
- "\r\n" +
- "This is the content of the file\n" +
- "\r\n" +
- "-----1234--\r\n";
-
- final ServletFileUpload upload = new ServletFileUpload(new
DiskFileItemFactory());
- upload.setFileSizeMax(-1);
- upload.setSizeMax(300);
-
- // the first item should be within the max size limit
- // set the read limit to 10 to simulate a "real" stream
- // otherwise the buffer would be immediately filled
-
- final MockHttpServletRequest req = new MockHttpServletRequest(
- request.getBytes(StandardCharsets.US_ASCII),
Constants.CONTENT_TYPE);
- req.setContentLength(-1);
- req.setReadLimit(10);
-
- final FileItemIterator it = upload.getItemIterator(req);
- assertTrue(it.hasNext());
-
- FileItemStream item = it.next();
- assertFalse(item.isFormField());
- assertEquals("file1", item.getFieldName());
- assertEquals("foo1.tab", item.getName());
-
- {
- final InputStream stream = item.openStream();
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Streams.copy(stream, baos, true);
- }
-
- // the second item is over the size max, thus we expect an error
- try {
- // the header is still within size max -> this shall still succeed
- assertTrue(it.hasNext());
- } catch (final SizeLimitExceededException e) {
- fail();
- }
-
- item = it.next();
-
- try {
- final InputStream stream = item.openStream();
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Streams.copy(stream, baos, true);
- fail();
- } catch (final FileUploadIOException e) {
- // expected
- }
- }
-
-}
diff --git
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/StreamingTest.java
b/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/StreamingTest.java
deleted file mode 100644
index c6c034d66c..0000000000
---
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/StreamingTest.java
+++ /dev/null
@@ -1,288 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.commons.fileupload2;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FilterInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStreamWriter;
-import java.nio.charset.StandardCharsets;
-import java.util.Iterator;
-import java.util.List;
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.wicket.commons.fileupload2.FileItem;
-import org.apache.wicket.commons.fileupload2.FileItemIterator;
-import org.apache.wicket.commons.fileupload2.FileItemStream;
-import org.apache.wicket.commons.fileupload2.FileUploadBase;
-import org.apache.wicket.commons.fileupload2.FileUploadException;
-import org.apache.wicket.commons.fileupload2.InvalidFileNameException;
-import org.apache.wicket.commons.fileupload2.MultipartStream;
-import org.apache.wicket.commons.fileupload2.disk.DiskFileItemFactory;
-import org.apache.wicket.commons.fileupload2.pub.IOFileUploadException;
-import org.apache.wicket.commons.fileupload2.servlet.ServletFileUpload;
-import org.apache.wicket.commons.fileupload2.servlet.ServletRequestContext;
-import org.junit.jupiter.api.Test;
-
-/**
- * Unit test for items with varying sizes.
- */
-public class StreamingTest {
-
- /**
- * Tests a file upload with varying file sizes.
- */
- @Test
- public void testFileUpload()
- throws IOException, FileUploadException {
- final byte[] request = newRequest();
- final List<FileItem> fileItems = parseUpload(request);
- final Iterator<FileItem> fileIter = fileItems.iterator();
- int add = 16;
- int num = 0;
- for (int i = 0; i < 16384; i += add) {
- if (++add == 32) {
- add = 16;
- }
- final FileItem item = fileIter.next();
- assertEquals("field" + (num++), item.getFieldName());
- final byte[] bytes = item.get();
- assertEquals(i, bytes.length);
- for (int j = 0; j < i; j++) {
- assertEquals((byte) j, bytes[j]);
- }
- }
- assertTrue(!fileIter.hasNext());
- }
-
- /**
- * Tests, whether an invalid request throws a proper
- * exception.
- */
- @Test
- public void testFileUploadException()
- throws IOException, FileUploadException {
- final byte[] request = newRequest();
- final byte[] invalidRequest = new byte[request.length - 11];
- System.arraycopy(request, 0, invalidRequest, 0, request.length - 11);
- try {
- parseUpload(invalidRequest);
- fail("Expected EndOfStreamException");
- } catch (final IOFileUploadException e) {
- assertTrue(e.getCause() instanceof
MultipartStream.MalformedStreamException);
- }
- }
-
- /**
- * Tests, whether an IOException is properly delegated.
- */
- @Test
- public void testIOException()
- throws IOException {
- final byte[] request = newRequest();
- final InputStream stream = new FilterInputStream(new
ByteArrayInputStream(request)) {
- private int num;
- @Override
- public int read() throws IOException {
- if (++num > 123) {
- throw new IOException("123");
- }
- return super.read();
- }
- @Override
- public int read(final byte[] pB, final int pOff, final int pLen)
- throws IOException {
- for (int i = 0; i < pLen; i++) {
- final int res = read();
- if (res == -1) {
- return i == 0 ? -1 : i;
- }
- pB[pOff + i] = (byte) res;
- }
- return pLen;
- }
- };
- try {
- parseUpload(stream, request.length);
- fail("Expected IOException");
- } catch (final FileUploadException e) {
- assertTrue(e.getCause() instanceof IOException);
- assertEquals("123", e.getCause().getMessage());
- }
- }
-
- /**
- * Test for FILEUPLOAD-135
- */
- @Test
- public void testFILEUPLOAD135()
- throws IOException, FileUploadException {
- final byte[] request = newShortRequest();
- final ByteArrayInputStream bais = new ByteArrayInputStream(request);
- final List<FileItem> fileItems = parseUpload(new InputStream() {
- @Override
- public int read()
- throws IOException
- {
- return bais.read();
- }
- @Override
- public int read(final byte[] b, final int off, final int len)
throws IOException
- {
- return bais.read(b, off, Math.min(len, 3));
- }
-
- }, request.length);
- final Iterator<FileItem> fileIter = fileItems.iterator();
- assertTrue(fileIter.hasNext());
- final FileItem item = fileIter.next();
- assertEquals("field", item.getFieldName());
- final byte[] bytes = item.get();
- assertEquals(3, bytes.length);
- assertEquals((byte)'1', bytes[0]);
- assertEquals((byte)'2', bytes[1]);
- assertEquals((byte)'3', bytes[2]);
- assertTrue(!fileIter.hasNext());
- }
-
- private List<FileItem> parseUpload(final byte[] bytes) throws
FileUploadException {
- return parseUpload(new ByteArrayInputStream(bytes), bytes.length);
- }
-
- private FileItemIterator parseUpload(final int pLength, final InputStream
pStream)
- throws FileUploadException, IOException {
- final String contentType = "multipart/form-data; boundary=---1234";
-
- final FileUploadBase upload = new ServletFileUpload();
- upload.setFileItemFactory(new DiskFileItemFactory());
- final HttpServletRequest request = new MockHttpServletRequest(pStream,
- pLength, contentType);
-
- return upload.getItemIterator(new ServletRequestContext(request));
- }
-
- private List<FileItem> parseUpload(final InputStream pStream, final int
pLength)
- throws FileUploadException {
- final String contentType = "multipart/form-data; boundary=---1234";
-
- final FileUploadBase upload = new ServletFileUpload();
- upload.setFileItemFactory(new DiskFileItemFactory());
- final HttpServletRequest request = new MockHttpServletRequest(pStream,
- pLength, contentType);
-
- return upload.parseRequest(new ServletRequestContext(request));
- }
-
- private String getHeader(final String pField) {
- return "-----1234\r\n"
- + "Content-Disposition: form-data; name=\"" + pField + "\"\r\n"
- + "\r\n";
-
- }
-
- private String getFooter() {
- return "-----1234--\r\n";
- }
-
- private byte[] newShortRequest() throws IOException {
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- final OutputStreamWriter osw = new OutputStreamWriter(baos,
StandardCharsets.US_ASCII);
- osw.write(getHeader("field"));
- osw.write("123");
- osw.write("\r\n");
- osw.write(getFooter());
- osw.close();
- return baos.toByteArray();
- }
-
- private byte[] newRequest() throws IOException {
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- final OutputStreamWriter osw = new OutputStreamWriter(baos,
StandardCharsets.US_ASCII);
- int add = 16;
- int num = 0;
- for (int i = 0; i < 16384; i += add) {
- if (++add == 32) {
- add = 16;
- }
- osw.write(getHeader("field" + (num++)));
- osw.flush();
- for (int j = 0; j < i; j++) {
- baos.write((byte) j);
- }
- osw.write("\r\n");
- }
- osw.write(getFooter());
- osw.close();
- return baos.toByteArray();
- }
-
- /**
- * Tests, whether an {@link InvalidFileNameException} is thrown.
- */
- @Test
- public void testInvalidFileNameException() throws Exception {
- final String fileName = "foo.exe\u0000.png";
- final String request =
- "-----1234\r\n" +
- "Content-Disposition: form-data; name=\"file\"; filename=\"" +
fileName + "\"\r\n" +
- "Content-Type: text/whatever\r\n" +
- "\r\n" +
- "This is the content of the file\n" +
- "\r\n" +
- "-----1234\r\n" +
- "Content-Disposition: form-data; name=\"field\"\r\n" +
- "\r\n" +
- "fieldValue\r\n" +
- "-----1234\r\n" +
- "Content-Disposition: form-data; name=\"multi\"\r\n" +
- "\r\n" +
- "value1\r\n" +
- "-----1234\r\n" +
- "Content-Disposition: form-data; name=\"multi\"\r\n" +
- "\r\n" +
- "value2\r\n" +
- "-----1234--\r\n";
- final byte[] reqBytes = request.getBytes(StandardCharsets.US_ASCII);
-
- final FileItemIterator fileItemIter = parseUpload(reqBytes.length, new
ByteArrayInputStream(reqBytes));
- final FileItemStream fileItemStream = fileItemIter.next();
- try {
- fileItemStream.getName();
- fail("Expected exception");
- } catch (final InvalidFileNameException e) {
- assertEquals(fileName, e.getName());
- assertEquals(-1, e.getMessage().indexOf(fileName));
- assertTrue(e.getMessage().contains("foo.exe\\0.png"));
- }
-
- try {
- parseUpload(reqBytes);
- fail("Expected exception");
- } catch (final InvalidFileNameException e) {
- assertEquals(fileName, e.getName());
- assertEquals(-1, e.getMessage().indexOf(fileName));
- assertTrue(e.getMessage().contains("foo.exe\\0.png"));
- }
- }
-
-}
diff --git
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/Util.java
b/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/Util.java
deleted file mode 100644
index 62b4996098..0000000000
---
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/Util.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.commons.fileupload2;
-
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.wicket.commons.fileupload2.FileItem;
-import org.apache.wicket.commons.fileupload2.FileUpload;
-import org.apache.wicket.commons.fileupload2.FileUploadException;
-import org.apache.wicket.commons.fileupload2.disk.DiskFileItemFactory;
-import org.apache.wicket.commons.fileupload2.portlet.PortletFileUpload;
-import org.apache.wicket.commons.fileupload2.servlet.ServletFileUpload;
-import org.apache.wicket.commons.fileupload2.servlet.ServletRequestContext;
-
-/**
- * Test utility methods.
- *
- * @since 1.4
- */
-public class Util {
-
- public static List<FileItem> parseUpload(final FileUpload upload, final
byte[] bytes) throws FileUploadException {
- return parseUpload(upload, bytes, Constants.CONTENT_TYPE);
- }
-
- public static List<FileItem> parseUpload(final FileUpload upload, final
byte[] bytes, final String contentType)
- throws FileUploadException {
- final HttpServletRequest request = new MockHttpServletRequest(bytes,
contentType);
- return upload.parseRequest(new ServletRequestContext(request));
- }
-
- public static List<FileItem> parseUpload(final FileUpload upload, final
String content)
- throws UnsupportedEncodingException, FileUploadException {
- final byte[] bytes = content.getBytes(StandardCharsets.US_ASCII);
- return parseUpload(upload, bytes, Constants.CONTENT_TYPE);
- }
-
- /**
- * Return a list of {@link FileUpload} implementations for parameterized
tests.
- * @return a list of {@link FileUpload} implementations
- */
- public static List<FileUpload> fileUploadImplementations() {
- return Arrays.asList(
- new ServletFileUpload(new DiskFileItemFactory()),
- new PortletFileUpload(new DiskFileItemFactory()));
- }
-}
diff --git
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/jaksrvlt/JakSrvltFileUploadTest.java
b/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/jaksrvlt/JakSrvltFileUploadTest.java
index d323fd9e21..340dddc117 100644
---
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/jaksrvlt/JakSrvltFileUploadTest.java
+++
b/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/jaksrvlt/JakSrvltFileUploadTest.java
@@ -27,7 +27,6 @@ import jakarta.servlet.http.HttpServletRequest;
import org.apache.wicket.commons.fileupload2.Constants;
import org.apache.wicket.commons.fileupload2.FileItem;
-import org.apache.wicket.commons.fileupload2.FileUploadTest;
import org.apache.wicket.commons.fileupload2.disk.DiskFileItemFactory;
import org.apache.wicket.commons.fileupload2.jaksrvlt.JakSrvltFileUpload;
import org.junit.jupiter.api.Test;
@@ -35,7 +34,6 @@ import org.junit.jupiter.api.Test;
/**
* Test for {@link
org.apache.wicket.commons.fileupload2.servlet.ServletFileUpload}.
*
- * @see FileUploadTest
* @since 1.4
*/
public class JakSrvltFileUploadTest {
diff --git
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/portlet/MockPortletActionRequest.java
b/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/portlet/MockPortletActionRequest.java
deleted file mode 100644
index c23b0d1712..0000000000
---
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/portlet/MockPortletActionRequest.java
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.commons.fileupload2.portlet;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.security.Principal;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Locale;
-import java.util.Map;
-
-import javax.portlet.ActionRequest;
-import javax.portlet.PortalContext;
-import javax.portlet.PortletMode;
-import javax.portlet.PortletPreferences;
-import javax.portlet.PortletSession;
-import javax.portlet.WindowState;
-
-import org.apache.wicket.commons.fileupload2.FileUploadBase;
-
-/**
- * Mock class for tests. Implements an {@link ActionRequest}.
- *
- * @see PortletFileUploadTest
- * @since 1.4
- */
-@SuppressWarnings("rawtypes") // because of the portlet ActionRequest API does
not use generics
-public class MockPortletActionRequest implements ActionRequest {
-
- private final Hashtable<String, Object> attributes = new Hashtable<>();
-
- private final Map<String, String> parameters = new HashMap<>();
-
- private String characterEncoding;
- private final int length;
- private final String contentType;
- private final InputStream requestData;
-
- public MockPortletActionRequest(final byte[] requestData, final String
contentType) {
- this(new ByteArrayInputStream(requestData), requestData.length,
contentType);
- }
-
- public MockPortletActionRequest(final ByteArrayInputStream
byteArrayInputStream,
- final int requestLength, final String
contentType) {
- this.requestData = byteArrayInputStream;
- length = requestLength;
- this.contentType = contentType;
- attributes.put(FileUploadBase.CONTENT_TYPE, contentType);
- }
-
- @Override
- public Object getAttribute(final String key) {
- return attributes.get(key);
- }
-
- @Override
- public Enumeration getAttributeNames() {
- return attributes.keys();
- }
-
- @Override
- public String getAuthType() {
- return null;
- }
-
- @Override
- public String getContextPath() {
- return null;
- }
-
- @Override
- public Locale getLocale() {
- return Locale.getDefault();
- }
-
- @Override
- public Enumeration getLocales() {
- return
Collections.enumeration(Arrays.asList(Locale.getAvailableLocales()));
- }
-
- @Override
- public String getParameter(final String key) {
- return parameters.get(key);
- }
-
- @Override
- public Map getParameterMap() {
- return Collections.unmodifiableMap(parameters);
- }
-
- @Override
- public Enumeration getParameterNames() {
- return Collections.enumeration(parameters.keySet());
- }
-
- @Override
- public String[] getParameterValues(final String arg0) {
- return null;
- }
-
- @Override
- public PortalContext getPortalContext() {
- return null;
- }
-
- @Override
- public PortletMode getPortletMode() {
- return null;
- }
-
- @Override
- public PortletSession getPortletSession() {
- return null;
- }
-
- @Override
- public PortletSession getPortletSession(final boolean arg0) {
- return null;
- }
-
- @Override
- public PortletPreferences getPreferences() {
- return null;
- }
-
- @Override
- public Enumeration getProperties(final String arg0) {
- return null;
- }
-
- @Override
- public String getProperty(final String arg0) {
- return null;
- }
-
- @Override
- public Enumeration getPropertyNames() {
- return null;
- }
-
- @Override
- public String getRemoteUser() {
- return null;
- }
-
- @Override
- public String getRequestedSessionId() {
- return null;
- }
-
- @Override
- public String getResponseContentType() {
- return null;
- }
-
- @Override
- public Enumeration getResponseContentTypes() {
- return null;
- }
-
- @Override
- public String getScheme() {
- return null;
- }
-
- @Override
- public String getServerName() {
- return null;
- }
-
- @Override
- public int getServerPort() {
- return 0;
- }
-
- @Override
- public Principal getUserPrincipal() {
- return null;
- }
-
- @Override
- public WindowState getWindowState() {
- return null;
- }
-
- @Override
- public boolean isPortletModeAllowed(final PortletMode arg0) {
- return false;
- }
-
- @Override
- public boolean isRequestedSessionIdValid() {
- return false;
- }
-
- @Override
- public boolean isSecure() {
- return false;
- }
-
- @Override
- public boolean isUserInRole(final String arg0) {
- return false;
- }
-
- @Override
- public boolean isWindowStateAllowed(final WindowState arg0) {
- return false;
- }
-
- @Override
- public void removeAttribute(final String key) {
- attributes.remove(key);
- }
-
- @Override
- public void setAttribute(final String key, final Object value) {
- attributes.put(key, value);
- }
-
- @Override
- public String getCharacterEncoding() {
- return characterEncoding;
- }
-
- @Override
- public int getContentLength() {
- return length;
- }
-
- @Override
- public String getContentType() {
- return contentType;
- }
-
- @Override
- public InputStream getPortletInputStream() throws IOException {
- return requestData;
- }
-
- @Override
- public BufferedReader getReader() throws UnsupportedEncodingException,
IOException {
- return null;
- }
-
- @Override
- public void setCharacterEncoding(final String characterEncoding) throws
UnsupportedEncodingException {
- this.characterEncoding = characterEncoding;
- }
-
-}
diff --git
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/portlet/PortletFileUploadTest.java
b/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/portlet/PortletFileUploadTest.java
deleted file mode 100644
index 8ccb728215..0000000000
---
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/portlet/PortletFileUploadTest.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.commons.fileupload2.portlet;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.nio.charset.StandardCharsets;
-import java.util.List;
-import java.util.Map;
-
-import javax.portlet.ActionRequest;
-
-import org.apache.wicket.commons.fileupload2.Constants;
-import org.apache.wicket.commons.fileupload2.FileItem;
-import org.apache.wicket.commons.fileupload2.FileUploadTest;
-import org.apache.wicket.commons.fileupload2.disk.DiskFileItemFactory;
-import org.apache.wicket.commons.fileupload2.portlet.PortletFileUpload;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-/**
- * Test for {@link PortletFileUpload}.
- *
- * @see FileUploadTest
- * @since 1.4
- */
-public class PortletFileUploadTest {
-
- private PortletFileUpload upload;
-
- @BeforeEach
- public void setUp() {
- upload = new PortletFileUpload(new DiskFileItemFactory());
- }
-
- @Test
- public void parseParameterMap()
- throws Exception {
- final String text = "-----1234\r\n" +
- "Content-Disposition: form-data; name=\"file\";
filename=\"foo.tab\"\r\n" +
- "Content-Type: text/whatever\r\n" +
- "\r\n" +
- "This is the content of the file\n" +
- "\r\n" +
- "-----1234\r\n" +
- "Content-Disposition: form-data; name=\"field\"\r\n" +
- "\r\n" +
- "fieldValue\r\n" +
- "-----1234\r\n" +
- "Content-Disposition: form-data; name=\"multi\"\r\n" +
- "\r\n" +
- "value1\r\n" +
- "-----1234\r\n" +
- "Content-Disposition: form-data; name=\"multi\"\r\n" +
- "\r\n" +
- "value2\r\n" +
- "-----1234--\r\n";
- final byte[] bytes = text.getBytes(StandardCharsets.US_ASCII);
- final ActionRequest request = new MockPortletActionRequest(bytes,
Constants.CONTENT_TYPE);
-
- final Map<String, List<FileItem>> mappedParameters =
upload.parseParameterMap(request);
- assertTrue(mappedParameters.containsKey("file"));
- assertEquals(1, mappedParameters.get("file").size());
-
- assertTrue(mappedParameters.containsKey("field"));
- assertEquals(1, mappedParameters.get("field").size());
-
- assertTrue(mappedParameters.containsKey("multi"));
- assertEquals(2, mappedParameters.get("multi").size());
- }
-
-}
diff --git
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/servlet/ServletFileUploadTest.java
b/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/servlet/ServletFileUploadTest.java
deleted file mode 100644
index 69c36aef2e..0000000000
---
a/wicket-commons-fileupload/src/test/java/org/apache/wicket/commons/fileupload2/servlet/ServletFileUploadTest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.commons.fileupload2.servlet;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.nio.charset.StandardCharsets;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.wicket.commons.fileupload2.Constants;
-import org.apache.wicket.commons.fileupload2.FileItem;
-import org.apache.wicket.commons.fileupload2.FileUploadTest;
-import org.apache.wicket.commons.fileupload2.MockHttpServletRequest;
-import org.apache.wicket.commons.fileupload2.disk.DiskFileItemFactory;
-import org.apache.wicket.commons.fileupload2.servlet.ServletFileUpload;
-import org.junit.jupiter.api.Test;
-
-/**
- * Test for {@link ServletFileUpload}.
- *
- * @see FileUploadTest
- * @since 1.4
- */
-public class ServletFileUploadTest {
-
- /**
- * Test case for <a
href="https://issues.apache.org/jira/browse/FILEUPLOAD-210">
- */
- @Test
- public void parseParameterMap()
- throws Exception {
- final String text = "-----1234\r\n" +
- "Content-Disposition: form-data; name=\"file\";
filename=\"foo.tab\"\r\n" +
- "Content-Type: text/whatever\r\n" +
- "\r\n" +
- "This is the content of the file\n" +
- "\r\n" +
- "-----1234\r\n" +
- "Content-Disposition: form-data; name=\"field\"\r\n" +
- "\r\n" +
- "fieldValue\r\n" +
- "-----1234\r\n" +
- "Content-Disposition: form-data; name=\"multi\"\r\n" +
- "\r\n" +
- "value1\r\n" +
- "-----1234\r\n" +
- "Content-Disposition: form-data; name=\"multi\"\r\n" +
- "\r\n" +
- "value2\r\n" +
- "-----1234--\r\n";
- final byte[] bytes = text.getBytes(StandardCharsets.US_ASCII);
- final HttpServletRequest request = new MockHttpServletRequest(bytes,
Constants.CONTENT_TYPE);
-
- final ServletFileUpload upload = new ServletFileUpload(new
DiskFileItemFactory());
- final Map<String, List<FileItem>> mappedParameters =
upload.parseParameterMap(request);
- assertTrue(mappedParameters.containsKey("file"));
- assertEquals(1, mappedParameters.get("file").size());
-
- assertTrue(mappedParameters.containsKey("field"));
- assertEquals(1, mappedParameters.get("field").size());
-
- assertTrue(mappedParameters.containsKey("multi"));
- assertEquals(2, mappedParameters.get("multi").size());
- }
-
-
- @Test
- public void parseImpliedUtf8()
- throws Exception {
- // utf8 encoded form-data without explicit content-type encoding
- final String text = "-----1234\r\n" +
- "Content-Disposition: form-data; name=\"utf8Html\"\r\n" +
- "\r\n" +
- "Thís ís the coñteñt of the fíle\n" +
- "\r\n" +
- "-----1234--\r\n";
-
- final byte[] bytes = text.getBytes(StandardCharsets.UTF_8);
- final HttpServletRequest request = new MockHttpServletRequest(bytes,
Constants.CONTENT_TYPE);
-
- final DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
- fileItemFactory.setDefaultCharset("UTF-8");
- final ServletFileUpload upload = new
ServletFileUpload(fileItemFactory);
- final List<FileItem> fileItems = upload.parseRequest(request);
- final FileItem fileItem = fileItems.get(0);
- assertTrue(fileItem.getString().contains("coñteñt"),
fileItem.getString());
- }
-}
diff --git a/wicket-core/pom.xml b/wicket-core/pom.xml
index 583cc0727e..eb73608f28 100644
--- a/wicket-core/pom.xml
+++ b/wicket-core/pom.xml
@@ -28,11 +28,11 @@
<name>Wicket Core</name>
<description>
Wicket is a Java web application framework that takes
simplicity,
- separation of concerns and ease of development to a whole new
level.
- Wicket pages can be mocked up, previewed and later revised
using
- standard WYSIWYG HTML design tools. Dynamic content processing
and
- form handling is all handled in Java code using a first-class
- component model backed by POJO data beans that can easily be
+ separation of concerns and ease of development to a whole new
level.
+ Wicket pages can be mocked up, previewed and later revised using
+ standard WYSIWYG HTML design tools. Dynamic content processing
and
+ form handling is all handled in Java code using a first-class
+ component model backed by POJO data beans that can easily be
persisted using your favorite technology.
</description>
<properties>
@@ -143,7 +143,7 @@ org.apache.wicket.util.template;-noimport:=true,
org.apache.wicket.util.tester;-noimport:=true,
org.apache.wicket.validation;-noimport:=true,
org.apache.wicket.validation.validator;-noimport:=true
- </osgi.export.package>
+ </osgi.export.package>
<osgi.import.package>!java*,!kotlin*,!sun.nio.ch,!com.sun.crypto.provider,org.slf4j*;version="[1.7,3)",jakarta.servlet,jakarta.servlet.http,*</osgi.import.package>
</properties>
<dependencies>
@@ -161,6 +161,10 @@ org.apache.wicket.validation.validator;-noimport:=true
<groupId>com.github.openjson</groupId>
<artifactId>openjson</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.wicket</groupId>
+ <artifactId>wicket-commons-fileupload</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-request</artifactId>
diff --git a/wicket-util/pom.xml b/wicket-util/pom.xml
index 801f8282d9..0368b81135 100755
--- a/wicket-util/pom.xml
+++ b/wicket-util/pom.xml
@@ -48,7 +48,6 @@
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-commons-fileupload</artifactId>
- <version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>