Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 39 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@

<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
<maven.compiler.showWarnings>true</maven.compiler.showWarnings>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>24</maven.compiler.source>
<maven.compiler.target>24</maven.compiler.target>

<!-- Project Versions -->
<asm.version>9.8</asm.version>
Expand All @@ -151,6 +151,7 @@
<commons-fileupload.version>2.0.0-M2</commons-fileupload.version>
<commons-io.version>2.19.0</commons-io.version>
<commons-lang3.version>3.17.0</commons-lang3.version>
<tomcat.version>12.0.0-M1-SNAPSHOT</tomcat.version>
<guice.version>7.0.0</guice.version>
<el-impl.version>2.2.1-b05</el-impl.version>
<error_prone_annotations.version>2.38.0</error_prone_annotations.version>
Expand Down Expand Up @@ -338,6 +339,16 @@
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-api</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-coyote</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
Expand Down Expand Up @@ -1462,6 +1473,32 @@
</plugins>
</build>
</profile>
<profile>
<id>java24</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>${maven-toolchains-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>24</version>
</jdk>
</toolchains>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>on-jdk-11-or-12</id>
<activation>
Expand All @@ -1471,15 +1508,6 @@
<javadoc.additionalJOption>--no-module-directories</javadoc.additionalJOption>
</properties>
</profile>
<profile>
<id>on-jdk-early-access</id>
<activation>
<jdk>[24,)</jdk>
</activation>
<properties>
<javadoc.jdk.apidocs.link>https://download.java.net/java/early_access/jdk${java.specification.version}/docs/api/</javadoc.jdk.apidocs.link>
</properties>
</profile>
</profiles>
<reporting>
<plugins>
Expand Down
8 changes: 8 additions & 0 deletions wicket-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ org.apache.wicket.validation.validator;-noimport:=true
<groupId>com.github.openjson</groupId>
<artifactId>openjson</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-coyote</artifactId>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-request</artifactId>
Expand Down
4 changes: 3 additions & 1 deletion wicket-core/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
requires org.danekja.jdk.serializable.functional;
requires com.github.openjson;
requires static org.bouncycastle.provider;
requires org.apache.tomcat.coyote;
requires org.apache.tomcat.api;

provides org.apache.wicket.IInitializer with org.apache.wicket.Initializer;
provides org.apache.wicket.IInitializer with org.apache.wicket.Initializer;
provides org.apache.wicket.resource.FileSystemPathService with org.apache.wicket.resource.FileSystemJarPathService;

uses org.apache.wicket.IInitializer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.commons.fileupload2.core.FileUploadByteCountLimitException;
import org.apache.commons.fileupload2.core.FileUploadSizeException;
import org.apache.commons.fileupload2.core.FileUploadFileCountLimitException;
import org.apache.wicket.Application;
import org.apache.wicket.Component;
import org.apache.wicket.IGenericComponent;
import org.apache.wicket.IRequestListener;
Expand All @@ -50,6 +51,7 @@
import org.apache.wicket.model.Model;
import org.apache.wicket.protocol.http.servlet.MultipartServletWebRequest;
import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
import org.apache.wicket.protocol.http.servlet.TomcatUploadProgressListenerFactory;
import org.apache.wicket.request.IRequestParameters;
import org.apache.wicket.request.Request;
import org.apache.wicket.request.Response;
Expand Down Expand Up @@ -278,6 +280,11 @@ public void component(final Component component, final IVisit<Void> visit)
/** True if the form has enctype of multipart/form-data */
private short multiPart = 0;

/**
* The ID of the file upload.
*/
private String uploadId;

/**
* A user has explicitly called {@link #setMultiPart(boolean)} with value {@code true} forcing
* it to be true
Expand Down Expand Up @@ -1451,7 +1458,7 @@ protected boolean handleMultiPart()
{
ServletWebRequest request = (ServletWebRequest)getRequest();
final MultipartServletWebRequest multipartWebRequest = request.newMultipartWebRequest(
getMaxSize(), getPage().getId());
getMaxSize(), getUploadId());
multipartWebRequest.setFileMaxSize(getFileMaxSize());
multipartWebRequest.setFileCountMax(getFileCountMax());
multipartWebRequest.parseFileParts();
Expand All @@ -1477,6 +1484,37 @@ protected boolean handleMultiPart()
return true;
}

/**
*
* @return The upload ID.
*/
public final String getUploadId()
{
if (uploadId != null)
{
return uploadId;
}
uploadId = computeUploadId(getPage());
return uploadId;
}

/**
* Computes the upload ID.
*
* @param page The {@link Page}
* @return the upload ID.
*/
public static String computeUploadId(Page page) {
if (Application.get().getApplicationSettings().isUseTomcatNativeFileUpload()) {
String uploadId = TomcatUploadProgressListenerFactory.getUploadId();
if (uploadId != null) {
return uploadId;
}
throw new WicketRuntimeException("If you are using Tomcat for uploading files you should have registered a TomcatUploadProgressListenerFactory");
}
return page.getId();
}

/**
* The default message may look like ".. may not exceed 10240 Bytes..". Which is ok, but
* sometimes you may want something like "10KB". By subclassing this method you may replace
Expand Down Expand Up @@ -1669,6 +1707,9 @@ private void adjustNestedTagName(ComponentTag tag) {
*/
protected CharSequence getActionUrl()
{
if (isMultiPart()) {
return urlForListener(new PageParameters().add("uploadId", getUploadId()));
}
return urlForListener(new PageParameters());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ protected List<FileUpload> convertValue(String[] value) throws ConversionExcepti
return getFileUploads();
}

public String getUploadId() {
return getMarkupId();
}

@Override
public boolean isMultiPart()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.util.Objects;
import java.util.UUID;
import org.apache.commons.io.IOUtils;
import org.apache.wicket.Application;
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.AjaxUtils;
Expand All @@ -38,6 +40,7 @@
import org.apache.wicket.markup.html.form.upload.FileUploadField;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.protocol.http.servlet.TomcatUploadProgressListenerFactory;
import org.apache.wicket.request.Request;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.mapper.parameter.PageParameters;
Expand All @@ -59,6 +62,8 @@ public abstract class FileUploadToResourceField extends FileUploadField
{
private static final Logger LOGGER = LoggerFactory.getLogger(FileUploadToResourceField.class);

private String uploadId;

/**
* Info regarding an upload.
*/
Expand Down Expand Up @@ -180,7 +185,7 @@ public List<UploadInfo> getObject()
// at this point files were stored at the server side by resource
// UploadFieldId acts as a discriminator at application level
// so that uploaded files are isolated.
uploadInfo.setFile(fileManager().getFile(getUploadFieldId(), uploadInfo.clientFileName));
uploadInfo.setFile(fileManager().getFile(getUploadId(), uploadInfo.clientFileName));
}
return fileInfos;
}
Expand All @@ -194,9 +199,9 @@ public void setObject(List<UploadInfo> object)
protected abstract IUploadsFileManager fileManager();

