reiern70 opened a new pull request, #1671:
URL: https://github.com/apache/wicket/pull/1671

   Closes #1670
   Closes #1669
   
   Two commits, one per issue. The second one builds on the first.
   
   ### Make uploads to a resource fail cleanly and keep files of one name apart 
(#1670)
   
   - A failed upload calls `onUploadFailure()` with "The upload failed." (new 
key `uploadToResourceFailed`) instead of ending on the error page.
   - The field only accepts the resource keys of the limits and of no files 
selected. An HTTP status text, a network failure or an answer that is not JSON 
reads as a failed upload, instead of throwing `MissingResourceException` or 
claiming the file is too large.
   - The resource no longer sends exception messages to the browser. It logs 
them as errors, which it did not do at all before.
   - The script checks the limits of the field before sending. Files beyond 
them get the message of the limit and are not uploaded, instead of the server 
resetting the connection.
   - A second upload of the same field is refused while one runs. Before, the 
two requests shared the progress information in the session, and one of them 
failed.
   - The received files are reported to the field by POST. Before, beyond some 
65 files the GET URL exceeded the request line limit of Jetty and Tomcat and 
`onUploadSuccess()` was never called.
   - `FolderUploadsFileManager` stores files under random names, so two files 
with the same name no longer overwrite each other.
   - `cancel()` does nothing once the upload has ended, and a before-send 
callback returning `false` keeps the upload from being sent.
   
   ### Add a drop zone and a file list to uploads to a resource (#1669)
   
   - `FileDropZoneBehavior` makes any component a drop target for the files of 
a field. It respects the `accept` and `multiple` attributes of the input, 
leaves folders out, and sets `wicket-upload-dragover` while files are dragged 
over it.
   - `FileListBehavior`, on a `<ul>` or `<ol>`, lists the files chosen for the 
next upload, each with a Remove button (key `uploadToResourceRemove`). With a 
list and a `multiple` input, files chosen or dropped add up instead of 
replacing each other. Uploaded files leave the list, failed ones stay.
   - A field without these behaviors works as before.
   - The upload-to-resource example shows both. Its styles never applied, 
because they were in a `<head>` the page ignores and inline, which the CSP of 
the examples blocks, so they are in `UploadToResourcePage.css` now. Its guard 
against leaving the page during an upload used jQuery and failed under the 
plain JavaScript engine.
   
   ### API changes and migration
   
   Keeping files of one name apart needs a stored name that travels from the 
file manager through the browser back to the field, so on master:
   
   - `IUploadsFileManager` gets `store(FileUpload, String)`, which returns the 
stored name. `save()` is deprecated for removal. The two defaults call each 
other, so an implementation written for `save()` keeps working, with the old 
behaviour for files of one name.
   - `AbstractFileUploadResource.saveFiles()` returns the stored names, and 
`prepareResponse()` and `generateJsonResponse()` receive them. 
`FileUploadResourceReference.generateFileInfo()` receives the stored name as 
well. These are hooks for subclasses, so the signatures change rather than 
keeping deprecated ones that would no longer be called: an override fails to 
compile instead of being skipped silently.
   - `UploadInfo` carries the stored name (`getFileName()`, new constructor, 
the old one is deprecated). `equals()` and `hashCode()` use it.
   
   There is no OpenRewrite recipe, because none of this is mechanical. Like the 
other Wicket 11 changes that need manual migration, the note is in the comment 
of the `MigrateToWicket11` recipe in `wicket.yml`. There is no "Migration to 
Wicket 11.0" page on the wiki yet. Draft wording for it:
   
   > Uploads to a resource (FileUploadToResourceField): implement 
`IUploadsFileManager#store(FileUpload, String)` instead of the deprecated 
`save()`. It stores the file under a name of its own and returns that name, 
which `getFile(uploadFieldId, fileName)` then receives. The name goes to the 
browser and back, so `getFile()` must not return a file of another upload 
field. `FolderUploadsFileManager` stores files under random names: find them 
with `UploadInfo#getFile()` or `UploadInfo#getFileName()`, not by client file 
name. Subclasses of `AbstractFileUploadResource` receive the stored names in 
`saveFiles()`, `prepareResponse()` and `generateJsonResponse()`, subclasses of 
`FileUploadResourceReference` in `generateFileInfo()`. A failed upload reads 
"The upload failed." (resource key `uploadToResourceFailed`) instead of ending 
on the error page.
   
   No backport: wicket-10.x stays as it is.
   
   ### Tests
   
   - WicketTester: `FileUploadToResourceFieldTest`, `FileListBehaviorTest`, 
`FileDropZoneBehaviorTest`, and `store()` tests in 
`FolderUploadsFileManagerTest`.
   - QUnit: `upload-to-resource.js`, run against both the jQuery and the plain 
JavaScript engine.
   - By hand, on the upload-to-resource example in Chrome and Firefox under 
both engines: files of one name, the limits, a second upload while one runs, 
cancel, server failures, picks adding up, remove, a real file drop (Chrome) and 
the leave-page prompt.
   - `mvn clean install -Pjs-test` is green.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to