Browse Source

Fixing upload handler error handling (#11630)

* Fixing upload handler error handling

For some reason stream variable cleanup did not use UI.getCurrent(), despite current UI was set earlier in handleRequest, what I see specifically for this purpose. So I chanted this. This will address also issue #7289

Furthermore there was TODO in handle request about error handling. I interpreted this to refer to possible corner case, that UI is not found via session. In this case it is more appropriate throw UploadException and abort, than lat NPE happen.

* Fixing exception type
tags/8.9.0.alpha1
Tatu Lund 4 years ago
parent
commit
3652c3a8f1

+ 6
- 2
server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java View File

session.lock(); session.lock();
try { try {
UI uI = session.getUIById(Integer.parseInt(uiId)); UI uI = session.getUIById(Integer.parseInt(uiId));
if (uI == null) {
throw new IOException(
"File upload ignored because the UI was not found and stream variable cannot be determined");
}
// Set UI so that it can be used in stream variable clean up
UI.setCurrent(uI); UI.setCurrent(uI);


streamVariable = uI.getConnectorTracker() streamVariable = uI.getConnectorTracker()
.getStreamVariable(connectorId, variableName); .getStreamVariable(connectorId, variableName);
String secKey = uI.getConnectorTracker().getSeckey(streamVariable); String secKey = uI.getConnectorTracker().getSeckey(streamVariable);
if (secKey == null || !secKey.equals(parts[3])) { if (secKey == null || !secKey.equals(parts[3])) {
// TODO Should rethink error handling
return true; return true;
} }


try { try {
// Store ui reference so we can do cleanup even if connector is // Store ui reference so we can do cleanup even if connector is
// detached in some event handler // detached in some event handler
UI ui = connector.getUI();
UI ui = UI.getCurrent();
boolean forgetVariable = streamToReceiver(session, inputStream, boolean forgetVariable = streamToReceiver(session, inputStream,
streamVariable, filename, mimeType, contentLength); streamVariable, filename, mimeType, contentLength);
if (forgetVariable) { if (forgetVariable) {

Loading…
Cancel
Save