/*
This is an application unique ID assigned to upload field.
This is an application wide unique ID assigned to upload field.
*/
protected abstract String getUploadFieldId();
protected abstract String getUploadId();

protected abstract List<UploadInfo> getFileUploadInfos();
}
Expand Down Expand Up @@ -235,9 +240,9 @@ protected IUploadsFileManager fileManager() {
}

@Override
protected String getUploadFieldId()
protected String getUploadId()
{
return FileUploadToResourceField.this.getMarkupId();
return FileUploadToResourceField.this.getUploadId();
}

@Override
Expand Down Expand Up @@ -357,13 +362,13 @@ protected String generateAUniqueApplicationWiseId()
return "WRFUF_" + UUID.randomUUID().toString().replace("-", "_");
}


@Override
public void renderHead(IHeaderResponse response) {
CoreLibrariesContributor.contributeAjax(getApplication(), response);
response.render(JavaScriptHeaderItem.forReference(JS));
JSONObject jsonObject = new JSONObject();
jsonObject.put("inputName", getMarkupId());
jsonObject.put("uploadId", getUploadId());
jsonObject.put("resourceUrl", urlFor(getFileUploadResourceReference(), new PageParameters()).toString());
jsonObject.put("ajaxCallBackUrl", ajaxBehavior.getCallbackUrl());
jsonObject.put("maxSize", getMaxSize().bytes());
Expand All @@ -382,6 +387,33 @@ public void renderHead(IHeaderResponse response) {
+ getClientSideUploadErrorCallBack() + ");"));
}

/**
* @return the unique upload ID.
*/
public final String getUploadId() {
if (uploadId != null)
{
return uploadId;
}
uploadId = computeUploadId();
return uploadId;
}

/**
* Comoputes the upload ID.
* @return
*/
private String computeUploadId() {
if (Application.get().getApplicationSettings().isUseTomcatNativeFileUpload()) {
String uploadId = TomcatUploadProgressListenerFactory.getUploadId();
if (uploadId != null) {
return uploadId;
}
throw new WicketRuntimeException("If you are using Tomcat for uploading files you should have registered a TomcatUploadProgressListenerFactory");
}
return getMarkupId();
}

/**
* Sets maximum size of each file in upload request.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
{
this.settings = settings;
this.inputName = settings.inputName;
this.uploadId = settings.uploadId;
this.input = document.getElementById(this.inputName);
this.resourceUrl = settings.resourceUrl + "?uploadId=" + this.inputName + "&maxSize=" + this.settings.maxSize;
this.resourceUrl = settings.resourceUrl + "?uploadId=" + this.uploadId + "&maxSize=" + this.settings.maxSize;
if (this.settings.fileMaxSize != null) {
this.resourceUrl = this.resourceUrl + "&fileMaxSize=" + this.settings.fileMaxSize;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public BufferedHttpServletResponse(HttpServletResponse realResponse)
}

/**
* @see jakarta.servlet.http.HttpServletResponse#addCookie(javax.servlet.http.Cookie)
* @see jakarta.servlet.http.HttpServletResponse#addCookie(jakarta.servlet.http.Cookie)
*/
@Override
public void addCookie(Cookie cookie)
Expand Down Expand Up @@ -158,6 +158,18 @@ public void sendRedirect(String location) throws IOException
redirect = location;
}

@Override
public void sendRedirect(String location, int sc, boolean clearBuffer) throws IOException {
isOpen();
realResponse.sendRedirect(location);
}

@Override
public void sendEarlyHints() {
isOpen();
realResponse.sendEarlyHints();
}

/**
* @return The redirect url
*/
Expand Down
Loading
Loading